@@ -24,20 +24,20 @@ public void testStreams() throws Exception
2424 // First, write encoded stuff (won't compress, but produces something)
2525 byte [] input = "Whatever stuff..." .getBytes (StandardCharsets .UTF_8 );
2626
27- LZFFileOutputStream out = new LZFFileOutputStream (f );
28- out .write (input );
29- out . close ();
27+ try ( LZFFileOutputStream out = new LZFFileOutputStream (f )) {
28+ out .write (input );
29+ }
3030
3131 long len = f .length ();
3232 // happens to be 22; 17 bytes uncompressed, with 5 byte header
3333 assertEquals (22L , len );
3434
35- LZFFileInputStream in = new LZFFileInputStream (f );
36- for (byte b : input ) {
37- assertEquals (b & 0xFF , in .read ());
35+ try (LZFFileInputStream in = new LZFFileInputStream (f )) {
36+ for (byte b : input ) {
37+ assertEquals (b & 0xFF , in .read ());
38+ }
39+ assertEquals (-1 , in .read ());
3840 }
39- assertEquals (-1 , in .read ());
40- in .close ();
4141 }
4242
4343 @ Test
@@ -46,14 +46,14 @@ public void testReadAndWrite() throws Exception
4646 File f = tempDir .resolve ("lzf-test.lzf" ).toFile ();
4747
4848 byte [] fluff = constructFluff (132000 );
49- LZFFileOutputStream fout = new LZFFileOutputStream (f );
50- fout .write (fluff );
51- fout .close ();
52-
53- LZFFileInputStream in = new LZFFileInputStream (f );
49+ try (LZFFileOutputStream fout = new LZFFileOutputStream (f )) {
50+ fout .write (fluff );
51+ }
52+
5453 ByteArrayOutputStream bytes = new ByteArrayOutputStream (fluff .length );
55- in .readAndWrite (bytes );
56- in .close ();
54+ try (LZFFileInputStream in = new LZFFileInputStream (f )) {
55+ in .readAndWrite (bytes );
56+ }
5757 byte [] actual = bytes .toByteArray ();
5858 assertArrayEquals (fluff , actual );
5959 }
0 commit comments