Contents:
CheckedInputStream
CheckedOutputStream
Checksum
CRC32
DataFormatException
Deflater
DeflaterOutputStream
GZIPInputStream
GZIPOutputStream
Inflater
InflaterInputStream
ZipEntry
ZipException
ZipFile
ZipInputStream
ZipOutputStream
The package java.util.zipjava.util.zip are those that provide the means to read and write data that is compatible with the popular GZIP and ZIP formats: GZIPInputStream, GZIPOutputStream, ZipInputStream, and ZipOutputStream. Figure 18.1 shows the class hierarchy for the java.util.zip package.
It is easy to use the GZIP and ZIP classes because they subclass java.io.FilterInputStream and java.io.FilterOutputStream. For example, to decompress GZIP data, you simply create a GZIPInputStream around the input stream that represents the compressed data. As with any InputStreamread() methods of the GZIPInputStream. The following code fragment creates a GZIPInputStream that reads data from the file sample.gz :
// Now use in.read() to get decompressed data.
Similarly, you can compress data using the GZIP format by creating a GZIPOutputStream around an output stream and using the write() methods of GZIPOutputStream. The following code fragment creates a GZIPOutputStream that writes data to the file sample.gz :
new GZIPOutputStream(outFile); // Now use out.write() to write compressed data.
A ZIP file, or archive, is not quite as easy to use because it may contain more than one compressed file. A ZipEntry object represents each compressed file in the archive. When you are reading from a ZipInputStream, you must first call getNextEntry() to access an entry, and then you can read decompressed data from the stream, just like with a GZIPInputStream. When you are writing data to a ZipOutputStream, use putNextEntry() before you start writing each entry in the archive. The ZipFile
The remainder of the classes in java.util.zip exist to support the GZIP and ZIP classes. The generic Deflater and Inflater classes implement the ZLIB algorithms; they are used by DeflaterOutputStream and InflaterInputStream to decompress and compress data. The Checksum interface and the classes that implement it, Adler32 and CRC32, define algorithms that generate checksums from stream data. These checksums are used by the CheckedInputStream and CheckedOutputStream classes.
java.util.zip.Adler32
java.lang.Object
None
java.util.zip.Checksum
New as of JDK 1.1
The Adler32 class implements the Checksum interface using the Adler-32 algorithm. This algorithm is significantly faster than CRC-32 and almost as reliable.
This constructor creates an Adler32 object.
The current checksum value.
Checksum.getValue()
This method returns the current value of this checksum.
Checksum.reset()
This method resets the checksum to its initial value, making it appear as though it has not been updated by any data.
The value to be added to the data stream for the checksum calculation.
Checksum.update(int)
int.
An array of bytes to be added to the data stream for the checksum calculation.
This method adds the bytes from the specified array to the data stream and updates the checksum value.
An array of bytes to be added to the data stream for the checksum calculation.
An offset into the byte array.
The number of bytes to use.
Checksum.update(byte[], int, int)
This method adds len bytes from the specified array, starting at off, to the data stream and updates the checksum value.
|
Method |
Inherited From |
Method |
Inherited From |
|---|---|---|---|
|
clone() |
Object |
equals(Object) |
Object |
|
finalize() |
Object |
getClass() |
Object |
|
hashCode() |
Object |
notify() |
Object |
|
notifyAll() |
Object |
toString() |
Object |
|
wait() |
Object |
wait(long) |
Object |
|
wait(long, int) |
Object |
Checksum, CRC32
| Главная |