Ignore:
Timestamp:
2012-04-29T15:38:56+02:00 (12 years ago)
Author:
donvip
Message:

see #josm7641 - Close file handle after XSD validation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/opendata/src/org/openstreetmap/josm/plugins/opendata/core/io/NeptuneReader.java

    r28031 r28361  
    1717
    1818import java.io.File;
     19import java.io.FileInputStream;
     20import java.io.FileNotFoundException;
    1921import java.io.IOException;
    2022import java.io.InputStream;
     
    107109                }
    108110               
    109                 Source xmlFile = new StreamSource(file);
    110                
    111111                try {
    112                         SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    113                         Schema schema = schemaFactory.newSchema(schemaURL);
    114                         Validator validator = schema.newValidator();
    115                         validator.validate(xmlFile);
    116                         System.out.println(xmlFile.getSystemId() + " is valid");
    117                         return true;
    118                 } catch (SAXException e) {
    119                         System.out.println(xmlFile.getSystemId() + " is NOT valid");
    120                         System.out.println("Reason: " + e.getLocalizedMessage());
    121                 } catch (IOException e) {
    122                         System.out.println(xmlFile.getSystemId() + " is NOT valid");
    123                         System.out.println("Reason: " + e.getLocalizedMessage());
     112                        FileInputStream in = new FileInputStream(file);
     113                        Source xmlFile = new StreamSource(in);
     114                        try {
     115                                SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
     116                                Schema schema = schemaFactory.newSchema(schemaURL);
     117                                Validator validator = schema.newValidator();
     118                                validator.validate(xmlFile);
     119                                System.out.println(xmlFile.getSystemId() + " is valid");
     120                                return true;
     121                        } catch (SAXException e) {
     122                                System.out.println(xmlFile.getSystemId() + " is NOT valid");
     123                                System.out.println("Reason: " + e.getLocalizedMessage());
     124                        } catch (IOException e) {
     125                                System.out.println(xmlFile.getSystemId() + " is NOT valid");
     126                                System.out.println("Reason: " + e.getLocalizedMessage());
     127                        } finally {
     128                                try {
     129                                        in.close();
     130                                } catch (IOException e) {
     131                                        // Ignore exception
     132                                }
     133                        }
     134                } catch (FileNotFoundException e) {
     135                        System.err.println(e.getMessage());
    124136                }
    125137               
Note: See TracChangeset for help on using the changeset viewer.