public class

CheckedInputStream

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

Class Overview

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

[Expand]
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[] buf, int off, int nbytes)
Reads up to n bytes of data from the underlying input stream, storing it into buf, starting at offset off.
long skip(long nbytes)
Skip up to n bytes of data on the underlying input stream.
[Expand]
Inherited Methods
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable

Public Constructors

public CheckedInputStream (InputStream is, Checksum csum)

Since: API Level 1

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 the input stream to calculate checksum from.
csum an entity implementing the checksum algorithm.

Public Methods

public Checksum getChecksum ()

Since: API Level 1

Returns the checksum calculated on the stream read so far.

Returns
  • the updated checksum.

public int read ()

Since: API Level 1

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

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

public int read (byte[] buf, int off, int nbytes)

Since: API Level 1

Reads up to n bytes of data from the underlying input stream, storing it into buf, starting at offset off. The checksum is updated with the bytes read.

Parameters
buf the byte array in which to store the bytes read.
off the initial position in buf to store the bytes read from this stream.
nbytes the maximum number of bytes to store in buf.
Returns
  • the number of bytes actually read or -1 if arrived at the end of the filtered stream while reading the data.
Throws
IOException if this stream is closed or some I/O error occurs.

public long skip (long nbytes)

Since: API Level 1

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

Parameters
nbytes the number of bytes to skip.
Returns
  • the number of bytes skipped.
Throws
IOException if this stream is closed or another I/O error occurs.