Buffered Source
A source that keeps a buffer internally so that callers can do small reads without a performance penalty. It also allows clients to read ahead, buffering as much as necessary before consuming input.
Inheritors
Properties
Functions
Returns a new source that buffers reads from source
. The returned source will perform bulk reads into its in-memory buffer. Use this wherever you read a source to get an ergonomic and efficient access to data.
Returns a source that uses cipher to encrypt or decrypt this.
Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.
Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.
Closes this source and releases the resources held by this source. It is an error to read a closed source. It is safe to close a source more than once.
Returns a GzipSource that gzip-decompresses this Source while reading.
Equivalent to indexOf(b, 0).
Equivalent to indexOf(bytes, 0).
Returns the index of the first b
in the buffer at or after fromIndex
. This expands the buffer as necessary until b
is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.
Returns the index of the first match for bytes
in the buffer at or after fromIndex
. This expands the buffer as necessary until bytes
is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are found.
Returns the index of b
if it is found in the range of fromIndex
inclusive to toIndex
exclusive. If b
isn't found, or if fromIndex == toIndex
, then -1 is returned.
Equivalent to indexOfElement(targetBytes, 0).
Returns the first index in this buffer that is at or after fromIndex
and that contains any of the bytes in targetBytes
. This expands the buffer as necessary until a target byte is found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.
Returns an InflaterSource that DEFLATE-decompresses this Source while reading.
Returns an input stream that reads from this source.
Returns a new BufferedSource
that can read data from this BufferedSource
without consuming it. The returned source becomes invalid once this source is next read or closed.
Returns true if the bytes at offset
in this source equal bytes
. This expands the buffer as necessary until a byte does not match, all bytes are matched, or if the stream is exhausted before enough bytes could determine a match.
Returns true if byteCount
bytes at offset
in this source equal bytes
at bytesOffset
. This expands the buffer as necessary until a byte does not match, all bytes are matched, or if the stream is exhausted before enough bytes could determine a match.
Removes up to sink.length
bytes from this and copies them into sink
. Returns the number of bytes read, or -1 if this source is exhausted.
Removes up to byteCount
bytes from this and copies them into sink
at offset
. Returns the number of bytes read, or -1 if this source is exhausted.
Removes at least 1, and up to byteCount
bytes from this and appends them to sink
. Returns the number of bytes read, or -1 if this source is exhausted.
Removes at least 1, and up to byteCount
bytes from this and appends them to sink
. Returns the number of bytes read, or -1 if this source is exhausted.
Removes at least 1, and up to byteCount
bytes from this and appends them to sink
. Returns the number of bytes read, or -1 if this source is exhausted.
Removes all bytes from this and returns them as a byte array.
Removes byteCount
bytes from this and returns them as a byte array.
Removes all bytes from this and returns them as a byte string.
Removes byteCount
bytes from this and returns them as a byte string.
Reads a long from this source in signed decimal form (i.e., as a string in base 10 with optional leading '-'). This will iterate until a non-digit character is found.
Removes exactly sink.length
bytes from this and copies them into sink
. Throws an java.io.EOFException if the requested number of bytes cannot be read.
Removes exactly byteCount
bytes from this and appends them to sink
. Throws an java.io.EOFException if the requested number of bytes cannot be read.
Reads a long form this source in hexadecimal form (i.e., as a string in base 16). This will iterate until a non-hexadecimal character is found.
Removes eight bytes from this source and returns a little-endian long.
Removes two bytes from this source and returns a little-endian short.
Removes all bytes from this, decodes them as charset
, and returns the string.
Removes byteCount
bytes from this, decodes them as charset
, and returns the string.
Removes all bytes from this, decodes them as UTF-8, and returns the string. Returns the empty string if this source is empty.
Removes byteCount
bytes from this, decodes them as UTF-8, and returns the string.
Removes and returns a single UTF-8 code point, reading between 1 and 4 bytes as necessary.
Removes and returns characters up to but not including the next line break. A line break is either "\n"
or "\r\n"
; these characters are not included in the result.
Removes and returns characters up to but not including the next line break. A line break is either "\n"
or "\r\n"
; these characters are not included in the result.
Like readUtf8LineStrict, except this allows the caller to specify the longest allowed match. Use this to protect against streams that may not include "\n"
or "\r\n"
.
Returns true when the buffer contains at least byteCount
bytes, expanding it as necessary. Returns false if the source is exhausted before the requested bytes can be read.
Finds the first byte string in options
that is a prefix of this buffer, consumes it from this source, and returns its index. If no byte string in options
is a prefix of this buffer this returns -1 and no bytes are consumed.