Class ChecksumValidatingInputStream
- java.lang.Object
-
- java.io.InputStream
-
- software.amazon.awssdk.core.internal.io.ChecksumValidatingInputStream
-
- All Implemented Interfaces:
Closeable,AutoCloseable,software.amazon.awssdk.http.Abortable
public class ChecksumValidatingInputStream extends InputStream implements software.amazon.awssdk.http.Abortable
Stream that will update the Checksum as the data is read. When end of the stream is reached the computed Checksum is validated with Expected checksum.
-
-
Constructor Summary
Constructors Constructor Description ChecksumValidatingInputStream(InputStream inputStream, SdkChecksum sdkChecksum, String expectedChecksum)Creates an input stream using the specified Checksum, input stream, and length.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()voidclose()intread()Reads from the underlying stream.intread(byte[] buf, int off, int len)Reads up to len bytes at a time from the input stream, updates the checksum.voidreset()Resets stream state, including the running checksum.-
Methods inherited from class java.io.InputStream
available, mark, markSupported, read, skip
-
-
-
-
Constructor Detail
-
ChecksumValidatingInputStream
public ChecksumValidatingInputStream(InputStream inputStream, SdkChecksum sdkChecksum, String expectedChecksum)
Creates an input stream using the specified Checksum, input stream, and length.- Parameters:
inputStream- the input streamsdkChecksum- the Checksum implementationexpectedChecksum- the checksum value as seen un .
-
-
Method Detail
-
read
public int read() throws IOExceptionReads from the underlying stream. If the end of the stream is reached, the running checksum will be appended a byte at a time (1 per read call).- Specified by:
readin classInputStream- Returns:
- byte read, if eos has been reached, -1 will be returned.
- Throws:
IOException
-
read
public int read(byte[] buf, int off, int len) throws IOExceptionReads up to len bytes at a time from the input stream, updates the checksum. If the end of the stream has been reached the checksum will be appended to the last 4 bytes.- Overrides:
readin classInputStream- Parameters:
buf- buffer to write intooff- offset in the buffer to write tolen- maximum number of bytes to attempt to read.- Returns:
- number of bytes written into buf, otherwise -1 will be returned to indicate eos.
- Throws:
IOException
-
reset
public void reset() throws IOExceptionResets stream state, including the running checksum.- Overrides:
resetin classInputStream- Throws:
IOException
-
abort
public void abort()
- Specified by:
abortin interfacesoftware.amazon.awssdk.http.Abortable
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
-