Package com.jalios.io
Class SizeLimitInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.jalios.io.SizeLimitInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
InputStream Filter that will throw an SizeLimitExceededException if the wrapped stream
exceed the byte count specified in constructor.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassSignals that a size limit has been reach during an I/O operation. -
Field Summary
Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionSizeLimitInputStream(InputStream in, long limit) Constructs a new SizeLimitInputStreamFilter. -
Method Summary
Modifier and TypeMethodDescriptionintread()Reads the next byte of data adding to the count of bytes received if a byte is successfully read.intread(byte[] b) Reads a number of bytes into the byte array, keeping count of the number read.intread(byte[] b, int off, int len) Reads a number of bytes into the byte array at a specific offset, keeping count of the number read.longskip(long length) Skips the stream over the specified number of bytes, adding the skipped amount to the count.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, resetMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
SizeLimitInputStream
Constructs a new SizeLimitInputStreamFilter.- Parameters:
in- the InputStream to delegate tolimit- the number of bytes accepted by the filter before throwing an exception
-
-
Method Details
-
read
Reads a number of bytes into the byte array, keeping count of the number read.- Overrides:
readin classFilterInputStream- Parameters:
b- the buffer into which the data is read, not null- Returns:
- the total number of bytes read into the buffer, -1 if end of stream
- Throws:
IOException- if an I/O error occurs- See Also:
-
read
Reads a number of bytes into the byte array at a specific offset, keeping count of the number read.- Overrides:
readin classFilterInputStream- Parameters:
b- the buffer into which the data is read, not nulloff- the start offset in the bufferlen- the maximum number of bytes to read- Returns:
- the total number of bytes read into the buffer, -1 if end of stream
- Throws:
IOException- if an I/O error occurs- See Also:
-
read
Reads the next byte of data adding to the count of bytes received if a byte is successfully read.- Overrides:
readin classFilterInputStream- Returns:
- the byte read, -1 if end of stream
- Throws:
IOException- if an I/O error occurs- See Also:
-
skip
Skips the stream over the specified number of bytes, adding the skipped amount to the count.- Overrides:
skipin classFilterInputStream- Parameters:
length- the number of bytes to skip- Returns:
- the actual number of bytes skipped
- Throws:
IOException- if an I/O error occurs- See Also:
-