Strabon
changeset 140:59234a910710
Trying on Strabon KMZ..
author | Michael Sioutis |
---|---|
date | Wed May 09 15:48:56 2012 +0300 (2012-05-09) |
parents | 2c6b9d24ada8 |
children | 36df5f584371 |
files | runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java |
line diff
1.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Wed May 09 14:11:28 2012 +0300 1.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java Wed May 09 15:48:56 2012 +0300 1.3 @@ -19,9 +19,12 @@ 1.4 import java.util.Set; 1.5 import java.util.zip.ZipEntry; 1.6 import java.util.zip.ZipOutputStream; 1.7 +import java.io.*; 1.8 +import java.util.zip.*; 1.9 1.10 import javax.xml.namespace.QName; 1.11 1.12 +import org.apache.commons.io.FileUtils; 1.13 import org.apache.commons.io.output.ByteArrayOutputStream; 1.14 import org.geotools.data.simple.SimpleFeatureCollection; 1.15 import org.geotools.feature.FeatureCollections; 1.16 @@ -638,15 +641,53 @@ 1.17 { 1.18 //compress 1.19 // FileOutputStream fos = new FileOutputStream(new File("deleteme.kmz")); 1.20 - ZipOutputStream kmzout = new ZipOutputStream(retStream); 1.21 + //ZipOutputStream kmzout = new ZipOutputStream(retStream); 1.22 // ZipOutputStream kmzout = new ZipOutputStream(fos); 1.23 - ZipEntry entry = new ZipEntry("doc.kml"); 1.24 + //ZipEntry entry = new ZipEntry("doc.kml"); 1.25 1.26 - kmzout.setLevel(9); 1.27 - kmzout.putNextEntry(entry); 1.28 - kmzout.write(newString.getBytes()); 1.29 - kmzout.closeEntry(); 1.30 - kmzout.close(); 1.31 + //kmzout.setLevel(6); 1.32 + //kmzout.putNextEntry(entry); 1.33 + //kmzout.write(newString.getBytes()); 1.34 + //kmzout.closeEntry(); 1.35 + //kmzout.close(); 1.36 + 1.37 + try { 1.38 + File file = new File("/tmp/tmp.kml"); 1.39 + String filename = "/tmp/tmp.kml"; 1.40 + FileUtils.writeStringToFile(file, newString); 1.41 + 1.42 + File zfile = new File("/tmp/tmp.kmz"); 1.43 + String zipfilename = "/tmp/tmp.kmz"; 1.44 + 1.45 + byte[] buf = new byte[1024]; 1.46 + FileInputStream fis = new FileInputStream(filename); 1.47 + fis.read(buf,0,buf.length); 1.48 + 1.49 + CRC32 crc = new CRC32(); 1.50 + ZipOutputStream s = new ZipOutputStream( 1.51 + (OutputStream)new FileOutputStream(zipfilename)); 1.52 + 1.53 + //s.setLevel(6); 1.54 + 1.55 + ZipEntry entry = new ZipEntry(filename); 1.56 + entry.setSize((long)buf.length); 1.57 + crc.reset(); 1.58 + crc.update(buf); 1.59 + entry.setCrc( crc.getValue()); 1.60 + s.putNextEntry(entry); 1.61 + s.write(buf, 0, buf.length); 1.62 + s.finish(); 1.63 + s.close(); 1.64 + 1.65 + String kmzString = FileUtils.readFileToString(zfile); 1.66 + writeOut.write(kmzString); 1.67 + 1.68 + //FileUtils.forceDelete(file); 1.69 + //FileUtils.forceDelete(zfile); 1.70 + 1.71 + } catch (Exception e) { 1.72 + e.printStackTrace(); 1.73 + } 1.74 1.75 } 1.76