Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 3, 2023
1 parent f5ca826 commit 254eb26
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@ public class ByteBufferUtilsTest extends BaseMapTest

public void testByteBufferInput() throws Exception {
byte[] input = new byte[] { 1, 2, 3 };
ByteBufferBackedInputStream wrapped = new ByteBufferBackedInputStream(ByteBuffer.wrap(input));
assertEquals(3, wrapped.available());
assertEquals(1, wrapped.read());
byte[] buffer = new byte[10];
assertEquals(2, wrapped.read(buffer, 0, 5));
wrapped.close();
try (ByteBufferBackedInputStream wrapped = new ByteBufferBackedInputStream(ByteBuffer.wrap(input))) {
assertEquals(3, wrapped.available());
assertEquals(1, wrapped.read());
byte[] buffer = new byte[10];
assertEquals(2, wrapped.read(buffer, 0, 5));
// And now ought to get -1
assertEquals(-1, wrapped.read(buffer, 0, 5));
}
}

public void testByteBufferOutput() throws Exception {
ByteBuffer b = ByteBuffer.wrap(new byte[10]);
ByteBufferBackedOutputStream wrappedOut = new ByteBufferBackedOutputStream(b);
wrappedOut.write(1);
wrappedOut.write(new byte[] { 2, 3 });
assertEquals(3, b.position());
assertEquals(7, b.remaining());
wrappedOut.close();
try (ByteBufferBackedOutputStream wrappedOut = new ByteBufferBackedOutputStream(b)) {
wrappedOut.write(1);
wrappedOut.write(new byte[] { 2, 3 });
assertEquals(3, b.position());
assertEquals(7, b.remaining());
}
}

public void testReadFromByteBuffer() throws Exception
Expand Down

0 comments on commit 254eb26

Please sign in to comment.