Buffer implements ReadableByteChannel, WritableByteChannel { @Override public abstract int read(ByteBuffer destination) throws IOException; protected  Buffer(); @Override abstract int read(ByteBuffer destination); abstract int read(WritableByteChannel destination); @Override abstract boolean isOpen(); abstract boolean isInWriteMode(); @Override abstract void close(); @Override abstract int write(ByteBuffer data); abstract int write(ReadableByteChannel source); abstract int remaining(); boolean hasRemaining(); abstract int size(); final void recycleBuffer(); abstract void finishWritePhase(); abstract boolean isBackedByMemory(); abstract void copyToBuffer(Buffer destinationBuffer); abstract Buffer duplicate();  }
@Test public void testIntSerialize() { final SerializationBuffer<IntegerRecord> intSerializationBuffer = new SerializationBuffer<IntegerRecord>(); final int NUM = 0xab627ef; IntegerRecord intRecord = new IntegerRecord(NUM); try { intSerializationBuffer.serialize(intRecord); } catch (IOException e) { e.printStackTrace(); fail(); } try { intSerializationBuffer.serialize(intRecord); fail(); } catch (IOException e) { } try { intSerializationBuffer.read(writeable); } catch (IOException e) { e.printStackTrace(); fail(); } try { intSerializationBuffer.serialize(intRecord); } catch (IOException e) { e.printStackTrace(); fail(); } DefaultDeserializer<IntegerRecord> intDeserialitionBuffer = new DefaultDeserializer<IntegerRecord>(IntegerRecord.class, true); IntegerRecord record = new IntegerRecord(); try { record = intDeserialitionBuffer.readData(record, readable); } catch (IOException e) { e.printStackTrace(); fail(); } assertEquals(NUM, record.getValue()); try { record = intDeserialitionBuffer.readData(record, readable); fail(); } catch (IOException e) { } }
@Test public void testStringSerialize() { final SerializationBuffer<StringRecord> stringSerializationBuffer = new SerializationBuffer<StringRecord>(); final String str = "abc"; StringRecord stringrecord = new StringRecord(str); try { stringSerializationBuffer.serialize(stringrecord); } catch (IOException e) { e.printStackTrace(); fail(); } try { stringSerializationBuffer.read(writeable); } catch (IOException e) { e.printStackTrace(); fail(); } final String str2 = "abcdef"; stringrecord = new StringRecord(str2); try { stringSerializationBuffer.serialize(stringrecord); stringSerializationBuffer.read(writeable); } catch (IOException e) { e.printStackTrace(); fail(); } final DefaultDeserializer<StringRecord> stringDeserialitionBuffer = new DefaultDeserializer<StringRecord>(StringRecord.class, true); StringRecord record = new StringRecord(); try { record = stringDeserialitionBuffer.readData(record, readable); } catch (IOException e) { e.printStackTrace(); fail(); } assertEquals(str, record.toString()); try { record = stringDeserialitionBuffer.readData(record, readable); } catch (IOException e) { e.printStackTrace(); fail(); } assertEquals(str2, record.toString()); }