• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.util;
2 
3 import java.nio.ByteBuffer;
4 
5 import com.fasterxml.jackson.databind.BaseMapTest;
6 
7 public class ByteBufferUtilsTest extends BaseMapTest
8 {
testByteBufferInput()9     public void testByteBufferInput() throws Exception {
10         byte[] input = new byte[] { 1, 2, 3 };
11         ByteBufferBackedInputStream wrapped = new ByteBufferBackedInputStream(ByteBuffer.wrap(input));
12         assertEquals(3, wrapped.available());
13         assertEquals(1, wrapped.read());
14         byte[] buffer = new byte[10];
15         assertEquals(2, wrapped.read(buffer, 0, 5));
16         wrapped.close();
17     }
18 
testByteBufferOutput()19     public void testByteBufferOutput() throws Exception {
20         ByteBuffer b = ByteBuffer.wrap(new byte[10]);
21         ByteBufferBackedOutputStream wrappedOut = new ByteBufferBackedOutputStream(b);
22         wrappedOut.write(1);
23         wrappedOut.write(new byte[] { 2, 3 });
24         assertEquals(3, b.position());
25         assertEquals(7, b.remaining());
26         wrappedOut.close();
27     }
28 }
29