public class LengthCheckInputStream extends SdkFilterInputStream
Modifier and Type | Field and Description |
---|---|
private long |
dataLength
The length of the data read from the underlying input stream so far.
|
static boolean |
EXCLUDE_SKIPPED_BYTES |
private long |
expectedLength
Total number of bytes expected to be read from the underlying input
stream.
|
static boolean |
INCLUDE_SKIPPED_BYTES |
private boolean |
includeSkipped
True if skipped bytes are to be included as part of the data length;
false otherwise.
|
private int |
markCount |
private long |
marked |
private int |
resetCount |
private boolean |
resetSinceLastMarked
Used for diagnostic purposes.
|
Constructor and Description |
---|
LengthCheckInputStream(java.io.InputStream in,
long expectedLength,
boolean includeSkipped)
Constructs an input stream that performs length check to ensure the
number of bytes read from the underlying input stream is the same as the
expected total.
|
Modifier and Type | Method and Description |
---|---|
private void |
checkLength(boolean eof)
Checks the data length read so far against the expected total.
|
private java.lang.String |
diagnosticInfo() |
void |
mark(int readlimit) |
int |
read() |
int |
read(byte[] b,
int off,
int len) |
void |
reset() |
long |
skip(long n) |
abort, abortIfNeeded, available, close, isMetricActivated, markSupported, release
public static final boolean INCLUDE_SKIPPED_BYTES
public static final boolean EXCLUDE_SKIPPED_BYTES
private final long expectedLength
private final boolean includeSkipped
private long dataLength
private long marked
private boolean resetSinceLastMarked
private int markCount
private int resetCount
public LengthCheckInputStream(java.io.InputStream in, long expectedLength, boolean includeSkipped)
in
- the underlying input streamexpectedLength
- the total length of the data in bytes expected to be read from
the underlying input stream; must be non-negative.includeSkipped
- true if bytes skipped are to be considered as part of the data
length; false otherwise. Typically, this parameter should be
set to false for uploading data to AWS, but set to true for
receiving data from AWS.public int read() throws java.io.IOException
read
in class SdkFilterInputStream
AmazonClientException
- if the data length read has exceeded the expected total, or
if the total data length is not the same as the expected
total.java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
read
in class SdkFilterInputStream
AmazonClientException
- if the data length read has exceeded the expected total, or
if the total data length is not the same as the expected
total.java.io.IOException
public void mark(int readlimit)
mark
in class SdkFilterInputStream
public void reset() throws java.io.IOException
reset
in class SdkFilterInputStream
java.io.IOException
private void checkLength(boolean eof)
eof
- true if end of stream has been encountered; false otherwiseAmazonClientException
- if the data length read has exceeded the expected total, or
if the total data length is not the same as the expected
total.private java.lang.String diagnosticInfo()
public long skip(long n) throws java.io.IOException
skip
in class SdkFilterInputStream
AmazonClientException
- if includeSkipped
is true and the data length
skipped has exceeded the expected total.java.io.IOException