@@ -130,25 +130,26 @@ private static void testFramed(FuzzedDataProvider data) {
130130 byte [] compressed = compressedBuf .toByteArray ();
131131
132132 for (int bufferSize : new int []{1 , 64 , 256 , 1024 , 4096 }) {
133- SnappyFramedInputStream framedIn = new SnappyFramedInputStream (
134- new ByteArrayInputStream (compressed ), true );
135- ByteArrayOutputStream out = new ByteArrayOutputStream ();
136- byte [] buf = new byte [bufferSize ];
137- int readBytes ;
138- while ((readBytes = framedIn .read (buf )) != -1 ) {
139- out .write (buf , 0 , readBytes );
133+ try (SnappyFramedInputStream framedIn = new SnappyFramedInputStream (
134+ new ByteArrayInputStream (compressed ), true )) {
135+ ByteArrayOutputStream out = new ByteArrayOutputStream ();
136+ byte [] buf = new byte [bufferSize ];
137+ int readBytes ;
138+ while ((readBytes = framedIn .read (buf )) != -1 ) {
139+ out .write (buf , 0 , readBytes );
140+ }
141+ out .flush ();
140142 }
141- out .flush ();
142143 }
143144 } catch (IOException e ) {
145+ throw new RuntimeException (e );
144146 }
145147
146- try {
147- byte [] invalidData = data .consumeBytes (100 );
148- SnappyFramedInputStream invalidIn = new SnappyFramedInputStream (
149- new ByteArrayInputStream (invalidData ));
148+ try (SnappyFramedInputStream invalidIn = new SnappyFramedInputStream (
149+ new ByteArrayInputStream (data .consumeBytes (100 )))) {
150150 while (invalidIn .read () != -1 ) {}
151151 } catch (IOException e ) {
152+ throw new RuntimeException (e );
152153 }
153154 }
154155
@@ -207,22 +208,22 @@ private static void testBlockStream(FuzzedDataProvider data) {
207208 out .close ();
208209 byte [] compressed = compressedBuf .toByteArray ();
209210
210- SnappyInputStream in = new SnappyInputStream (new ByteArrayInputStream (compressed ));
211- ByteArrayOutputStream result = new ByteArrayOutputStream ();
212- byte [] buf = new byte [1024 ];
213- int read ;
214- while ((read = in .read (buf )) != -1 ) {
215- result .write (buf , 0 , read );
211+ try (SnappyInputStream in = new SnappyInputStream (new ByteArrayInputStream (compressed ))) {
212+ ByteArrayOutputStream result = new ByteArrayOutputStream ();
213+ byte [] buf = new byte [1024 ];
214+ int read ;
215+ while ((read = in .read (buf )) != -1 ) {
216+ result .write (buf , 0 , read );
217+ }
216218 }
217- in .close ();
218219 } catch (Exception e ) {
220+ throw new RuntimeException (e );
219221 }
220222
221- try {
222- byte [] invalid = data .consumeBytes (100 );
223- SnappyInputStream in = new SnappyInputStream (new ByteArrayInputStream (invalid ));
223+ try (SnappyInputStream in = new SnappyInputStream (new ByteArrayInputStream (data .consumeBytes (100 )))) {
224224 while (in .read () != -1 ) {}
225225 } catch (Exception e ) {
226+ throw new RuntimeException (e );
226227 }
227228 }
228229
0 commit comments