diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java index 02f7782ebf..1b46007ebb 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java @@ -486,34 +486,34 @@ public TFile.Writer getWriter() { } private void writeVersion() throws IOException { - DataOutputStream out = this.writer.prepareAppendKey(-1); - VERSION_KEY.write(out); - out.close(); - out = this.writer.prepareAppendValue(-1); - out.writeInt(VERSION); - out.close(); + try (DataOutputStream out = this.writer.prepareAppendKey(-1)) { + VERSION_KEY.write(out); + } + try (DataOutputStream out = this.writer.prepareAppendValue(-1)) { + out.writeInt(VERSION); + } } public void writeApplicationOwner(String user) throws IOException { - DataOutputStream out = this.writer.prepareAppendKey(-1); - APPLICATION_OWNER_KEY.write(out); - out.close(); - out = this.writer.prepareAppendValue(-1); - out.writeUTF(user); - out.close(); + try (DataOutputStream out = this.writer.prepareAppendKey(-1)) { + APPLICATION_OWNER_KEY.write(out); + } + try (DataOutputStream out = this.writer.prepareAppendValue(-1)) { + out.writeUTF(user); + } } public void writeApplicationACLs(Map appAcls) throws IOException { - DataOutputStream out = this.writer.prepareAppendKey(-1); - APPLICATION_ACL_KEY.write(out); - out.close(); - out = this.writer.prepareAppendValue(-1); - for (Entry entry : appAcls.entrySet()) { - out.writeUTF(entry.getKey().toString()); - out.writeUTF(entry.getValue()); + try (DataOutputStream out = this.writer.prepareAppendKey(-1)) { + APPLICATION_ACL_KEY.write(out); + } + try (DataOutputStream out = this.writer.prepareAppendValue(-1)) { + for (Entry entry : appAcls.entrySet()) { + out.writeUTF(entry.getKey().toString()); + out.writeUTF(entry.getValue()); + } } - out.close(); } public void append(LogKey logKey, LogValue logValue) throws IOException { @@ -522,12 +522,12 @@ public void append(LogKey logKey, LogValue logValue) throws IOException { if (pendingUploadFiles.size() == 0) { return; } - DataOutputStream out = this.writer.prepareAppendKey(-1); - logKey.write(out); - out.close(); - out = this.writer.prepareAppendValue(-1); - logValue.write(out, pendingUploadFiles); - out.close(); + try (DataOutputStream out = this.writer.prepareAppendKey(-1)) { + logKey.write(out); + } + try (DataOutputStream out = this.writer.prepareAppendValue(-1)) { + logValue.write(out, pendingUploadFiles); + } } public void close() {