< prev index next >

test/javax/xml/jaxp/libs/org/xml/sax/ptests/MyNSContentHandler.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -29,15 +29,16 @@
 import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.FileWriter;
 import org.xml.sax.SAXException;
 
-class MyNSContentHandler extends DefaultHandler {
+class MyNSContentHandler extends DefaultHandler implements AutoCloseable{
     /**
      * Prefix for written string.
      */
     private final static String WRITE_ERROR = "bWrite error";
+
     /**
      * FileWriter to write output file.
      */
     private final BufferedWriter bWriter;
 

@@ -203,6 +204,16 @@
             bWriter.newLine();
         } catch (IOException ex) {
             throw new SAXException(WRITE_ERROR, ex);
         }
     }
+
+    /**
+     * Close writer if it's initiated.
+     * @throws IOException if any I/O error when close writer. 
+     */
+    @Override
+    public void close() throws IOException {
+        if (bWriter != null)
+            bWriter.close();
+    }
 }
< prev index next >