Revision 11247 trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/writer/GPEXmlWriterHandler.java

View differences:

GPEXmlWriterHandler.java
64 64
 *
65 65
 * $Id$
66 66
 * $Log$
67
 * Revision 1.5  2007-04-17 10:30:11  jorpiell
67
 * Revision 1.6  2007-04-19 07:25:49  jorpiell
68
 * Add the add methods to teh contenhandler and change the register mode
69
 *
70
 * Revision 1.5  2007/04/17 10:30:11  jorpiell
68 71
 * Add a method to compress a file
69 72
 *
70 73
 * Revision 1.4  2007/04/14 16:07:30  jorpiell
......
88 91
	protected Writer writer = null;
89 92
	private String targetNamespace = null;
90 93
	
91
	public GPEXmlWriterHandler(String format, GPEErrorHandler errorHandler) {
92
		super(format, errorHandler);
93
		try {
94
			writer = createWriter();
95
			initXmlHeader();
96
		} catch (IOException e) {
97
			errorHandler.addError(e);
98
		}		
94
	public GPEXmlWriterHandler() {
95
		
99 96
	}	
100 97
	
101 98
	/**
102 99
	 * Writes the XML header
103 100
	 * @throws IOException
104 101
	 */
105
	private void initXmlHeader() throws IOException{
102
	protected void initXmlHeader() throws IOException{
103
		writer = createWriter();
106 104
		writer.write("<?xml version=\"");
107 105
		writer.write(GPEDefaults.getProperty(GPEDefaults.XML_VERSION).toString());
108 106
		writer.write("\" encoding=\"");
......
120 118
	protected abstract Writer createWriter() throws IOException;
121 119
	
122 120
	/**
123
	 * @return the outputStream
124
	 */
125
	protected Writer getWriter() {
126
		return writer;
127
	}
128

  
129
	/**
130 121
	 * Returns the selected target namespace. If
131 122
	 * the namespace doesn't exists it returns the 
132 123
	 * default Namespace (cit); 
......
155 146
		File zipFile = null;
156 147
		String fileNameAux = null;
157 148
		while (fileExists){
158
			fileNameAux = getFile().getAbsolutePath() + i;
149
			fileNameAux = getOutputFile().getAbsolutePath() + i;
159 150
			zipFile = new File(fileNameAux);
160 151
			if (!zipFile.exists()){
161 152
				fileExists = false;
......
167 158
					new BufferedOutputStream(
168 159
							new FileOutputStream(zipFile)));
169 160
			byte[] data = new byte[BUFFER_SIZE];
170
			FileInputStream fi = new FileInputStream(getFile());
161
			FileInputStream fi = new FileInputStream(getOutputFile());
171 162
			InputStream origin = new BufferedInputStream( fi, BUFFER_SIZE );
172
			ZipEntry entry = new ZipEntry(getFile().getName());
163
			ZipEntry entry = new ZipEntry(getOutputFile().getName());
173 164
			out.putNextEntry( entry );
174 165
			int count;
175 166
			while(( count = origin.read(data, 0, BUFFER_SIZE ) ) != -1 ){
......
180 171
			//Close the zip file
181 172
			out.close();	
182 173
			//Change the file name and delete the first
183
			zipFile.renameTo(getFile());
174
			zipFile.renameTo(getOutputFile());
184 175
			new File(fileNameAux).delete();
185 176
		} catch (FileNotFoundException e) {
186 177
			//Never throwed;

Also available in: Unified diff