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:
Checksum
Fields
Fields declared in class java.io.FilterInputStream
in
Constructors
Constructor | Description |
---|---|
CheckedInputStream(InputStream in,
Checksum cksum) | Creates an input stream using the specified Checksum. |
Methods
Modifier and Type | Method | Description |
---|---|---|
Checksum | getChecksum() | Returns the Checksum for this input stream. |
int | read() | Reads a byte. |
int | read(byte[] buf,
int off,
int len) | Reads into an array of bytes. |
long | skip(long n) | Skips specified number of bytes of input. |
Methods declared in class java.io.FilterInputStream
available, close, mark, markSupported, read, reset
Methods declared in class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
Methods declared in class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructors
CheckedInputStream
public CheckedInputStream(InputStream in, Checksum cksum)
Creates an input stream using the specified Checksum.
- Parameters:
-
in
- the input stream -
cksum
- the Checksum
Methods
read
public int read() throws IOException
Reads a byte. Will block if no input is available.
- Overrides:
-
read
in 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:
FilterInputStream.in
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:
-
read
in 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
- Ifbuf
isnull
. -
IndexOutOfBoundsException
- Ifoff
is negative,len
is negative, orlen
is greater thanbuf.length - off
-
IOException
- if an I/O error has occurred - See Also:
FilterInputStream.in
skip
public long skip(long n) throws IOException
Skips specified number of bytes of input.
- Overrides:
-
skip
in 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
getChecksum
public Checksum getChecksum()
Returns the Checksum for this input stream.
- Returns:
- the Checksum value
© 1993, 2020, 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.
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/zip/CheckedInputStream.html