@@ -16,22 +16,24 @@ public class ByteBufferUtilsTest extends BaseMapTest
16
16
17
17
public void testByteBufferInput () throws Exception {
18
18
byte [] input = new byte [] { 1 , 2 , 3 };
19
- ByteBufferBackedInputStream wrapped = new ByteBufferBackedInputStream (ByteBuffer .wrap (input ));
20
- assertEquals (3 , wrapped .available ());
21
- assertEquals (1 , wrapped .read ());
22
- byte [] buffer = new byte [10 ];
23
- assertEquals (2 , wrapped .read (buffer , 0 , 5 ));
24
- wrapped .close ();
19
+ try (ByteBufferBackedInputStream wrapped = new ByteBufferBackedInputStream (ByteBuffer .wrap (input ))) {
20
+ assertEquals (3 , wrapped .available ());
21
+ assertEquals (1 , wrapped .read ());
22
+ byte [] buffer = new byte [10 ];
23
+ assertEquals (2 , wrapped .read (buffer , 0 , 5 ));
24
+ // And now ought to get -1
25
+ assertEquals (-1 , wrapped .read (buffer , 0 , 5 ));
26
+ }
25
27
}
26
28
27
29
public void testByteBufferOutput () throws Exception {
28
30
ByteBuffer b = ByteBuffer .wrap (new byte [10 ]);
29
- ByteBufferBackedOutputStream wrappedOut = new ByteBufferBackedOutputStream (b );
30
- wrappedOut .write (1 );
31
- wrappedOut .write (new byte [] { 2 , 3 });
32
- assertEquals (3 , b .position ());
33
- assertEquals (7 , b .remaining ());
34
- wrappedOut . close ();
31
+ try ( ByteBufferBackedOutputStream wrappedOut = new ByteBufferBackedOutputStream (b )) {
32
+ wrappedOut .write (1 );
33
+ wrappedOut .write (new byte [] { 2 , 3 });
34
+ assertEquals (3 , b .position ());
35
+ assertEquals (7 , b .remaining ());
36
+ }
35
37
}
36
38
37
39
public void testReadFromByteBuffer () throws Exception
0 commit comments