Package org.apache.activemq.transport
Class FrameSizeLimitedFilterInputStream
java.lang.Object
java.io.InputStream
org.apache.activemq.transport.FrameSizeLimitedFilterInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A filtered style input stream that allows reads up to a given known max frame size
before it starts to throw exceptions indicating the reader has exceeded the set
limit. This can be used to wrap another stream that contains a protocol frame to
be parsed and enforce that decoding of that frame does not cross the boundary set
as the max available bytes before error.
This is a specialized stream type that may obfuscate the actual state of the underlying stream such as its actual available bytes. The user should be aware of the behavior of this stream when using it to ensure they do not run into unexpected failures. It is possible to configure this stream with a higher available limit than the underlying stream actually has access to but that inconsistency is left as a requirement for the caller to handle.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new uninitialized instance of the filter stream that will fail to read until a stream and a frame size limit is configured.FrameSizeLimitedFilterInputStream(int available, InputStream in) Create a new instance with the given amount of available bytes that should be readable before an exception is thrown indicating that more bytes where requested from the known fixed frame size than is allowed. -
Method Summary
Modifier and TypeMethodDescriptionintvoidclose()Render the stream unusable until a reset is called that either changes the stream and assigns a new max or simply assigns a new max which assumes that the underlying stream remains readable which is only a subset of stream types such as byte array wrapper variants.voidmark(int readLimit) booleanintread()intread(byte[] b) intread(byte[] b, int off, int len) voidreset()voidResets the number of available bytes that can be read from the underlying stream.voidresetAvailable(int available) Resets the number of available bytes that can be read from the underlying stream to the new amount.voidresetAvailable(InputStream in, int available) Resets the number of available bytes and assigns a new stream that can be read from the which allows this type to be re-usable across command reads.longskip(long amount) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
FrameSizeLimitedFilterInputStream
public FrameSizeLimitedFilterInputStream()Create a new uninitialized instance of the filter stream that will fail to read until a stream and a frame size limit is configured. -
FrameSizeLimitedFilterInputStream
Create a new instance with the given amount of available bytes that should be readable before an exception is thrown indicating that more bytes where requested from the known fixed frame size than is allowed.- Parameters:
available- The number of available bytes to allow in a given frame.in- TheInputStreamto read from (cannot be null).
-
-
Method Details
-
close
Render the stream unusable until a reset is called that either changes the stream and assigns a new max or simply assigns a new max which assumes that the underlying stream remains readable which is only a subset of stream types such as byte array wrapper variants.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
resetAvailable
public void resetAvailable()Resets the number of available bytes that can be read from the underlying stream. The underlying stream may still throw exceptions if it cannot provide this many bytes. As a result of calling this method any currently set mark is cleared and the stream cannot be reset back to a previously available number of bytes from this point onward.Calling this method on a stream wrapper that has not been initialized will not result in a readable state, the limit remains zero.
-
resetAvailable
public void resetAvailable(int available) Resets the number of available bytes that can be read from the underlying stream to the new amount. The underlying stream may still throw exceptions if it cannot provide this many bytes. As a result of calling this method any currently set mark is cleared and the stream cannot be reset back to a previously available number of bytes from this point onward.- Parameters:
available- The new available number of bytes to allow from this stream wrapper
-
resetAvailable
Resets the number of available bytes and assigns a new stream that can be read from the which allows this type to be re-usable across command reads. The underlying stream may still throw exceptions if it cannot provide this many bytes. As a result of calling this method any currently set mark is cleared and the stream cannot be reset back to a previously available number of bytes from this point onward.- Parameters:
in- The new input stream to read bytes from (cannot be assigned as null).available- The new available number of bytes to allow from this stream wrapper
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
mark
public void mark(int readLimit) - Overrides:
markin classInputStream
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-