Revision 11223

View differences:

trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/writer/GPEXmlWriterHandler.java
1 1
package org.gvsig.gpe.xml.writer;
2 2

  
3
import java.io.BufferedInputStream;
4
import java.io.BufferedOutputStream;
3 5
import java.io.File;
6
import java.io.FileInputStream;
4 7
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
5 9
import java.io.FileWriter;
6 10
import java.io.IOException;
7 11
import java.io.InputStream;
8 12
import java.io.OutputStream;
13
import java.util.zip.ZipEntry;
14
import java.util.zip.ZipOutputStream;
15

  
9 16
import org.gvsig.gpe.xml.writer.Writer;
10 17

  
11 18
import org.apache.xml.utils.NameSpace;
......
57 64
 *
58 65
 * $Id$
59 66
 * $Log$
60
 * Revision 1.4  2007-04-14 16:07:30  jorpiell
67
 * Revision 1.5  2007-04-17 10:30:11  jorpiell
68
 * Add a method to compress a file
69
 *
70
 * Revision 1.4  2007/04/14 16:07:30  jorpiell
61 71
 * The writer has been created
62 72
 *
63 73
 * Revision 1.3  2007/04/13 07:17:57  jorpiell
......
134 144
		return targetNamespace;
135 145
	}
136 146
	
147
	/**
148
	 * This method compress a file using the ZIP
149
	 * compression
150
	 */
151
	protected void compressFile(){
152
		int BUFFER_SIZE = 1024;
153
		int i = 0;
154
		boolean fileExists = true;
155
		File zipFile = null;
156
		String fileNameAux = null;
157
		while (fileExists){
158
			fileNameAux = getFile().getAbsolutePath() + i;
159
			zipFile = new File(fileNameAux);
160
			if (!zipFile.exists()){
161
				fileExists = false;
162
			}
163
			i++;
164
		}
165
		try {
166
			ZipOutputStream out = new ZipOutputStream(
167
					new BufferedOutputStream(
168
							new FileOutputStream(zipFile)));
169
			byte[] data = new byte[BUFFER_SIZE];
170
			FileInputStream fi = new FileInputStream(getFile());
171
			InputStream origin = new BufferedInputStream( fi, BUFFER_SIZE );
172
			ZipEntry entry = new ZipEntry(getFile().getName());
173
			out.putNextEntry( entry );
174
			int count;
175
			while(( count = origin.read(data, 0, BUFFER_SIZE ) ) != -1 ){
176
				out.write(data, 0, count);
177
			}
178
			//Close the file
179
			origin.close();
180
			//Close the zip file
181
			out.close();	
182
			//Change the file name and delete the first
183
			zipFile.renameTo(getFile());
184
			new File(fileNameAux).delete();
185
		} catch (FileNotFoundException e) {
186
			//Never throwed;
187
		} catch (IOException e) {
188
			// TODO Auto-generated catch block
189
			e.printStackTrace();
190
		} 
191
	}
137 192
	
138 193
}
139 194
	
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/writer/GPEKmlWriterHandler.java
1 1
package org.gvsig.gpe.kml.writer;
2 2

  
3
import java.io.BufferedInputStream;
4
import java.io.BufferedOutputStream;
3 5
import java.io.File;
6
import java.io.FileInputStream;
7
import java.io.FileNotFoundException;
8
import java.io.FileOutputStream;
4 9
import java.io.FileWriter;
5 10
import java.io.IOException;
11
import java.io.InputStream;
12
import java.util.zip.Adler32;
13
import java.util.zip.CheckedOutputStream;
14
import java.util.zip.ZipEntry;
15
import java.util.zip.ZipFile;
16
import java.util.zip.ZipOutputStream;
6 17

  
7 18
import org.gvsig.gpe.GPEErrorHandler;
8 19
import org.gvsig.gpe.gml.GMLTags;
......
17 28
import org.gvsig.gpe.kml.writer.geometries.PolygonWriter;
18 29
import org.gvsig.gpe.xml.writer.GPEXmlWriterHandler;
19 30
import org.gvsig.gpe.xml.writer.Writer;
31
import org.xml.sax.InputSource;
20 32

  
21 33

  
22 34
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
......
63 75
 *
64 76
 * $Id$
65 77
 * $Log$
66
 * Revision 1.4  2007-04-14 16:08:07  jorpiell
78
 * Revision 1.5  2007-04-17 10:30:41  jorpiell
79
 * Add a method to compress a file
80
 *
81
 * Revision 1.4  2007/04/14 16:08:07  jorpiell
67 82
 * Kml writing support added
68 83
 *
69 84
 * Revision 1.3  2007/04/13 13:16:21  jorpiell
......
92 107
	 * @see org.gvsig.gpe.xml.writer.GPEXmlWriterHandler#createOutputStream()
93 108
	 */
94 109
	protected Writer createWriter() throws IOException {
95
		if(getFile().getName().toUpperCase().endsWith("KMZ")){
96
			//TODO: Create the KMZ outputStream
97
		}
98 110
		return new Writer(new FileWriter(getFile()));	 
99 111
	}
100 112
	
......
126 138
		} catch (IOException e) {
127 139
			getErrorHandler().addError(e);
128 140
		}
129
	}
141
		if (getFormat().toUpperCase().equals("KMZ")){
142
			compressFile();
143
		}
144
	}	
130 145
	
131 146
	/*
132 147
	 * (non-Javadoc)

Also available in: Unified diff