@@ -16,22 +16,24 @@ public class ByteBufferUtilsTest extends BaseMapTest
1616
1717 public void testByteBufferInput () throws Exception {
1818 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+ }
2527 }
2628
2729 public void testByteBufferOutput () throws Exception {
2830 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+ }
3537 }
3638
3739 public void testReadFromByteBuffer () throws Exception
0 commit comments