Skip to content

Most visited

Recently visited

navigation
Added in API level 1

CheckedInputStream

public class CheckedInputStream
extends FilterInputStream

java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.util.zip.CheckedInputStream


The CheckedInputStream class is used to maintain a checksum at the same time as the data, on which the checksum is computed, is read from a stream. The purpose of this checksum is to establish data integrity, comparing the computed checksum against a published checksum value.

Summary

Inherited fields

From class java.io.FilterInputStream

Public constructors

CheckedInputStream(InputStream is, Checksum csum)

Constructs a new CheckedInputStream on InputStream is.

Public methods

Checksum getChecksum()

Returns the checksum calculated on the stream read so far.

int read()

Reads one byte of data from the underlying input stream and updates the checksum with the byte data.

int read(byte[] buffer, int byteOffset, int byteCount)

Reads up to byteCount bytes of data from the underlying input stream, storing it into buffer, starting at offset byteOffset.

long skip(long byteCount)

Skip up to byteCount bytes of data on the underlying input stream.

Inherited methods

From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public constructors

CheckedInputStream

Added in API level 1
CheckedInputStream (InputStream is, 
                Checksum csum)

Constructs a new CheckedInputStream on InputStream is. The checksum will be calculated using the algorithm implemented by csum.

Warning: passing a null source creates an invalid CheckedInputStream. All operations on such a stream will fail.

Parameters
is InputStream: the input stream to calculate checksum from.
csum Checksum: an entity implementing the checksum algorithm.

Public methods

getChecksum

Added in API level 1
Checksum getChecksum ()

Returns the checksum calculated on the stream read so far.

Returns
Checksum

read

Added in API level 1
int read ()

Reads one byte of data from the underlying input stream and updates the checksum with the byte data.

Returns
int -1 at the end of the stream, a single byte value otherwise.
Throws
IOException if an IOException occurs.

read

Added in API level 1
int read (byte[] buffer, 
                int byteOffset, 
                int byteCount)

Reads up to byteCount bytes of data from the underlying input stream, storing it into buffer, starting at offset byteOffset. The checksum is updated with the bytes read. Returns the number of bytes actually read or -1 if arrived at the end of the filtered stream while reading the data.

Parameters
buffer byte
byteOffset int
byteCount int
Returns
int
Throws
IOException if this stream is closed or some I/O error occurs.

skip

Added in API level 1
long skip (long byteCount)

Skip up to byteCount bytes of data on the underlying input stream. Any skipped bytes are added to the running checksum value.

Parameters
byteCount long: the number of bytes to skip.
Returns
long the number of bytes skipped.
Throws
IOException if this stream is closed or another I/O error occurs.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.