public interface BufferedSource extends Source
Modifier and Type | Method and Description |
---|---|
Buffer |
buffer()
Returns this source's internal buffer.
|
boolean |
exhausted()
Returns true if there are no more bytes in this source.
|
long |
indexOf(byte b)
Returns the index of the first
b in the buffer. |
long |
indexOf(byte b,
long fromIndex)
Returns the index of the first
b in the buffer at or after fromIndex . |
long |
indexOf(ByteString bytes)
Returns the index of the first match for
bytes in the buffer. |
long |
indexOf(ByteString bytes,
long fromIndex)
Returns the index of the first match for
bytes in the buffer at or after fromIndex . |
long |
indexOfElement(ByteString targetBytes)
Returns the index of the first byte in
targetBytes in the buffer. |
long |
indexOfElement(ByteString targetBytes,
long fromIndex)
Returns the index of the first byte in
targetBytes in the buffer
at or after fromIndex . |
InputStream |
inputStream()
Returns an input stream that reads from this source.
|
int |
read(byte[] sink)
Removes up to
sink.length bytes from this and copies them into sink . |
int |
read(byte[] sink,
int offset,
int byteCount)
Removes up to
byteCount bytes from this and copies them into sink at
offset . |
long |
readAll(Sink sink)
Removes all bytes from this and appends them to
sink . |
byte |
readByte()
Removes a byte from this source and returns it.
|
byte[] |
readByteArray()
Removes all bytes from this and returns them as a byte array.
|
byte[] |
readByteArray(long byteCount)
Removes
byteCount bytes from this and returns them as a byte array. |
ByteString |
readByteString()
Removes all bytes bytes from this and returns them as a byte string.
|
ByteString |
readByteString(long byteCount)
Removes
byteCount bytes from this and returns them as a byte string. |
long |
readDecimalLong()
Reads a long from this source in signed decimal form (i.e., as a string in base 10 with
optional leading '-').
|
void |
readFully(Buffer sink,
long byteCount)
Removes exactly
byteCount bytes from this and appends them to
sink . |
void |
readFully(byte[] sink)
Removes exactly
sink.length bytes from this and copies them into sink . |
long |
readHexadecimalUnsignedLong()
Reads a long form this source in hexadecimal form (i.e., as a string in base 16).
|
int |
readInt()
Removes four bytes from this source and returns a big-endian int.
|
int |
readIntLe()
Removes four bytes from this source and returns a little-endian int.
|
long |
readLong()
Removes eight bytes from this source and returns a big-endian long.
|
long |
readLongLe()
Removes eight bytes from this source and returns a little-endian long.
|
short |
readShort()
Removes two bytes from this source and returns a big-endian short.
|
short |
readShortLe()
Removes two bytes from this source and returns a little-endian short.
|
String |
readString(Charset charset)
Removes all bytes from this, decodes them as
charset , and returns
the string. |
String |
readString(long byteCount,
Charset charset)
Removes
byteCount bytes from this, decodes them as charset ,
and returns the string. |
String |
readUtf8()
Removes all bytes from this, decodes them as UTF-8, and returns the string.
|
String |
readUtf8(long byteCount)
Removes
byteCount bytes from this, decodes them as UTF-8, and
returns the string. |
int |
readUtf8CodePoint()
Removes and returns a single UTF-8 code point, reading between 1 and 4 bytes as necessary.
|
String |
readUtf8Line()
Removes and returns characters up to but not including the next line break.
|
String |
readUtf8LineStrict()
Removes and returns characters up to but not including the next line break.
|
boolean |
request(long byteCount)
Returns true when the buffer contains at least
byteCount bytes,
expanding it as necessary. |
void |
require(long byteCount)
Returns when the buffer contains at least
byteCount bytes. |
void |
skip(long byteCount)
Reads and discards
byteCount bytes from this source. |
Buffer buffer()
boolean exhausted() throws IOException
IOException
void require(long byteCount) throws IOException
byteCount
bytes. Throws
an EOFException
if the source is exhausted before the
required bytes can be read.IOException
boolean request(long byteCount) throws IOException
byteCount
bytes,
expanding it as necessary. Returns false if the source is exhausted before
the requested bytes can be read.IOException
byte readByte() throws IOException
IOException
short readShort() throws IOException
IOException
short readShortLe() throws IOException
IOException
int readInt() throws IOException
IOException
int readIntLe() throws IOException
IOException
long readLong() throws IOException
IOException
long readLongLe() throws IOException
IOException
long readDecimalLong() throws IOException
NumberFormatException
- if the found digits do not fit into a long
or a decimal
number was not present.IOException
long readHexadecimalUnsignedLong() throws IOException
NumberFormatException
- if the found hexadecimal does not fit into a long
or
hexadecimal was not found.IOException
void skip(long byteCount) throws IOException
byteCount
bytes from this source. Throws an
EOFException
if the source is exhausted before the
requested bytes can be skipped.IOException
ByteString readByteString() throws IOException
IOException
ByteString readByteString(long byteCount) throws IOException
byteCount
bytes from this and returns them as a byte string.IOException
byte[] readByteArray() throws IOException
IOException
byte[] readByteArray(long byteCount) throws IOException
byteCount
bytes from this and returns them as a byte array.IOException
int read(byte[] sink) throws IOException
sink.length
bytes from this and copies them into sink
.
Returns the number of bytes read, or -1 if this source is exhausted.IOException
void readFully(byte[] sink) throws IOException
sink.length
bytes from this and copies them into sink
.
Throws an EOFException
if the requested number of bytes cannot be read.IOException
int read(byte[] sink, int offset, int byteCount) throws IOException
byteCount
bytes from this and copies them into sink
at
offset
. Returns the number of bytes read, or -1 if this source is exhausted.IOException
void readFully(Buffer sink, long byteCount) throws IOException
byteCount
bytes from this and appends them to
sink
. Throws an EOFException
if the requested
number of bytes cannot be read.IOException
long readAll(Sink sink) throws IOException
sink
. Returns the
total number of bytes written to sink
which will be 0 if this is
exhausted.IOException
String readUtf8() throws IOException
IOException
String readUtf8(long byteCount) throws IOException
byteCount
bytes from this, decodes them as UTF-8, and
returns the string.IOException
String readUtf8Line() throws IOException
"\n"
or "\r\n"
; these characters are
not included in the result.
On the end of the stream this method returns null, just
like BufferedReader
. If the source doesn't end with a line
break then an implicit line break is assumed. Null is returned once the
source is exhausted. Use this for human-generated data, where a trailing
line break is optional.
IOException
String readUtf8LineStrict() throws IOException
"\n"
or "\r\n"
; these characters are
not included in the result.
On the end of the stream this method throws. Every call
must consume either '\r\n' or '\n'. If these characters are absent in the
stream, an EOFException
is thrown. Use this for
machine-generated data where a missing line break implies truncated input.
IOException
int readUtf8CodePoint() throws IOException
If this source is exhausted before a complete code point can be read, this throws an EOFException
and consumes no input.
If this source doesn't start with a properly-encoded UTF-8 code point, this method will
remove 1 or more non-UTF-8 bytes and return the replacement character (U+FFFD
). This
covers encoding problems (the input is not properly-encoded UTF-8), characters out of range
(beyond the 0x10ffff limit of Unicode), code points for UTF-16 surrogates (U+d800..U+dfff) and
overlong encodings (such as 0xc080
for the NUL character in modified UTF-8).
IOException
String readString(Charset charset) throws IOException
charset
, and returns
the string.IOException
String readString(long byteCount, Charset charset) throws IOException
byteCount
bytes from this, decodes them as charset
,
and returns the string.IOException
long indexOf(byte b) throws IOException
b
in the buffer. 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.IOException
long indexOf(byte b, long fromIndex) throws IOException
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.IOException
long indexOf(ByteString bytes) throws IOException
bytes
in the buffer. 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.IOException
long indexOf(ByteString bytes, long fromIndex) throws IOException
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.IOException
long indexOfElement(ByteString targetBytes) throws IOException
targetBytes
in the buffer.
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.IOException
long indexOfElement(ByteString targetBytes, long fromIndex) throws IOException
targetBytes
in the buffer
at or after fromIndex
. 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.IOException
InputStream inputStream()
Copyright © 2017. All rights reserved.