From 841b319e4d8375220ee7856c93e400821ee86989 Mon Sep 17 00:00:00 2001 From: yuliangwan Date: Tue, 25 Jun 2019 05:14:05 +0800 Subject: [PATCH] HBASE-22611 Close the DataOutputStream object #325 --- .../hbase/io/encoding/RowIndexCodecV1.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java index 32933892655..07e17d84f7f 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java @@ -118,16 +118,17 @@ public class RowIndexCodecV1 extends AbstractDataBlockEncoder { } boolean includesMvcc = decodingCtx.getHFileContext().isIncludesMvcc(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream out = new DataOutputStream(baos); - for (Cell cell : kvs) { - KeyValue currentCell = KeyValueUtil.copyToNewKeyValue(cell); - out.write(currentCell.getBuffer(), currentCell.getOffset(), - currentCell.getLength()); - if (includesMvcc) { - WritableUtils.writeVLong(out, cell.getSequenceId()); + try (DataOutputStream out = new DataOutputStream(baos)) { + for (Cell cell : kvs) { + KeyValue currentCell = KeyValueUtil.copyToNewKeyValue(cell); + out.write(currentCell.getBuffer(), currentCell.getOffset(), + currentCell.getLength()); + if (includesMvcc) { + WritableUtils.writeVLong(out, cell.getSequenceId()); + } } + out.flush(); } - out.flush(); return ByteBuffer.wrap(baos.getBuffer(), 0, baos.size()); } }