From 9fb92221dbf3d13c66ff88fc53b7b56fb94ad9c5 Mon Sep 17 00:00:00 2001 From: kamaci Date: Mon, 9 Jan 2017 23:25:03 +0200 Subject: [PATCH] NUTCH-2348 GZIPInputStream is closed at finally. --- src/java/org/apache/nutch/tools/arc/ArcRecordReader.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java b/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java index 7f36b52d81..434db0a98f 100644 --- a/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java +++ b/src/java/org/apache/nutch/tools/arc/ArcRecordReader.java @@ -234,11 +234,11 @@ public boolean next(Text key, BytesWritable value) throws IOException { ByteArrayOutputStream baos = null; int totalRead = 0; + GZIPInputStream zin = null; try { - // read 4K of the gzip at a time putting into a byte array byte[] buffer = new byte[4096]; - GZIPInputStream zin = new GZIPInputStream(in); + zin = new GZIPInputStream(in); int gzipRead = -1; baos = new ByteArrayOutputStream(); while ((gzipRead = zin.read(buffer, 0, buffer.length)) != -1) { @@ -255,6 +255,10 @@ public boolean next(Text key, BytesWritable value) throws IOException { in.seek(startRead + 1); } continue; + } finally { + if (zin != null) { + zin.close(); + } } // change the output stream to a byte array