Class InputStreams
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanatEndOfStream(InputStream input) Reports whether the stream is exhausted, consuming nothing when it is not.static InputStreammarkable(InputStream input) Returns a stream that supportsmark, wrapping the given stream only if it does not already.static byte[]readFully(InputStream input, int length) Reads exactly the specified number of bytes from the input stream.
-
Method Details
-
markable
Returns a stream that supportsmark, wrapping the given stream only if it does not already.Only for a codec that reads its input to end-of-stream. Wrapping buffers ahead, so a codec that returns while bytes remain would leave them in a wrapper its caller cannot see, and whatever decodes next would read from the wrong position. A codec that stops short must instead require
markSupportedof its caller, asrepeatWhiledoes, or avoid rewinding altogether, aschoicedoes.Composite codecs that peek before decoding an item should pass the result down rather than the original stream, so that combinators needing to rewind can be nested inside them.
ByteArrayInputStreamandBufferedInputStreamalready support mark and are returned unchanged;FileInputStream, socket streams andPushbackInputStreamdo not.- Parameters:
input- the stream to make markable, read to end-of-stream by the caller- Returns:
inputif it supports mark, otherwise a buffered wrapper- Throws:
NullPointerException- if input is null
-
atEndOfStream
Reports whether the stream is exhausted, consuming nothing when it is not.The stream must support
mark; pass it throughmarkable(InputStream)first.- Parameters:
input- a markable stream- Returns:
- true if the next read would return end-of-stream
- Throws:
IOException- if an I/O error occurs
-
readFully
Reads exactly the specified number of bytes from the input stream.- Parameters:
input- the input stream to read fromlength- the exact number of bytes to read- Returns:
- a byte array containing the bytes read
- Throws:
IllegalArgumentException- if length is negativeIOException- if an I/O error occursEOFException- if the stream ends before the required bytes are read
-