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 |
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. |
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 . |
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. |
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
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
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 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 © 2015. All rights reserved.