KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > io > archive > zip > Zip32Driver


1 /*
2  * Zip32Driver.java
3  *
4  * Created on 24. Dezember 2005, 00:01
5  */

6 /*
7  * Copyright 2006 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.io.archive.zip;
23
24 import de.schlichtherle.io.archive.*;
25 import de.schlichtherle.io.archive.spi.*;
26 import de.schlichtherle.io.rof.*;
27
28 import java.io.*;
29 import java.util.zip.*;
30
31 import javax.swing.*;
32
33 /**
34  * An {@link ArchiveDriver} which builds ZIP32 archives.
35  * Note that this driver does not check the CRC value of any entries in
36  * existing archives.
37  * <p>
38  * Instances of this class are immutable.
39  *
40  * @see CheckedZip32Driver
41  *
42  * @author Christian Schlichtherle
43  * @version @version@
44  * @since TrueZIP 6.0
45  */

46 public class Zip32Driver extends AbstractArchiveDriver {
47
48     private final boolean preambled;
49
50     private final boolean postambled;
51
52     /**
53      * Equivalent to {@link #Zip32Driver(String, boolean, boolean, Icon, Icon)
54      * this("IBM437", false, false, null, null)}.
55      * These parameters are based on heuristics.
56      */

57     public Zip32Driver() {
58         this("IBM437", false, false, null, null);
59     }
60
61     /**
62      * Equivalent to {@link #Zip32Driver(String, boolean, boolean, Icon, Icon)
63      * this(encoding, false, false, null, null)}.
64      * These parameters are based on heuristics.
65      */

66     public Zip32Driver(String JavaDoc encoding) {
67         this(encoding, false, false, null, null);
68     }
69
70     /**
71      * @param encoding The character set encoding to use for entry names and
72      * comments in any archive file read or written by this driver.
73      * @param preambled <code>true</code> if and only if a prospective ZIP
74      * compatible file is allowed to contain preamble data before the
75      * actual ZIP file data.
76      * Self Extracting Archives use this feature in order to store the
77      * application code that is required to extract the ZIP file contents.
78      * <p>
79      * Please note that any ZIP compatible file may actually have a
80      * preamble. However, for performance reasons this parameter should
81      * be set to <code>false</code>, unless required.
82      * @param postambled <code>true</code> if and only if a prospective ZIP
83      * compatible file is allowed to have a postamble of arbitrary
84      * length.
85      * If set to <code>false</code>, the ZIP compatible file may still
86      * have a postamble. However, the postamble must not exceed 64KB
87      * size, including the End Of Central Directory record and thus
88      * the ZIP file comment. This causes the initial ZIP file
89      * compatibility test to fail fast if the file is not compatible
90      * to the ZIP File Format Specification.
91      * For performance reasons, this parameter should be set to
92      * <code>false</code> unless you need to support Self Extracting
93      * Archives with very large postambles.
94      * @param openIcon The icon which should be displayed if an archive of
95      * this type is in the "open" state in a
96      * {@link de.schlichtherle.io.swing.JFileChooser} or
97      * {@link de.schlichtherle.io.swing.JFileTree}.
98      * @param closedIcon The icon which should be displayed if an archive of
99      * this type is in the "closed" state in a
100      * {@link de.schlichtherle.io.swing.JFileChooser} or
101      * {@link de.schlichtherle.io.swing.JFileTree}.
102      *
103      * @see #Zip32Driver()
104      */

105     public Zip32Driver(
106             String JavaDoc encoding,
107             boolean preambled,
108             boolean postambled,
109             Icon openIcon,
110             Icon closedIcon) {
111         super(encoding, openIcon, closedIcon);
112
113         this.preambled = preambled;
114         this.postambled = postambled;
115     }
116
117     //
118
// Properties:
119
//
120

121     /**
122      * Returns <code>true</code> if and only if a prospective ZIP compatible
123      * file is allowed to contain preamble data before the actual ZIP file data.
124      * Self Extracting Archives use this feature in order to store the
125      * application code that is required to extract the ZIP file contents.
126      */

127     public boolean getPreambled() {
128         return preambled;
129     }
130
131     /**
132      * Returns <code>true</code> if and only if a prospective ZIP compatible
133      * file is allowed to have a postamble of arbitrary length.
134      * If set to <code>false</code>, the ZIP compatible file may still have
135      * a postamble. However, the postamble must not exceed 64KB size, including
136      * the End Of Central Directory record and thus the ZIP file comment.
137      * This causes the initial ZIP file compatibility test to fail fast if
138      * the file is not compatible to the ZIP File Format Specification.
139      * For performance reasons, this parameter should be set to
140      * <code>false</code> unless you need to support Self Extracting Archives
141      * with very large postambles.
142      */

143     public boolean getPostambled() {
144         return postambled;
145     }
146
147     //
148
// Factory methods:
149
//
150

151     public ArchiveEntry createArchiveEntry(
152             final Archive archive,
153             final String JavaDoc entryName,
154             final ArchiveEntry blueprint)
155     throws CharConversionException {
156         ensureEncodable(entryName);
157
158         final Zip32Entry entry;
159         if (blueprint != null) {
160             if (blueprint instanceof Zip32Entry) {
161                 entry = new Zip32Entry(entryName, (Zip32Entry) blueprint);
162             } else {
163                 entry = new Zip32Entry(entryName);
164                 entry.setTime(blueprint.getTime());
165             }
166         } else {
167             entry = new Zip32Entry(entryName);
168         }
169         
170         return entry;
171     }
172
173     public InputArchive createInputArchive(Archive archive, ReadOnlyFile rof)
174     throws UnsupportedEncodingException, FileNotFoundException, IOException {
175         return createZip32InputArchive(
176                 rof, getEncoding(), getPreambled(), getPostambled());
177     }
178
179     protected Zip32InputArchive createZip32InputArchive(
180             ReadOnlyFile rof,
181             String JavaDoc encoding,
182             boolean preambled,
183             boolean postambled)
184     throws NullPointerException JavaDoc,
185             UnsupportedEncodingException,
186             FileNotFoundException,
187             ZipException,
188             IOException {
189         return new Zip32InputArchive(rof, encoding, preambled, postambled);
190     }
191
192     public OutputArchive createOutputArchive(
193             final Archive archive,
194             final OutputStream out,
195             final InputArchive source)
196     throws UnsupportedEncodingException, IOException {
197         return createZip32OutputArchive(
198                 out, getEncoding(), (Zip32InputArchive) source);
199     }
200
201     protected Zip32OutputArchive createZip32OutputArchive(
202             final OutputStream out,
203             final String JavaDoc encoding,
204             final Zip32InputArchive source)
205     throws NullPointerException JavaDoc,
206             UnsupportedEncodingException,
207             IOException {
208         return new Zip32OutputArchive(out, encoding, source);
209     }
210 }
211
Popular Tags