Package dev.omnist.document
Class InputSize
java.lang.Object
dev.omnist.document.InputSize
The one place the input-size bound lives (omnist-spec section 2.4.2, D-23 to D-26).
A reader refuses an input of more than Limits.maxInputBytes() bytes with the code
"document.limit.input-size" at path $, before decoding or parsing; an input of exactly the maximum is
accepted. The unit is bytes, not characters, and the count is taken on the input as received:
a leading byte-order mark counts (three bytes), because the check runs before the BOM is stripped.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckLength(long length, int maxBytes, String advice) Checks the size of a byte array.static booleanWhethertextis more thanmaxBytesUTF-8 bytes long.static StringThe message of a refusal for text of known size.static byte[]readBounded(InputStream in, int maxBytes, String advice) Readsinto its end, stopping as soon as it is known to hold more thanmaxBytes: at mostmaxBytes + 1bytes are ever buffered.static DocumentParseExceptionThe refusal for text over the maximum.static longutf8Length(CharSequence text) The length oftextin UTF-8 bytes, counted without allocating an encoded copy.
-
Field Details
-
CODE
document.limit.input-size: the input is larger than the maximum (D-23).- See Also:
-
-
Method Details
-
utf8Length
The length oftextin UTF-8 bytes, counted without allocating an encoded copy. A lone surrogate has no UTF-8 encoding and is counted as the three bytes of U+FFFD.- Parameters:
text- the text- Returns:
- its UTF-8 length
-
exceeds
Whethertextis more thanmaxBytesUTF-8 bytes long. Decides without a scan when the character count alone settles it: every character is at least one byte (a surrogate pair is two characters and four bytes), and at most three bytes per character.- Parameters:
text- the text, ornull(never over the limit)maxBytes- the maximum- Returns:
trueif the text is over the maximum
-
message
The message of a refusal for text of known size.- Parameters:
text- the refused textmaxBytes- the maximum it exceeded- Returns:
- the message
-
refusal
The refusal for text over the maximum.- Parameters:
text- the refused textmaxBytes- the maximum it exceeded- Returns:
- the exception to throw
-
readBounded
Readsinto its end, stopping as soon as it is known to hold more thanmaxBytes: at mostmaxBytes + 1bytes are ever buffered.- Parameters:
in- the streammaxBytes- the maximum accepted sizeadvice- appended to the refusal message, saying how to raise the maximum- Returns:
- the bytes read, at most
maxBytesof them - Throws:
IOException- if the stream failsDocumentParseException- with code "document.limit.input-size" at$if the stream holds more
-
checkLength
Checks the size of a byte array.- Parameters:
length- the length of the input in bytesmaxBytes- the maximum accepted sizeadvice- appended to the refusal message, saying how to raise the maximum- Throws:
DocumentParseException- with code "document.limit.input-size" at$iflength > maxBytes
-