Class ParserInputStream
java.lang.Object
java.io.InputStream
org.apache.juneau.marshall.parser.ParserInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable,Positionable
- Direct Known Subclasses:
BsonInputStream,CborInputStream,MsgPackInputStream
Input stream meant to be used as input for stream-based parsers.
Keeps track of current byte position.
Notes:
- This class is not thread safe.
See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcheckLength(long len, long maxLength, String what) Validates a wire-declared length/count against sane bounds before it is used to size an allocation or drive a container loop.intcheckLength(long len, String what) Validates a wire-declared length/count against sane bounds before it is used to size an allocation or drive a container loop, using this stream's configured maximum.Returns the current position in a reader or input stream.intread()voidsetMaxLength(int value) Sets the maximum allowed wire-declared length (in bytes) for payloads and element counts read off the stream before they are used to size an allocation or drive a container loop.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
ParserInputStream
Constructor.- Parameters:
pipe- The parser input.
Must not benull .- Throws:
IOException- Thrown by underlying stream.
-
-
Method Details
-
setMaxLength
Sets the maximum allowed wire-declared length (in bytes) for payloads and element counts read off the stream before they are used to size an allocation or drive a container loop.Guards against malformed input where a small payload declares a huge or negative length that would otherwise trigger
OutOfMemoryErrororNegativeArraySizeException.- Parameters:
value- The maximum length in bytes. Values ≤ 0 disable the cap (only the negative-length check remains).
-
checkLength
Validates a wire-declared length/count against sane bounds before it is used to size an allocation or drive a container loop, using this stream's configured maximum.- Parameters:
len- The declared length/count read off the wire.what- A short description of the field being read (for the error message).- Returns:
- The validated length as an int.
- Throws:
IOException- If the length is negative (or beyond int range) or exceeds the configured maximum.
-
checkLength
Validates a wire-declared length/count against sane bounds before it is used to size an allocation or drive a container loop.Shared bounds-check used by the stream-based parsers and by other low-level readers (such as the Protobuf reader) that do not extend this class but need the same guard.
- Parameters:
len- The declared length/count read off the wire.maxLength- The maximum allowed length. Values ≤ 0 are treated asInteger.MAX_VALUE(only the negative-length check applies).what- A short description of the field being read (for the error message).- Returns:
- The validated length as an int.
- Throws:
IOException- If the length is negative (or beyond int range) or exceeds the configured maximum.
-
getPosition
Description copied from interface:PositionableReturns the current position in a reader or input stream.- Specified by:
getPositionin interfacePositionable- Returns:
- The current position in a reader or input stream.
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-