From 6078172fee6b0843cf4aa0fce5090d728ab7e53a Mon Sep 17 00:00:00 2001 From: Tsuyoshi Ozawa Date: Wed, 2 Sep 2015 02:01:51 +0900 Subject: [PATCH] HADOOP-10365. BufferedOutputStream in FileUtil#unpackEntries() should be closed in finally block. Contributed by Kiran Kumar M R and Sanghyun Yun. (cherry picked from commit dd149adeace8727864371c5a1484c6534f8b450b) --- hadoop-common-project/hadoop-common/CHANGES.txt | 3 +++ .../main/java/org/apache/hadoop/fs/FileUtil.java | 14 +++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index cdc7b668ce4..010ba3c330a 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -35,6 +35,9 @@ Release 2.7.2 - UNRELEASED HADOOP-12359. hadoop fs -getmerge doc is wrong. (Jagadesh Kiran N via aajisaka) + HADOOP-10365. BufferedOutputStream in FileUtil#unpackEntries() should be + closed in finally block. (Kiran Kumar M R and Sanghyun Yun via ozawa) + Release 2.7.1 - 2015-07-06 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java index 91f00e18e3f..23fb9462449 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java @@ -729,15 +729,15 @@ private static void unpackEntries(TarArchiveInputStream tis, int count; byte data[] = new byte[2048]; - BufferedOutputStream outputStream = new BufferedOutputStream( - new FileOutputStream(outputFile)); + try (BufferedOutputStream outputStream = new BufferedOutputStream( + new FileOutputStream(outputFile));) { - while ((count = tis.read(data)) != -1) { - outputStream.write(data, 0, count); + while ((count = tis.read(data)) != -1) { + outputStream.write(data, 0, count); + } + + outputStream.flush(); } - - outputStream.flush(); - outputStream.close(); } /**