HeapDataOutputStream extends
    org.apache.geode.internal.serialization.BufferDataOutputStream implements ObjToByteArraySerializer, ByteBufferWriter { public void write(ByteBufferInputStream.ByteSource source) { ByteBuffer bb = source.getBackingByteBuffer(); if (bb != null) { write(bb); return; } if (this.ignoreWrites) return; checkIfWritable(); int remainingSpace = this.buffer.limit() - this.buffer.position(); if (remainingSpace < source.remaining()) { int oldLimit = source.limit(); source.limit(source.position() + remainingSpace); source.sendTo(this.buffer); source.limit(oldLimit); ensureCapacity(source.remaining()); } source.sendTo(this.buffer); } HeapDataOutputStream(KnownVersion version);  HeapDataOutputStream(String s);  HeapDataOutputStream(int allocSize, KnownVersion version);  HeapDataOutputStream(int allocSize);  HeapDataOutputStream(int allocSize, KnownVersion version, boolean doNotCopy);  HeapDataOutputStream(ByteBuffer initialBuffer, KnownVersion version, boolean doNotCopy);  HeapDataOutputStream(byte[] bytes); void trim(); void sendTo(BytesAndBitsForCompactor wrapper, byte userBits); int sendTo(SocketChannel chan); void sendTo(SocketChannel chan, ByteBuffer out); void sendTo(ByteBuffer out); void sendTo(OutputStream out, ByteBuffer outBuf); static int writeByteBufferToStream(OutputStream out, ByteBuffer outBuf, ByteBuffer inBuf); void sendTo(ByteBufferWriter out); void sendTo(DataOutput out); @Override void writeAsSerializedByteArray(Object v); void write(ByteBufferInputStream.ByteSource source);  }
@Test public void toByteBufferWithStartPositionAndNoChunksReturnsCorrectByteBuffer() throws IOException { HeapDataOutputStream heapDataOutputStream = new HeapDataOutputStream(SMALLEST_CHUNK_SIZE, null); heapDataOutputStream.write(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); ByteBuffer result = heapDataOutputStream.toByteBuffer(9); assertThat(result.remaining()).isEqualTo(1); assertThat(result.get(0)).isEqualTo((byte) 10); }
@Test public void toByteBufferWithStartPositionAndChunksReturnsCorrectByteBuffer() throws IOException { HeapDataOutputStream heapDataOutputStream = new HeapDataOutputStream(SMALLEST_CHUNK_SIZE, null); heapDataOutputStream.write(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); byte[] chunk = new byte[SMALLEST_CHUNK_SIZE]; for (byte i = 0; i < SMALLEST_CHUNK_SIZE; i++) { chunk[i] = i; } heapDataOutputStream.write(chunk); ByteBuffer result = heapDataOutputStream.toByteBuffer(9); assertThat(result.remaining()).isEqualTo(SMALLEST_CHUNK_SIZE + 1); assertThat(result.get(0)).isEqualTo((byte) 10); for (byte i = 0; i < SMALLEST_CHUNK_SIZE; i++) { assertThat(result.get(i + 1)).isEqualTo(i); } }