KickJava   Java API By Example, From Geeks To Geeks.

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


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

58 public class CheckedZip32InputArchive extends Zip32InputArchive {
59     
60     public CheckedZip32InputArchive(
61             ReadOnlyFile rof,
62             String JavaDoc encoding,
63             boolean preambled,
64             boolean postambled)
65     throws NullPointerException JavaDoc,
66             UnsupportedEncodingException,
67             FileNotFoundException,
68             ZipException,
69             IOException {
70         super(rof, encoding, preambled, postambled);
71     }
72
73     /**
74      * Overridden to read from a checked input stream.
75      */

76     public InputStream getInputStream(
77             ArchiveEntry entry,
78             ArchiveEntry dstEntry)
79     throws IOException {
80         return super.getInputStream(
81                 entry.getName(), true, !(dstEntry instanceof Zip32Entry));
82     }
83 }
Popular Tags