OSDN Git Service

XmlReader: close streams and readers
authorhneuer <hanno.neuer@gmail.com>
Wed, 2 Oct 2013 07:00:49 +0000 (09:00 +0200)
committerhneuer <hanno.neuer@gmail.com>
Wed, 2 Oct 2013 07:00:49 +0000 (09:00 +0200)
gdx/src/com/badlogic/gdx/utils/XmlReader.java

index 525ebd0..d1b3b41 100644 (file)
@@ -61,14 +61,24 @@ public class XmlReader {
        }\r
 \r
        public Element parse (InputStream input) throws IOException {\r
-               return parse(new InputStreamReader(input, "ISO-8859-1"));\r
+               Reader r = null;\r
+               try {\r
+                       r = new InputStreamReader(input, "ISO-8859-1");\r
+                       return parse(r);\r
+               } finally {\r
+                       StreamUtils.closeQuietly(r);\r
+               }\r
        }\r
 \r
        public Element parse (FileHandle file) throws IOException {\r
+               InputStream is = null;\r
                try {\r
-                       return parse(file.read());\r
+                       is = file.read();\r
+                       return parse(is);\r
                } catch (Exception ex) {\r
                        throw new SerializationException("Error parsing file: " + file, ex);\r
+               } finally {\r
+                       StreamUtils.closeQuietly(is);\r
                }\r
        }\r
 \r