KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > gammaStore > ZipStreamFactory


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Core License version 1 published by ozone-db.org.
3
//
4
// Copyright (C) 2003-@year@, Leo Mekenkamp. All rights reserved.
5
//
6
// $Id: ZipStreamFactory.java,v 1.1 2004/01/02 09:24:38 leomekenkamp Exp $
7

8 package org.ozoneDB.core.storage.gammaStore;
9
10 import java.io.IOException JavaDoc;
11 import java.io.InputStream JavaDoc;
12 import java.io.OutputStream JavaDoc;
13 import java.util.Collection JavaDoc;
14 import java.util.LinkedList JavaDoc;
15 import java.util.List JavaDoc;
16 import java.util.Properties JavaDoc;
17 import java.util.zip.GZIPInputStream JavaDoc;
18 import java.util.zip.GZIPOutputStream JavaDoc;
19 import java.util.zip.ZipEntry JavaDoc;
20 import java.util.zip.ZipInputStream JavaDoc;
21 import java.util.zip.ZipOutputStream JavaDoc;
22 import org.ozoneDB.core.storage.PropertyConfigurable;
23 import org.ozoneDB.core.storage.PropertyInfo;
24
25 /**
26  * Factory that creates streams that read/write to other streams via a Zip
27  * stream.
28  *
29  * @author <a HREF="mailto:leoATmekenkampD0Tcom">Leo Mekenkamp (mind the anti sp@m)</a>
30  * @version $Id: ZipStreamFactory.java,v 1.1 2004/01/02 09:24:38 leomekenkamp Exp $
31  */

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 JavaDoc[] {"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 JavaDoc[] {"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 JavaDoc[] {"entry", "FooBar", "R_Daneel_Olivaw"}
56     );
57     
58     private String JavaDoc prefix;
59     private int method;
60     private int level;
61     private String JavaDoc entryName;
62     
63     /**
64      * As prescribed by the <code>PropertyConfigurable</code> interface.
65      */

66     public ZipStreamFactory(Properties JavaDoc properties, String JavaDoc 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 JavaDoc createInputStream(InputStream JavaDoc in) throws IOException JavaDoc {
75         ZipInputStream JavaDoc result = new ZipInputStream JavaDoc(in);
76         result.getNextEntry();
77         return result;
78     }
79     
80     public OutputStream JavaDoc createOutputStream(OutputStream JavaDoc out) throws IOException JavaDoc {
81         ZipOutputStream JavaDoc result = new ZipOutputStream JavaDoc(out);
82         result.putNextEntry(new ZipEntry JavaDoc(entryName));
83         return result;
84     }
85  
86     public Collection JavaDoc getPropertyInfos() {
87         Collection JavaDoc result = new LinkedList JavaDoc();
88         result.add(LEVEL);
89         result.add(METHOD);
90         return result;
91     }
92     
93     public String JavaDoc getPrefix() {
94         return prefix;
95     }
96     
97 }
98
Popular Tags