You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@slider.apache.org by st...@apache.org on 2014/05/06 13:03:04 UTC

svn commit: r1592712 - /incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java

Author: stevel
Date: Tue May  6 11:03:03 2014
New Revision: 1592712

URL: http://svn.apache.org/r1592712
Log:
SLIDER-13 json ser to try-with-resources on resource load

Modified:
    incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java

Modified: incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java
URL: http://svn.apache.org/viewvc/incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java?rev=1592712&r1=1592711&r2=1592712&view=diff
==============================================================================
--- incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java (original)
+++ incubator/slider/trunk/slider-core/src/main/java/org/apache/slider/core/persist/JsonSerDeser.java Tue May  6 11:03:03 2014
@@ -107,19 +107,14 @@ public class JsonSerDeser<T> {
    */
   public T fromResource(String resource)
     throws IOException, JsonParseException, JsonMappingException {
-    InputStream resStream = null;
-    try {
-      resStream = this.getClass().getResourceAsStream(resource);
+    try(InputStream resStream = this.getClass().getResourceAsStream(resource)) {
       if (resStream == null) {
         throw new FileNotFoundException(resource);
       }
-
       return (T) (mapper.readValue(resStream, classType));
     } catch (IOException e) {
       log.error("Exception while parsing json resource {}: {}", resource, e);
       throw e;
-    } finally {
-      IOUtils.closeStream(resStream);
     }
   }