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 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(); }
assertTrue(reader.readPackedLong()==455); assertTrue(reader.readPackedLong()==455); reader.close();
assertTrue(reader.readPackedLong()==342); assertTrue(reader.readPackedLong()==342); reader.close();
assertEquals(3, decodedReader.read()); assertEquals(4, decodedReader.read()); decodedReader.close(); } catch (IOException e) { throw new RuntimeException(e);