Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 880
نمايش فراداده

CheckedInputStreamjava.util.zip

Java 1.1closeable

This class is a subclass of java.io.FilterInputStream; it allows a stream to be read and a checksum computed on its contents at the same time. This is useful when you want to check the integrity of a stream of data against a published checksum value. To create a CheckedInputStream, you must specify both the stream it should read and a Checksum object, such as CRC32, that implements the particular checksum algorithm you desire. The read( ) and skip( ) methods are the same as those of other input streams. As bytes are read, they are incorporated into the checksum that is being computed. The getChecksum( ) method does not return the checksum value itself, but rather the Checksum object. You must call the getValue( ) method of this object to obtain the checksum value.

Figure 16-135. java.util.zip.CheckedInputStream

public class

CheckedInputStream extends java.io.FilterInputStream { // Public Constructors public

CheckedInputStream (java.io.InputStream

in , Checksum

cksum ); // Public Instance Methods public Checksum

getChecksum ( ); // Public Methods Overriding FilterInputStream public int

read ( ) throws java.io.IOException; public int

read (byte[ ]

buf , int

off , int

len ) throws java.io.IOException; public long

skip (long

n ) throws java.io.IOException; }