KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * CheckedZip32Driver.java
3  *
4  * Created on 29. Juni 2006, 20:58
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.rof.*;
25
26 import java.io.*;
27 import java.util.zip.*;
28
29 import javax.swing.*;
30
31 /**
32  * A {@link Zip32Driver} which checks the CRC-32 values for all ZIP entries
33  * in input archives.
34  * The additional CRC-32 computation makes this class slower than its super
35  * class.
36  * <p>
37  * If there is a mismatch of the CRC-32 values for a ZIP entry in an input
38  * archive, the {@link InputStream#close} method of the corresponding stream
39  * for the archive entry will throw a
40  * {@link de.schlichtherle.util.zip.CRC32Exception}.
41  * This exception is then propagated through the stack up to the corresponding
42  * file operation in the package <code>de.schlichtherle.io</code> where it is
43  * either allowed to pass on or is catched and processed accordingly.
44  * For example, the {@link de.schlichtherle.io.FileInputStream#close()}
45  * method would allow the <code>CRC32Exception</code> to pass on to the
46  * client application, whereas the
47  * {@link de.schlichtherle.io.File#catTo(OutputStream)} method would simply
48  * return <code>false</code>.
49  * Other than this, the archive entry will be processed normally.
50  * So if just the CRC-32 value for the entry in the archive file has been
51  * modified, you can still read its entire contents.
52  * <p>
53  * Instances of this class are immutable.
54  *
55  * @see Zip32Driver
56  * @see CheckedZip32InputArchive
57  * @see CheckedZip32OutputArchive
58  *
59  * @author Christian Schlichtherle
60  * @version @version@
61  * @since TrueZIP 6.1
62  */

63 public class CheckedZip32Driver extends Zip32Driver {
64
65     /**
66      * Equivalent to {@link #CheckedZip32Driver(String, boolean, boolean, Icon, Icon)
67      * this("CP437", false, false, null, null)}.
68      * These parameters are based on heuristics.
69      */

70     public CheckedZip32Driver() {
71         this("CP437", false, false, null, null);
72     }
73
74     /**
75      * Equivalent to {@link #CheckedZip32Driver(String, boolean, boolean, Icon, Icon)
76      * this(encoding, false, false, null, null)}.
77      * These parameters are based on heuristics.
78      */

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

118     public CheckedZip32Driver(
119             String JavaDoc encoding,
120             boolean preambled,
121             boolean postambled,
122             Icon openIcon,
123             Icon closedIcon) {
124         super(encoding, preambled, postambled, openIcon, closedIcon);
125     }
126     
127     protected Zip32InputArchive createZip32InputArchive(
128             ReadOnlyFile rof,
129             String JavaDoc encoding,
130             boolean preambled,
131             boolean postambled)
132     throws NullPointerException JavaDoc,
133             UnsupportedEncodingException,
134             FileNotFoundException,
135             ZipException,
136             IOException {
137         return new CheckedZip32InputArchive(rof, encoding, preambled, postambled);
138     }
139 }
140
Popular Tags