Class CheckedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.util.zip.CheckedInputStream
- All Implemented Interfaces:
Closeable, AutoCloseable
public class CheckedInputStream extends FilterInputStream
An input stream that also maintains a checksum of the data being read. The checksum can then be used to verify the integrity of the input data.
- Since:
- 1.1
- See Also:
Field Summary
Fields declared in class FilterInputStream
in | Modifier and Type | Field | Description |
|---|---|---|
protected InputStream |
in |
The input stream to be filtered. |
Constructor Summary
| Constructor | Description |
|---|---|
CheckedInputStream |
Creates an input stream using the specified Checksum. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
Checksum |
getChecksum() |
Returns the Checksum for this input stream. |
int |
read() |
Reads a byte. |
int |
read |
Reads into an array of bytes. |
long |
skip |
Skips specified number of bytes of input. |
Methods declared in class FilterInputStream
available, close, mark, markSupported, read, reset | Modifier and Type | Method | Description |
|---|---|---|
int |
available() |
Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. |
void |
close() |
Closes this input stream and releases any system resources associated with the stream. |
void |
mark |
Marks the current position in this input stream. |
boolean |
markSupported() |
Tests if this input stream supports the mark and reset methods. |
int |
read |
Reads up to b.length bytes of data from this input stream into an array of bytes. |
void |
reset() |
Repositions this stream to the position at the time the mark method was last called on this input stream. |
Methods declared in class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo | Modifier and Type | Method | Description |
|---|---|---|
static InputStream |
nullInputStream() |
Returns a new InputStream that reads no bytes. |
byte[] |
readAllBytes() |
Reads all remaining bytes from the input stream. |
int |
readNBytes |
Reads the requested number of bytes from the input stream into the given byte array. |
byte[] |
readNBytes |
Reads up to a specified number of bytes from the input stream. |
void |
skipNBytes |
Skips over and discards exactly n bytes of data from this input stream. |
long |
transferTo |
Reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Constructor Details
CheckedInputStream
public CheckedInputStream(InputStream in, Checksum cksum)
Creates an input stream using the specified Checksum.
- Parameters:
-
in- the input stream -
cksum- the Checksum
Method Details
read
public int read() throws IOException
Reads a byte. Will block if no input is available.
- Overrides:
-
readin classFilterInputStream - Returns:
- the byte read, or -1 if the end of the stream is reached.
- Throws:
-
IOException- if an I/O error has occurred - See Also:
read
public int read(byte[] buf, int off, int len) throws IOException
Reads into an array of bytes. If
len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.- Overrides:
-
readin classFilterInputStream - Parameters:
-
buf- the buffer into which the data is read -
off- the start offset in the destination arrayb -
len- the maximum number of bytes read - Returns:
- the actual number of bytes read, or -1 if the end of the stream is reached.
- Throws:
-
NullPointerException- Ifbufisnull. -
IndexOutOfBoundsException- Ifoffis negative,lenis negative, orlenis greater thanbuf.length - off -
IOException- if an I/O error has occurred - See Also:
skip
public long skip(long n) throws IOException
Skips specified number of bytes of input.
- Overrides:
-
skipin classFilterInputStream - Parameters:
-
n- the number of bytes to skip - Returns:
- the actual number of bytes skipped
- Throws:
-
IOException- if an I/O error has occurred - See Also:
getChecksum
public Checksum getChecksum()
Returns the Checksum for this input stream.
- Returns:
- the Checksum value
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.