private void shutdown(String reason) { if (null!=reason) { log.warn(reason); } try { inputStreamFlyweight.close(); outputStreamFlyweight.close(); } catch (IOException e) { throw new RuntimeException(e); } }
private void shutdown(String reason) { if (null!=reason) { log.warn(reason); } try { inputStreamFlyweight.close(); outputStreamFlyweight.close(); } catch (IOException e) { throw new RuntimeException(e); } }
private void shutdown(String reason) { if (null!=reason) { log.warn(reason); } try { inputStreamFlyweight.close(); outputStreamFlyweight.close(); } catch (IOException e) { throw new RuntimeException(e); } }
@Test public void copyIntTest() throws IOException{ //create blob for test Pipe<RawDataSchema> encodedValuesToValidate = new Pipe<RawDataSchema>(new PipeConfig<RawDataSchema>(RawDataSchema.instance, 100, 4000)); encodedValuesToValidate.initBuffers(); DataOutputBlobWriter<RawDataSchema> writer = new DataOutputBlobWriter<RawDataSchema>(encodedValuesToValidate); //create int dictionary int[] intDictionary = new int[5]; Arrays.fill(intDictionary, 0); intDictionary[2] = 5; //make it increment 2 values 0 and 5 PhastEncoder.copyInt(intDictionary, writer, 0, 0, 2, 0, false); writer.close(); }
@Test public void testEncodeString() throws IOException{ //create a new blob pipe to put a string on Pipe<RawDataSchema> pipe = new Pipe<RawDataSchema>(new PipeConfig<RawDataSchema>(RawDataSchema.instance, 100, 4000)); pipe.initBuffers(); DataOutputBlobWriter<RawDataSchema> writer = new DataOutputBlobWriter<RawDataSchema>(pipe); //encode a string on blob using the static method StringBuilder testString = new StringBuilder("This is a test"); PhastEncoder.encodeString(writer, testString , 0, 0, false); writer.close(); //check what is on the pipe DataInputBlobReader<RawDataSchema> reader = new DataInputBlobReader<RawDataSchema>(pipe); //should be -63 int test = reader.readPackedInt(); //the string String value = reader.readUTF(); reader.close(); String s = value.toString(); assertTrue((test==-63) && (s.compareTo("This is a test")==0)); }
@Test public void decodeStringTest() throws IOException{ Pipe<RawDataSchema> pipe = new Pipe<RawDataSchema>(new PipeConfig<RawDataSchema>(RawDataSchema.instance, 100, 4000)); pipe.initBuffers(); DataOutputBlobWriter<RawDataSchema> writer = new DataOutputBlobWriter<RawDataSchema>(pipe); DataOutputBlobWriter.writePackedInt(writer, -63); writer.writeUTF("This is a test"); writer.close(); DataInputBlobReader<RawDataSchema> reader = new DataInputBlobReader<RawDataSchema>(pipe); String stest = PhastDecoder.decodeString(reader, false); reader.close(); assertTrue(stest.compareTo("This is a test") == 0); }
@Test public void defaultIntTest() throws IOException{ //create a blob to test Pipe<RawDataSchema> encodedValuesToValidate = new Pipe<RawDataSchema>(new PipeConfig<RawDataSchema>(RawDataSchema.instance, 100, 4000)); encodedValuesToValidate.initBuffers(); DataOutputBlobWriter<RawDataSchema> writer = new DataOutputBlobWriter<RawDataSchema>(encodedValuesToValidate); //make int array int[] defaultInt = new int[5]; defaultInt[3] = 4; //should encode 16 PhastEncoder.encodeDefaultInt(defaultInt, writer, 1, 1, 3, 16, false); //should encode 4 PhastEncoder.encodeDefaultInt(defaultInt, writer, 0, 1, 3, 16, false); writer.close(); DataInputBlobReader<RawDataSchema> reader = new DataInputBlobReader<RawDataSchema>(encodedValuesToValidate); int test1 = reader.readPackedInt(); //shouldnt encode anything reader.close(); }
DataOutputBlobWriter.writePackedInt(writer, 404); writer.close();
writer.close();
writer.close();
writer.writePackedShort((short)404); writer.close();
DataOutputBlobWriter.writePackedLong(writer, 404); writer.close();