Use try-with-resources.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/83c25072
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/83c25072
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/83c25072

Branch: refs/heads/master
Commit: 83c2507282ec1f5c008aeba60a14110dff3bc72e
Parents: a95384f
Author: Gary Gregory <garydgreg...@gmail.com>
Authored: Sat May 16 22:33:47 2015 -0700
Committer: Gary Gregory <garydgreg...@gmail.com>
Committed: Sat May 16 22:33:47 2015 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/layout/SerializedLayout.java      | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/83c25072/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
index e8fa142..eb7203d 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/SerializedLayout.java
@@ -61,14 +61,9 @@ public final class SerializedLayout extends 
AbstractLayout<LogEvent> {
     @Override
     public byte[] toByteArray(final LogEvent event) {
         final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        try {
-            final ObjectOutputStream oos = new PrivateObjectOutputStream(baos);
-            try {
-                oos.writeObject(event);
-                oos.reset();
-            } finally {
-                oos.close();
-            }
+        try (final ObjectOutputStream oos = new 
PrivateObjectOutputStream(baos)) {
+            oos.writeObject(event);
+            oos.reset();
         } catch (final IOException ioe) {
             LOGGER.error("Serialization of LogEvent failed.", ioe);
         }

Reply via email to