public InMemoryClosableChannel( byte[] bytes, boolean append ) { this.bytes = bytes; ByteBuffer writeBuffer = ByteBuffer.wrap( this.bytes ); ByteBuffer readBuffer = ByteBuffer.wrap( this.bytes ); if ( append ) { writeBuffer.position( bytes.length ); } this.writer = new Writer( writeBuffer ); this.reader = new Reader( readBuffer ); }
public void reset() { writer.clear(); reader.clear(); Arrays.fill( bytes, (byte) 0 ); }
@Override public void get( byte[] bytes, int length ) throws ReadPastEndException { ensureAvailableToRead( length ); buffer.get( bytes, 0, length ); }
@Override public double getDouble() throws ReadPastEndException { return reader.getDouble(); }
@Override public float getFloat() throws ReadPastEndException { return reader.getFloat(); }
@Override public byte get() throws ReadPastEndException { return reader.get(); }
@Override public void close() { reader.close(); writer.close(); }
@Override public long getLong() throws ReadPastEndException { ensureAvailableToRead( 8 ); return buffer.getLong(); }
@Override public short getShort() throws ReadPastEndException { ensureAvailableToRead( 2 ); return buffer.getShort(); }
@Override public double getDouble() throws ReadPastEndException { ensureAvailableToRead( 8 ); return buffer.getDouble(); }
@Override public float getFloat() throws ReadPastEndException { ensureAvailableToRead( 4 ); return buffer.getFloat(); }
@Override public long getLong() throws ReadPastEndException { return reader.getLong(); }
@Override public byte get() throws ReadPastEndException { ensureAvailableToRead( 1 ); return buffer.get(); }
@Override public void get( byte[] bytes, int length ) throws ReadPastEndException { reader.get( bytes, length ); }
@Override public int getInt() throws ReadPastEndException { return reader.getInt(); }
@Override public int getInt() throws ReadPastEndException { ensureAvailableToRead( 4 ); return buffer.getInt(); }
@Override public short getShort() throws ReadPastEndException { return reader.getShort(); }