1 8 package org.ozoneDB.core.storage.gammaStore; 9 10 import java.io.IOException ; 11 import java.io.InputStream ; 12 import java.io.OutputStream ; 13 import java.util.Collection ; 14 import java.util.LinkedList ; 15 import java.util.List ; 16 import java.util.Properties ; 17 import java.util.zip.GZIPInputStream ; 18 import java.util.zip.GZIPOutputStream ; 19 import java.util.zip.ZipEntry ; 20 import java.util.zip.ZipInputStream ; 21 import java.util.zip.ZipOutputStream ; 22 import org.ozoneDB.core.storage.PropertyConfigurable; 23 import org.ozoneDB.core.storage.PropertyInfo; 24 25 32 public class ZipStreamFactory implements StreamFactory, PropertyConfigurable { 33 34 public static final PropertyInfo LEVEL = new PropertyInfo( 35 ".level", 36 "[0-9]", 37 "1", 38 "compression level, see java.util.zip.ZipOutputStream.setLevel(int)", 39 new String [] {"1", "4"} 40 ); 41 42 public static final PropertyInfo METHOD = new PropertyInfo( 43 ".method", 44 "int", 45 "8", 46 "method used for compression, see java.util.zip.ZipOutputStream.setMethod(int)", 47 new String [] {"8 (DEFLATED)"} 48 ); 49 50 public static final PropertyInfo ENTRYNAME = new PropertyInfo( 51 ".entryName", 52 "String", 53 "O", 54 "name for the ZipEntry in the zip file", 55 new String [] {"entry", "FooBar", "R_Daneel_Olivaw"} 56 ); 57 58 private String prefix; 59 private int method; 60 private int level; 61 private String entryName; 62 63 66 public ZipStreamFactory(Properties properties, String prefix) { 67 System.out.println(properties + " " + prefix); 68 this.prefix = prefix; 69 method = Integer.parseInt(properties.getProperty(prefix + METHOD.getKey(), METHOD.getDefaultValue())); 70 level = Integer.parseInt(properties.getProperty(prefix + LEVEL, LEVEL.getDefaultValue())); 71 entryName = properties.getProperty(prefix + ENTRYNAME, ENTRYNAME.getDefaultValue()); 72 } 73 74 public InputStream createInputStream(InputStream in) throws IOException { 75 ZipInputStream result = new ZipInputStream (in); 76 result.getNextEntry(); 77 return result; 78 } 79 80 public OutputStream createOutputStream(OutputStream out) throws IOException { 81 ZipOutputStream result = new ZipOutputStream (out); 82 result.putNextEntry(new ZipEntry (entryName)); 83 return result; 84 } 85 86 public Collection getPropertyInfos() { 87 Collection result = new LinkedList (); 88 result.add(LEVEL); 89 result.add(METHOD); 90 return result; 91 } 92 93 public String getPrefix() { 94 return prefix; 95 } 96 97 } 98 | Popular Tags |