public final class Buffer extends Object implements BufferSource, BufferSink, Cloneable, ByteChannel
| Modifier and Type | Class and Description |
|---|---|
static class |
Buffer.UnsafeCursor |
| Constructor and Description |
|---|
Buffer() |
| Modifier and Type | Method and Description |
|---|---|
Buffer |
buffer() |
void |
clear()
丢弃此缓冲区中的所有字节。在使用完缓冲区后调用此方法将把它的段返回到池中.
|
Buffer |
clone() |
void |
close()
关闭此源并释放此源持有的资源.
|
long |
completeSegmentByteCount() |
Buffer |
copyTo(Buffer out,
long offset,
long byteCount)
从这里复制
byteCount字节,从offset开始,复制到out. |
Buffer |
copyTo(OutputStream out)
将其内容复制到
out. |
Buffer |
copyTo(OutputStream out,
long offset,
long byteCount)
从这里复制
byteCount字节,从offset开始,复制到 out. |
BufferSink |
emit() |
Buffer |
emitCompleteSegments() |
boolean |
equals(Object o) |
boolean |
exhausted() |
void |
flush() |
Buffer |
getBuffer() |
byte |
getByte(long pos)
返回
pos处的字节. |
int |
hashCode() |
ByteString |
hmacSha1(ByteString key) |
ByteString |
hmacSha256(ByteString key) |
ByteString |
hmacSha512(ByteString key) |
long |
indexOf(byte b)
Equivalent to
indexOf(b, 0). |
long |
indexOf(byte b,
long fromIndex)
Returns the index of the first
b in the buffer at or after fromIndex. |
long |
indexOf(byte b,
long fromIndex,
long toIndex)
Returns the index of
b if it is found in the range of fromIndex inclusive
to toIndex exclusive. |
long |
indexOf(ByteString bytes)
Equivalent to
indexOf(bytes, 0). |
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) |
long |
indexOfElement(ByteString targetBytes,
long fromIndex) |
InputStream |
inputStream()
an input stream that reads from this source.
|
boolean |
isOpen() |
ByteString |
md5() |
OutputStream |
outputStream() |
BufferSource |
peek()
a new
BufferSource that can read data from this BufferSource
without consuming it. |
boolean |
rangeEquals(long offset,
ByteString bytes)
true if the bytes at
offset in this source equal bytes. |
boolean |
rangeEquals(long offset,
ByteString bytes,
int bytesOffset,
int byteCount)
if
byteCount bytes at offset in this source equal bytes
* at bytesOffset. |
long |
read(Buffer sink,
long byteCount)
从中删除至少1个字节,最多为
byteCount字节, 并将它们
附加到sink。返回读取的字节数,如果该源已耗尽,则返回-1 |
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. |
int |
read(ByteBuffer sink) |
long |
readAll(Sink sink)
Removes all bytes from this and appends them to
sink. |
Buffer.UnsafeCursor |
readAndWriteUnsafe() |
Buffer.UnsafeCursor |
readAndWriteUnsafe(Buffer.UnsafeCursor unsafeCursor) |
byte |
readByte() |
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 '-').
|
Buffer |
readFrom(InputStream in)
将
in中的字节读入并转为bytes |
Buffer |
readFrom(InputStream in,
long byteCount)
Read
byteCount bytes from in to this. |
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() |
int |
readIntLe() |
long |
readLong() |
long |
readLongLe()
Removes eight bytes from this source and returns a little-endian long.
|
short |
readShort() |
short |
readShortLe()
Removes two bytes from this source and returns a little-endian short.
|
String |
readString(Charset charset) |
String |
readString(long byteCount,
Charset charset)
Removes
byteCount bytes from this, decodes them as charset, |
Buffer.UnsafeCursor |
readUnsafe() |
Buffer.UnsafeCursor |
readUnsafe(Buffer.UnsafeCursor unsafeCursor) |
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() |
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.
|
String |
readUtf8LineStrict(long limit)
Like
BufferSource.readUtf8LineStrict(), except this allows the caller to specify the longest
allowed match. |
boolean |
request(long byteCount) |
void |
require(long byteCount)
when the buffer contains at least
byteCount bytes. |
int |
select(BufferOption options)
Finds the first string in
options that is a prefix of this buffer, consumes it from
this buffer, and returns its index. |
ByteString |
sha1() |
ByteString |
sha256() |
ByteString |
sha512() |
long |
size() |
void |
skip(long byteCount)
从这个缓冲区的头部丢弃
byteCount字节. |
ByteString |
snapshot() |
ByteString |
snapshot(int byteCount) |
Timeout |
timeout()
返回此源的超时时间.
|
String |
toString() |
Segment |
writableSegment(int minimumCapacity) |
void |
write(Buffer source,
long byteCount) |
Buffer |
write(byte[] source) |
Buffer |
write(byte[] source,
int offset,
int byteCount) |
int |
write(ByteBuffer source) |
Buffer |
write(ByteString byteString) |
BufferSink |
write(Source source,
long byteCount) |
long |
writeAll(Source source) |
Buffer |
writeByte(int b) |
Buffer |
writeDecimalLong(long v) |
Buffer |
writeHexadecimalUnsignedLong(long v) |
Buffer |
writeInt(int i) |
Buffer |
writeIntLe(int i) |
Buffer |
writeLong(long v) |
Buffer |
writeLongLe(long v) |
Buffer |
writeShort(int s) |
Buffer |
writeShortLe(int s) |
Buffer |
writeString(String string,
Charset charset) |
Buffer |
writeString(String string,
int beginIndex,
int endIndex,
Charset charset) |
Buffer |
writeTo(OutputStream out)
将其内容写入
out. |
Buffer |
writeTo(OutputStream out,
long byteCount)
将
byteCount字节写入out. |
Buffer |
writeUtf8(String string) |
Buffer |
writeUtf8(String string,
int beginIndex,
int endIndex) |
Buffer |
writeUtf8CodePoint(int codePoint) |
public Segment head
public long size
public final long size()
public Buffer buffer()
buffer in interface BufferSinkbuffer in interface BufferSourcepublic Buffer getBuffer()
getBuffer in interface BufferSourcepublic OutputStream outputStream()
outputStream in interface BufferSinkpublic Buffer emitCompleteSegments()
emitCompleteSegments in interface BufferSinkpublic BufferSink emit()
emit in interface BufferSinkpublic boolean exhausted()
exhausted in interface BufferSourcepublic void require(long byteCount)
throws EOFException
BufferSourcebyteCount bytes.require in interface BufferSourcebyteCount - longEOFExceptionpublic boolean request(long byteCount)
request in interface BufferSourcebyteCount - longbyteCount bytes, expanding it as
necessary. Returns false if the source is exhausted before the requested bytes can be read.public BufferSource peek()
BufferSourceBufferSource that can read data from this BufferSource
without consuming it. The returned source becomes invalid once this source is next read or
closed.
For example, we can use peek() to lookahead and read the same data multiple times.
Buffer buffer = new Buffer();
buffer.writeUtf8("abcdefghi");
buffer.readUtf8(3) // returns "abc", buffer contains "defghi"
BufferSource peek = buffer.peek();
peek.readUtf8(3); // returns "def", buffer contains "defghi"
peek.readUtf8(3); // returns "ghi", buffer contains "defghi"
buffer.readUtf8(3); // returns "def", buffer contains "ghi"
peek in interface BufferSourcepublic InputStream inputStream()
BufferSourceinputStream in interface BufferSourcepublic final Buffer copyTo(OutputStream out) throws IOException
out.out - 输出流IOException - 抛出异常public final Buffer copyTo(OutputStream out, long offset, long byteCount) throws IOException
byteCount字节,从offset开始,复制到 out.out - 输出流offset - 偏移量byteCount - 偏移量IOException - 抛出异常public final Buffer copyTo(Buffer out, long offset, long byteCount)
byteCount字节,从offset开始,复制到out.out - 输出流offset - 偏移量byteCount - 偏移量public final Buffer writeTo(OutputStream out) throws IOException
out.out - 输出流IOException - 抛出异常public final Buffer writeTo(OutputStream out, long byteCount) throws IOException
byteCount字节写入out.out - 输出流byteCount - 偏移量IOException - 抛出异常public final Buffer readFrom(InputStream in) throws IOException
in中的字节读入并转为bytesin - 输入流IOException - 抛出异常public final Buffer readFrom(InputStream in, long byteCount) throws IOException
byteCount bytes from in to this.in - 输入流byteCount - 偏移量IOException - 抛出异常public final long completeSegmentByteCount()
public byte readByte()
readByte in interface BufferSourcepublic final byte getByte(long pos)
pos处的字节.pos - longpublic short readShort()
readShort in interface BufferSource
Buffer buffer = new Buffer()
.writeByte(0x7f)
.writeByte(0xff)
.writeByte(0x00)
.writeByte(0x0f);
assertEquals(4, buffer.size());
assertEquals(32767, buffer.readShort());
assertEquals(2, buffer.size());
assertEquals(15, buffer.readShort());
assertEquals(0, buffer.size());
public int readInt()
readInt in interface BufferSourcepublic long readLong()
readLong in interface BufferSourcepublic short readShortLe()
BufferSource
Buffer buffer = new Buffer()
.writeByte(0xff)
.writeByte(0x7f)
.writeByte(0x0f)
.writeByte(0x00);
assertEquals(4, buffer.size());
assertEquals(32767, buffer.readShortLe());
assertEquals(2, buffer.size());
assertEquals(15, buffer.readShortLe());
assertEquals(0, buffer.size());
readShortLe in interface BufferSourcepublic int readIntLe()
readIntLe in interface BufferSourcepublic long readLongLe()
BufferSource
Buffer buffer = new Buffer()
.writeByte(0xff)
.writeByte(0xff)
.writeByte(0xff)
.writeByte(0xff)
.writeByte(0xff)
.writeByte(0xff)
.writeByte(0xff)
.writeByte(0x7f)
.writeByte(0x0f)
.writeByte(0x00)
.writeByte(0x00)
.writeByte(0x00)
.writeByte(0x00)
.writeByte(0x00)
.writeByte(0x00)
.writeByte(0x00);
assertEquals(16, buffer.size());
assertEquals(9223372036854775807L, buffer.readLongLe());
assertEquals(8, buffer.size());
assertEquals(15, buffer.readLongLe());
assertEquals(0, buffer.size());
readLongLe in interface BufferSourcepublic long readDecimalLong()
BufferSource
Buffer buffer = new Buffer()
.writeUtf8("8675309 -123 00001");
assertEquals(8675309L, buffer.readDecimalLong());
assertEquals(' ', buffer.readByte());
assertEquals(-123L, buffer.readDecimalLong());
assertEquals(' ', buffer.readByte());
assertEquals(1L, buffer.readDecimalLong());
readDecimalLong in interface BufferSourcepublic long readHexadecimalUnsignedLong()
BufferSource
Buffer buffer = new Buffer()
.writeUtf8("ffff CAFEBABE 10");
assertEquals(65535L, buffer.readHexadecimalUnsignedLong());
assertEquals(' ', buffer.readByte());
assertEquals(0xcafebabeL, buffer.readHexadecimalUnsignedLong());
assertEquals(' ', buffer.readByte());
assertEquals(0x10L, buffer.readHexadecimalUnsignedLong());
readHexadecimalUnsignedLong in interface BufferSourcepublic ByteString readByteString()
BufferSourcereadByteString in interface BufferSourcepublic ByteString readByteString(long byteCount) throws EOFException
BufferSourcebyteCount bytes from this and returns them as a byte string.readByteString in interface BufferSourcebyteCount - longEOFExceptionpublic int select(BufferOption options)
BufferSourceoptions that is a prefix of this buffer, consumes it from
this buffer, and returns its index. If no byte string in options is a prefix of this
buffer this returns -1 and no bytes are consumed.
This can be used as an alternative to BufferSource.readByteString() or even BufferSource.readUtf8() if
the set of expected values is known in advance.
Options FIELDS = Options.of(
ByteString.encodeUtf8("depth="),
ByteString.encodeUtf8("height="),
ByteString.encodeUtf8("width="));
Buffer buffer = new Buffer()
.writeUtf8("width=640\n")
.writeUtf8("height=480\n");
assertEquals(2, buffer.select(FIELDS));
assertEquals(640, buffer.readDecimalLong());
assertEquals('\n', buffer.readByte());
assertEquals(1, buffer.select(FIELDS));
assertEquals(480, buffer.readDecimalLong());
assertEquals('\n', buffer.readByte());
select in interface BufferSourceoptions - Optionspublic void readFully(Buffer sink, long byteCount) throws EOFException
BufferSourcebyteCount bytes from this and appends them to sink. Throws an
IOException if the requested number of bytes cannot be read.readFully in interface BufferSourcesink - BufferbyteCount - longEOFExceptionpublic long readAll(Sink sink) throws IOException
BufferSourcesink. Returns the total number of bytes
written to sink which will be 0 if this is exhausted.readAll in interface BufferSourcesink - SinkIOException - IOException IOException.public String readUtf8()
BufferSource
Buffer buffer = new Buffer()
.writeUtf8("Uh uh uh!")
.writeByte(' ')
.writeUtf8("You didn't say the magic word!");
assertEquals("Uh uh uh! You didn't say the magic word!", buffer.readUtf8());
assertEquals(0, buffer.size());
assertEquals("", buffer.readUtf8());
assertEquals(0, buffer.size());
readUtf8 in interface BufferSourcepublic String readUtf8(long byteCount) throws EOFException
BufferSourcebyteCount bytes from this, decodes them as UTF-8, and returns the string.
Buffer buffer = new Buffer()
.writeUtf8("Uh uh uh!")
.writeByte(' ')
.writeUtf8("You didn't say the magic word!");
assertEquals(40, buffer.size());
assertEquals("Uh uh uh! You ", buffer.readUtf8(14));
assertEquals(26, buffer.size());
assertEquals("didn't say the", buffer.readUtf8(14));
assertEquals(12, buffer.size());
assertEquals(" magic word!", buffer.readUtf8(12));
assertEquals(0, buffer.size());
readUtf8 in interface BufferSourcebyteCount - longEOFExceptionpublic String readString(Charset charset)
readString in interface BufferSourcecharset - Charset Removes all bytes from this, decodes them as charset,public String readString(long byteCount, Charset charset) throws EOFException
BufferSourcebyteCount bytes from this, decodes them as charset,readString in interface BufferSourcebyteCount - byteCountcharset - CharsetEOFExceptionpublic String readUtf8Line() throws EOFException
BufferSource"\n" or "\r\n"; these characters are not included in the result.
Buffer buffer = new Buffer()
.writeUtf8("I'm a hacker!\n")
.writeUtf8("That's what I said: you're a nerd.\n")
.writeUtf8("I prefer to be called a hacker!\n");
assertEquals(81, buffer.size());
assertEquals("I'm a hacker!", buffer.readUtf8Line());
assertEquals(67, buffer.size());
assertEquals("That's what I said: you're a nerd.", buffer.readUtf8Line());
assertEquals(32, buffer.size());
assertEquals("I prefer to be called a hacker!", buffer.readUtf8Line());
assertEquals(0, buffer.size());
assertEquals(null, buffer.readUtf8Line());
assertEquals(0, buffer.size());
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.
readUtf8Line in interface BufferSourceEOFExceptionpublic String readUtf8LineStrict() throws EOFException
BufferSource"\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 IOException
is thrown. Use this for machine-generated data where a missing line break implies truncated
input.
readUtf8LineStrict in interface BufferSourceEOFExceptionpublic String readUtf8LineStrict(long limit) throws EOFException
BufferSourceBufferSource.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".
The returned string will have at most limit UTF-8 bytes, and the maximum number
of bytes scanned is limit + 2. If limit == 0 this will always throw
an IOException because no bytes will be scanned.
This method is safe. No bytes are discarded if the match fails, and the caller is free to try another match:
Buffer buffer = new Buffer();
buffer.writeUtf8("12345\r\n");
// This will throw! There must be \r\n or \n at the limit or before it.
buffer.readUtf8LineStrict(4);
// No bytes have been consumed so the caller can retry.
assertEquals("12345", buffer.readUtf8LineStrict(5));
readUtf8LineStrict in interface BufferSourcelimit - longEOFExceptionpublic int readUtf8CodePoint()
throws EOFException
readUtf8CodePoint in interface BufferSourceIf this source is exhausted before a complete code point can be read, this throws an IOException 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).
EOFExceptionpublic byte[] readByteArray()
BufferSourcereadByteArray in interface BufferSourcepublic byte[] readByteArray(long byteCount)
throws EOFException
BufferSourcebyteCount bytes from this and returns them as a byte array.readByteArray in interface BufferSourcebyteCount - longEOFExceptionpublic int read(byte[] sink)
BufferSourcesink.length bytes from this and copies them into sink. Returns
the number of bytes read, or -1 if this source is exhausted.read in interface BufferSourcesink - byte[]public void readFully(byte[] sink)
throws EOFException
BufferSourcesink.length bytes from this and copies them into sink. Throws
an IOException if the requested number of bytes cannot be read.readFully in interface BufferSourcesink - byte[]EOFExceptionpublic int read(byte[] sink,
int offset,
int byteCount)
BufferSourcebyteCount bytes from this and copies them into sink at offset. Returns the number of bytes read, or -1 if this source is exhausted.read in interface BufferSourcesink - byte[]offset - intbyteCount - intpublic int read(ByteBuffer sink) throws IOException
read in interface ReadableByteChannelIOExceptionpublic final void clear()
public void skip(long byteCount)
throws EOFException
byteCount字节.skip in interface BufferSourcebyteCount - longEOFExceptionpublic Buffer write(ByteString byteString)
write in interface BufferSinkpublic Buffer writeUtf8(String string)
writeUtf8 in interface BufferSinkpublic Buffer writeUtf8(String string, int beginIndex, int endIndex)
writeUtf8 in interface BufferSinkpublic Buffer writeUtf8CodePoint(int codePoint)
writeUtf8CodePoint in interface BufferSinkpublic Buffer writeString(String string, Charset charset)
writeString in interface BufferSinkpublic Buffer writeString(String string, int beginIndex, int endIndex, Charset charset)
writeString in interface BufferSinkpublic Buffer write(byte[] source)
write in interface BufferSinkpublic Buffer write(byte[] source, int offset, int byteCount)
write in interface BufferSinkpublic int write(ByteBuffer source) throws IOException
write in interface WritableByteChannelIOExceptionpublic long writeAll(Source source) throws IOException
writeAll in interface BufferSinkIOExceptionpublic BufferSink write(Source source, long byteCount) throws IOException
write in interface BufferSinkIOExceptionpublic Buffer writeByte(int b)
writeByte in interface BufferSinkpublic Buffer writeShort(int s)
writeShort in interface BufferSinkpublic Buffer writeShortLe(int s)
writeShortLe in interface BufferSinkpublic Buffer writeInt(int i)
writeInt in interface BufferSinkpublic Buffer writeIntLe(int i)
writeIntLe in interface BufferSinkpublic Buffer writeLong(long v)
writeLong in interface BufferSinkpublic Buffer writeLongLe(long v)
writeLongLe in interface BufferSinkpublic Buffer writeDecimalLong(long v)
writeDecimalLong in interface BufferSinkpublic Buffer writeHexadecimalUnsignedLong(long v)
writeHexadecimalUnsignedLong in interface BufferSinkpublic Segment writableSegment(int minimumCapacity)
minimumCapacity - intminimumCapacity
bytes to, creating it if necessary.public long read(Buffer sink, long byteCount)
SourcebyteCount字节, 并将它们
附加到sink。返回读取的字节数,如果该源已耗尽,则返回-1public long indexOf(byte b)
BufferSourceindexOf(b, 0).indexOf in interface BufferSourceb - bytepublic long indexOf(byte b,
long fromIndex)
BufferSourceb 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.
Buffer buffer = new Buffer();
buffer.writeUtf8("Don't move! He can't see us if we don't move.");
byte m = 'm';
assertEquals(6, buffer.indexOf(m));
assertEquals(40, buffer.indexOf(m, 12));
indexOf in interface BufferSourceb - bytefromIndex - longpublic long indexOf(byte b,
long fromIndex,
long toIndex)
BufferSourceb 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.
The scan terminates at either toIndex or the end of the buffer, whichever comes
first. The maximum number of bytes scanned is toIndex-fromIndex.
indexOf in interface BufferSourceb - bytefromIndex - longtoIndex - longpublic long indexOf(ByteString bytes) throws IOException
BufferSourceindexOf(bytes, 0).indexOf in interface BufferSourcebytes - ByteStringIOException - IOException IOException.public long indexOf(ByteString bytes, long fromIndex) throws IOException
BufferSourcebytes 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.
ByteString MOVE = ByteString.encodeUtf8("move");
Buffer buffer = new Buffer();
buffer.writeUtf8("Don't move! He can't see us if we don't move.");
assertEquals(6, buffer.indexOf(MOVE));
assertEquals(40, buffer.indexOf(MOVE, 12));
indexOf in interface BufferSourcebytes - ByteStringfromIndex - longIOException - IOException IOException.public long indexOfElement(ByteString targetBytes)
indexOfElement in interface BufferSourcetargetBytes - ByteString
Equivalent to indexOfElement(targetBytes, 0).public long indexOfElement(ByteString targetBytes, long fromIndex)
indexOfElement in interface BufferSourcetargetBytes - ByteStringfromIndex - longpublic boolean rangeEquals(long offset,
ByteString bytes)
BufferSourceoffset 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.
ByteString simonSays = ByteString.encodeUtf8("Simon says:");
Buffer standOnOneLeg = new Buffer().writeUtf8("Simon says: Stand on first leg.");
assertTrue(standOnOneLeg.rangeEquals(0, simonSays));
Buffer payMeMoney = new Buffer().writeUtf8("Pay me $1,000,000.");
assertFalse(payMeMoney.rangeEquals(0, simonSays));
rangeEquals in interface BufferSourceoffset - longbytes - ByteStringpublic boolean rangeEquals(long offset,
ByteString bytes,
int bytesOffset,
int byteCount)
BufferSourcebyteCount 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.rangeEquals in interface BufferSourceoffset - longbytes - ByteStringbytesOffset - intbyteCount - intpublic void flush()
public void close()
Sourcepublic final ByteString md5()
public final ByteString sha1()
public final ByteString sha256()
public final ByteString sha512()
public final ByteString hmacSha1(ByteString key)
key - ByteStringpublic final ByteString hmacSha256(ByteString key)
key - ByteStringpublic final ByteString hmacSha512(ByteString key)
key - ByteStringpublic final ByteString snapshot()
public final ByteString snapshot(int byteCount)
public final Buffer.UnsafeCursor readUnsafe()
public final Buffer.UnsafeCursor readUnsafe(Buffer.UnsafeCursor unsafeCursor)
public final Buffer.UnsafeCursor readAndWriteUnsafe()
public final Buffer.UnsafeCursor readAndWriteUnsafe(Buffer.UnsafeCursor unsafeCursor)
Copyright © 2019. All rights reserved.