diff options
author | pascalschumacher <pascalschumacher@gmx.net> | 2016-10-23 22:30:00 +0200 |
---|---|---|
committer | pascalschumacher <pascalschumacher@gmx.net> | 2016-10-23 22:30:00 +0200 |
commit | f9cab271b3bc8c2fb6e2c51449ad3bc07e62e174 (patch) | |
tree | e2012fdbc881ef34cebd50f177ed8678a0d503bd /src/main/java/org/apache/commons/lang3/SerializationUtils.java | |
parent | dc53e49b4afa5d59c533cf2b4918402c37411fbd (diff) | |
download | apache-commons-lang-f9cab271b3bc8c2fb6e2c51449ad3bc07e62e174.tar.gz |
LANG-1279: Update Java requirement from Java 6 to 7
use try with resources in SerializationUtils
Diffstat (limited to 'src/main/java/org/apache/commons/lang3/SerializationUtils.java')
-rw-r--r-- | src/main/java/org/apache/commons/lang3/SerializationUtils.java | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/src/main/java/org/apache/commons/lang3/SerializationUtils.java b/src/main/java/org/apache/commons/lang3/SerializationUtils.java index f64869575..b40063a89 100644 --- a/src/main/java/org/apache/commons/lang3/SerializationUtils.java +++ b/src/main/java/org/apache/commons/lang3/SerializationUtils.java @@ -136,22 +136,10 @@ public class SerializationUtils { if (outputStream == null) { throw new IllegalArgumentException("The OutputStream must not be null"); } - ObjectOutputStream out = null; - try { - // stream closed in the finally - out = new ObjectOutputStream(outputStream); + try (ObjectOutputStream out = new ObjectOutputStream(outputStream)){ out.writeObject(obj); - } catch (final IOException ex) { throw new SerializationException(ex); - } finally { - try { - if (out != null) { - out.close(); - } - } catch (final IOException ex) { // NOPMD - // ignore close exception - } } } @@ -205,26 +193,12 @@ public class SerializationUtils { if (inputStream == null) { throw new IllegalArgumentException("The InputStream must not be null"); } - ObjectInputStream in = null; - try { - // stream closed in the finally - in = new ObjectInputStream(inputStream); + try (ObjectInputStream in = new ObjectInputStream(inputStream)) { @SuppressWarnings("unchecked") final T obj = (T) in.readObject(); return obj; - - } catch (final ClassNotFoundException ex) { + } catch (final ClassNotFoundException | IOException ex) { throw new SerializationException(ex); - } catch (final IOException ex) { - throw new SerializationException(ex); - } finally { - try { - if (in != null) { - in.close(); - } - } catch (final IOException ex) { // NOPMD - // ignore close exception - } } } |