Revision 1688 tmp/org.txm.core/src/java/org/txm/scripts/importer/SplitBy.groovy

SplitBy.groovy (revision 1688)
12 12
	XMLOutputFactory factory = XMLOutputFactory.newInstance();
13 13
	FileOutputStream output;
14 14
	XMLStreamWriter writer;
15
	def parser;
15
	def parser, inputData;
16 16
	ArrayList<String> newfiles = [];
17 17
	
18 18
	public SplitBy(File xmlfile)
19 19
	{
20 20
		try {
21
			def inputData = xmlfile.toURI().toURL().openStream();
21
			inputData = xmlfile.toURI().toURL().openStream();
22 22
			def inputFactory = XMLInputFactory.newInstance();
23 23
			parser = inputFactory.createXMLStreamReader(inputData);
24 24
			
......
60 60
							if(files.contains(newfile))
61 61
							{
62 62
								println "Item declared twice "+filename+" at location "+parser.getLocation();
63
								if (parser != null) parser.close();
64
								if (inputData != null) inputData.close();
63 65
								return false;
64 66
							}
65 67
							files.add(newfile);
......
103 105
				writer.close();
104 106
			if(output != null)
105 107
				output.close();
108
				if (parser != null) parser.close();
109
				if (inputData != null) inputData.close();
106 110
			return true;
107 111
		}
108 112
		catch(Exception e){
109 113
			println "XML Error at location: "+parser.getLocation()
110 114
			e.printStackTrace()
111
			if(writer != null)
115
			if (writer != null)
112 116
				writer.close()
113 117
				output.close()
118
				if (parser != null) parser.close();
119
				if (inputData != null) inputData.close();
114 120
				return false
115 121
			}
116 122
	}

Also available in: Unified diff