diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/EncodedDataBlock.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/EncodedDataBlock.java index 9e832368b5f..9e0497eeaef 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/EncodedDataBlock.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/EncodedDataBlock.java @@ -165,14 +165,19 @@ public class EncodedDataBlock { if (compressor != null) { compressor.reset(); } - OutputStream compressingStream = algo.createCompressionStream( - compressedStream, compressor, 0); + OutputStream compressingStream = null; - compressingStream.write(inputBuffer, offset, length); - compressingStream.flush(); - compressingStream.close(); + try { + compressingStream = algo.createCompressionStream( + compressedStream, compressor, 0); - return compressedStream.size(); + compressingStream.write(inputBuffer, offset, length); + compressingStream.flush(); + + return compressedStream.size(); + } finally { + if (compressingStream != null) compressingStream.close(); + } } /**