Class Buffer
- java.lang.Object
-
- okio.Buffer
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable,Cloneable,BufferedSink,BufferedSource,Sink,Source
public final class Buffer extends Object implements BufferedSource, BufferedSink, Cloneable
A collection of bytes in memory.Moving data from one buffer to another is fast. Instead of copying bytes from one place in memory to another, this class just changes ownership of the underlying byte arrays.
This buffer grows with your data. Just like ArrayList, each buffer starts small. It consumes only the memory it needs to.
This buffer pools its byte arrays. When you allocate a byte array in Java, the runtime must zero-fill the requested array before returning it to you. Even if you're going to write over that space anyway. This class avoids zero-fill and GC churn by pooling byte arrays.
-
-
Constructor Summary
Constructors Constructor Description Buffer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Bufferbuffer()Returns this source's internal buffer.voidclear()Discards all bytes in this buffer.Bufferclone()Returns a deep copy of this buffer.voidclose()Closes this source and releases the resources held by this source.longcompleteSegmentByteCount()Returns the number of bytes in segments that are not writable.BuffercopyTo(OutputStream out)Copy the contents of this toout.BuffercopyTo(OutputStream out, long offset, long byteCount)CopybyteCountbytes from this, starting atoffset, toout.BuffercopyTo(Buffer out, long offset, long byteCount)CopybyteCountbytes from this, starting atoffset, toout.BufferedSinkemit()Writes all buffered data to the underlying sink, if one exists.BufferemitCompleteSegments()Writes complete segments to the underlying sink, if one exists.booleanequals(Object o)Compares this instance with the specified object and indicates if they are equal.booleanexhausted()Returns true if there are no more bytes in this source.voidflush()Pushes all buffered bytes to their final destination.bytegetByte(long pos)Returns the byte atpos.inthashCode()Returns an integer hash code for this object.longindexOf(byte b)Returns the index of the firstbin the buffer.longindexOf(byte b, long fromIndex)Returns the index ofbin this at or beyondfromIndex, or -1 if this buffer does not containbin that range.longindexOf(ByteString bytes)Returns the index of the first match forbytesin the buffer.longindexOf(ByteString bytes, long fromIndex)Returns the index of the first match forbytesin the buffer at or afterfromIndex.longindexOfElement(ByteString targetBytes)Returns the index of the first byte intargetBytesin the buffer.longindexOfElement(ByteString targetBytes, long fromIndex)Returns the index of the first byte intargetBytesin the buffer at or afterfromIndex.InputStreaminputStream()Returns an input stream that reads from this source.OutputStreamoutputStream()Returns an output stream that writes to this sink.intread(byte[] sink)Removes up tosink.lengthbytes from this and copies them intosink.intread(byte[] sink, int offset, int byteCount)Removes up tobyteCountbytes from this and copies them intosinkatoffset.longread(Buffer sink, long byteCount)Removes at least 1, and up tobyteCountbytes from this and appends them tosink.longreadAll(Sink sink)Removes all bytes from this and appends them tosink.bytereadByte()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)RemovesbyteCountbytes from this and returns them as a byte array.ByteStringreadByteString()Removes all bytes bytes from this and returns them as a byte string.ByteStringreadByteString(long byteCount)RemovesbyteCountbytes from this and returns them as a byte string.longreadDecimalLong()Reads a long from this source in signed decimal form (i.e., as a string in base 10 with optional leading '-').BufferreadFrom(InputStream in)Read and exhaust bytes frominto this.BufferreadFrom(InputStream in, long byteCount)ReadbyteCountbytes frominto this.voidreadFully(byte[] sink)Removes exactlysink.lengthbytes from this and copies them intosink.voidreadFully(Buffer sink, long byteCount)Removes exactlybyteCountbytes from this and appends them tosink.longreadHexadecimalUnsignedLong()Reads a long form this source in hexadecimal form (i.e., as a string in base 16).intreadInt()Removes four bytes from this source and returns a big-endian int.intreadIntLe()Removes four bytes from this source and returns a little-endian int.longreadLong()Removes eight bytes from this source and returns a big-endian long.longreadLongLe()Removes eight bytes from this source and returns a little-endian long.shortreadShort()Removes two bytes from this source and returns a big-endian short.shortreadShortLe()Removes two bytes from this source and returns a little-endian short.StringreadString(long byteCount, Charset charset)RemovesbyteCountbytes from this, decodes them ascharset, and returns the string.StringreadString(Charset charset)Removes all bytes from this, decodes them ascharset, and returns the string.StringreadUtf8()Removes all bytes from this, decodes them as UTF-8, and returns the string.StringreadUtf8(long byteCount)RemovesbyteCountbytes from this, decodes them as UTF-8, and returns the string.intreadUtf8CodePoint()Removes and returns a single UTF-8 code point, reading between 1 and 4 bytes as necessary.StringreadUtf8Line()Removes and returns characters up to but not including the next line break.StringreadUtf8LineStrict()Removes and returns characters up to but not including the next line break.booleanrequest(long byteCount)Returns true when the buffer contains at leastbyteCountbytes, expanding it as necessary.voidrequire(long byteCount)Returns when the buffer contains at leastbyteCountbytes.longsize()Returns the number of bytes currently in this buffer.voidskip(long byteCount)DiscardsbyteCountbytes from the head of this buffer.ByteStringsnapshot()Returns an immutable copy of this buffer as a byte string.ByteStringsnapshot(int byteCount)Returns an immutable copy of the firstbyteCountbytes of this buffer as a byte string.Timeouttimeout()Returns the timeout for this source.StringtoString()Returns a string containing a concise, human-readable description of this object.Bufferwrite(byte[] source)LikeOutputStream.write(byte[]), this writes a complete byte array to this sink.Bufferwrite(byte[] source, int offset, int byteCount)LikeOutputStream.write(byte[], int, int), this writesbyteCountbytes ofsource, starting atoffset.voidwrite(Buffer source, long byteCount)RemovesbyteCountbytes fromsourceand appends them to this.Bufferwrite(ByteString byteString)BufferedSinkwrite(Source source, long byteCount)RemovesbyteCountbytes fromsourceand appends them to this sink.longwriteAll(Source source)Removes all bytes fromsourceand appends them to this sink.BufferwriteByte(int b)Writes a byte to this sink.BufferwriteDecimalLong(long v)Writes a long to this sink in signed decimal form (i.e., as a string in base 10).BufferwriteHexadecimalUnsignedLong(long v)Writes a long to this sink in hexadecimal form (i.e., as a string in base 16).BufferwriteInt(int i)Writes a big-endian int to this sink using four bytes.BufferwriteIntLe(int i)Writes a little-endian int to this sink using four bytes.BufferwriteLong(long v)Writes a big-endian long to this sink using eight bytes.BufferwriteLongLe(long v)Writes a little-endian long to this sink using eight bytes.BufferwriteShort(int s)Writes a big-endian short to this sink using two bytes.BufferwriteShortLe(int s)Writes a little-endian short to this sink using two bytes.BufferwriteString(String string, int beginIndex, int endIndex, Charset charset)Encodes the characters atbeginIndexup toendIndexfromstringincharsetand writes it to this sink.BufferwriteString(String string, Charset charset)Encodesstringincharsetand writes it to this sink.BufferwriteTo(OutputStream out)Write the contents of this toout.BufferwriteTo(OutputStream out, long byteCount)WritebyteCountbytes from this toout.BufferwriteUtf8(String string)Encodesstringin UTF-8 and writes it to this sink.BufferwriteUtf8(String string, int beginIndex, int endIndex)Encodes the characters atbeginIndexup toendIndexfromstringin UTF-8 and writes it to this sink.BufferwriteUtf8CodePoint(int codePoint)EncodescodePointin UTF-8 and writes it to this sink.
-
-
-
Method Detail
-
size
public long size()
Returns the number of bytes currently in this buffer.
-
buffer
public Buffer buffer()
Description copied from interface:BufferedSourceReturns this source's internal buffer.- Specified by:
bufferin interfaceBufferedSink- Specified by:
bufferin interfaceBufferedSource
-
outputStream
public OutputStream outputStream()
Description copied from interface:BufferedSinkReturns an output stream that writes to this sink.- Specified by:
outputStreamin interfaceBufferedSink
-
emitCompleteSegments
public Buffer emitCompleteSegments()
Description copied from interface:BufferedSinkWrites complete segments to the underlying sink, if one exists. LikeSink.flush(), but weaker. Use this to limit the memory held in the buffer to a single segment.- Specified by:
emitCompleteSegmentsin interfaceBufferedSink
-
emit
public BufferedSink emit()
Description copied from interface:BufferedSinkWrites all buffered data to the underlying sink, if one exists. LikeSink.flush(), but weaker. Call this before this buffered sink goes out of scope so that its data can reach its destination.- Specified by:
emitin interfaceBufferedSink
-
exhausted
public boolean exhausted()
Description copied from interface:BufferedSourceReturns true if there are no more bytes in this source. This will block until there are bytes to read or the source is definitely exhausted.- Specified by:
exhaustedin interfaceBufferedSource
-
require
public void require(long byteCount) throws EOFExceptionDescription copied from interface:BufferedSourceReturns when the buffer contains at leastbyteCountbytes. Throws anEOFExceptionif the source is exhausted before the required bytes can be read.- Specified by:
requirein interfaceBufferedSource- Throws:
EOFException
-
request
public boolean request(long byteCount)
Description copied from interface:BufferedSourceReturns true when the buffer contains at leastbyteCountbytes, expanding it as necessary. Returns false if the source is exhausted before the requested bytes can be read.- Specified by:
requestin interfaceBufferedSource
-
inputStream
public InputStream inputStream()
Description copied from interface:BufferedSourceReturns an input stream that reads from this source.- Specified by:
inputStreamin interfaceBufferedSource
-
copyTo
public Buffer copyTo(OutputStream out) throws IOException
Copy the contents of this toout.- Throws:
IOException
-
copyTo
public Buffer copyTo(OutputStream out, long offset, long byteCount) throws IOException
CopybyteCountbytes from this, starting atoffset, toout.- Throws:
IOException
-
copyTo
public Buffer copyTo(Buffer out, long offset, long byteCount)
CopybyteCountbytes from this, starting atoffset, toout.
-
writeTo
public Buffer writeTo(OutputStream out) throws IOException
Write the contents of this toout.- Throws:
IOException
-
writeTo
public Buffer writeTo(OutputStream out, long byteCount) throws IOException
WritebyteCountbytes from this toout.- Throws:
IOException
-
readFrom
public Buffer readFrom(InputStream in) throws IOException
Read and exhaust bytes frominto this.- Throws:
IOException
-
readFrom
public Buffer readFrom(InputStream in, long byteCount) throws IOException
ReadbyteCountbytes frominto this.- Throws:
IOException
-
completeSegmentByteCount
public long completeSegmentByteCount()
Returns the number of bytes in segments that are not writable. This is the number of bytes that can be flushed immediately to an underlying sink without harming throughput.
-
readByte
public byte readByte()
Description copied from interface:BufferedSourceRemoves a byte from this source and returns it.- Specified by:
readBytein interfaceBufferedSource
-
getByte
public byte getByte(long pos)
Returns the byte atpos.
-
readShort
public short readShort()
Description copied from interface:BufferedSourceRemoves two bytes from this source and returns a big-endian short.- Specified by:
readShortin interfaceBufferedSource
-
readInt
public int readInt()
Description copied from interface:BufferedSourceRemoves four bytes from this source and returns a big-endian int.- Specified by:
readIntin interfaceBufferedSource
-
readLong
public long readLong()
Description copied from interface:BufferedSourceRemoves eight bytes from this source and returns a big-endian long.- Specified by:
readLongin interfaceBufferedSource
-
readShortLe
public short readShortLe()
Description copied from interface:BufferedSourceRemoves two bytes from this source and returns a little-endian short.- Specified by:
readShortLein interfaceBufferedSource
-
readIntLe
public int readIntLe()
Description copied from interface:BufferedSourceRemoves four bytes from this source and returns a little-endian int.- Specified by:
readIntLein interfaceBufferedSource
-
readLongLe
public long readLongLe()
Description copied from interface:BufferedSourceRemoves eight bytes from this source and returns a little-endian long.- Specified by:
readLongLein interfaceBufferedSource
-
readDecimalLong
public long readDecimalLong()
Description copied from interface:BufferedSourceReads 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.- Specified by:
readDecimalLongin interfaceBufferedSource
-
readHexadecimalUnsignedLong
public long readHexadecimalUnsignedLong()
Description copied from interface:BufferedSourceReads 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.- Specified by:
readHexadecimalUnsignedLongin interfaceBufferedSource
-
readByteString
public ByteString readByteString()
Description copied from interface:BufferedSourceRemoves all bytes bytes from this and returns them as a byte string.- Specified by:
readByteStringin interfaceBufferedSource
-
readByteString
public ByteString readByteString(long byteCount) throws EOFException
Description copied from interface:BufferedSourceRemovesbyteCountbytes from this and returns them as a byte string.- Specified by:
readByteStringin interfaceBufferedSource- Throws:
EOFException
-
readFully
public void readFully(Buffer sink, long byteCount) throws EOFException
Description copied from interface:BufferedSourceRemoves exactlybyteCountbytes from this and appends them tosink. Throws anEOFExceptionif the requested number of bytes cannot be read.- Specified by:
readFullyin interfaceBufferedSource- Throws:
EOFException
-
readAll
public long readAll(Sink sink) throws IOException
Description copied from interface:BufferedSourceRemoves all bytes from this and appends them tosink. Returns the total number of bytes written tosinkwhich will be 0 if this is exhausted.- Specified by:
readAllin interfaceBufferedSource- Throws:
IOException
-
readUtf8
public String readUtf8()
Description copied from interface:BufferedSourceRemoves all bytes from this, decodes them as UTF-8, and returns the string.- Specified by:
readUtf8in interfaceBufferedSource
-
readUtf8
public String readUtf8(long byteCount) throws EOFException
Description copied from interface:BufferedSourceRemovesbyteCountbytes from this, decodes them as UTF-8, and returns the string.- Specified by:
readUtf8in interfaceBufferedSource- Throws:
EOFException
-
readString
public String readString(Charset charset)
Description copied from interface:BufferedSourceRemoves all bytes from this, decodes them ascharset, and returns the string.- Specified by:
readStringin interfaceBufferedSource
-
readString
public String readString(long byteCount, Charset charset) throws EOFException
Description copied from interface:BufferedSourceRemovesbyteCountbytes from this, decodes them ascharset, and returns the string.- Specified by:
readStringin interfaceBufferedSource- Throws:
EOFException
-
readUtf8Line
public String readUtf8Line() throws EOFException
Description copied from interface:BufferedSourceRemoves 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.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.- Specified by:
readUtf8Linein interfaceBufferedSource- Throws:
EOFException
-
readUtf8LineStrict
public String readUtf8LineStrict() throws EOFException
Description copied from interface:BufferedSourceRemoves 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.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
EOFExceptionis thrown. Use this for machine-generated data where a missing line break implies truncated input.- Specified by:
readUtf8LineStrictin interfaceBufferedSource- Throws:
EOFException
-
readUtf8CodePoint
public int readUtf8CodePoint() throws EOFExceptionDescription copied from interface:BufferedSourceRemoves and returns a single UTF-8 code point, reading between 1 and 4 bytes as necessary.If this source is exhausted before a complete code point can be read, this throws an
EOFExceptionand 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 as0xc080for the NUL character in modified UTF-8).- Specified by:
readUtf8CodePointin interfaceBufferedSource- Throws:
EOFException
-
readByteArray
public byte[] readByteArray()
Description copied from interface:BufferedSourceRemoves all bytes from this and returns them as a byte array.- Specified by:
readByteArrayin interfaceBufferedSource
-
readByteArray
public byte[] readByteArray(long byteCount) throws EOFExceptionDescription copied from interface:BufferedSourceRemovesbyteCountbytes from this and returns them as a byte array.- Specified by:
readByteArrayin interfaceBufferedSource- Throws:
EOFException
-
read
public int read(byte[] sink)
Description copied from interface:BufferedSourceRemoves up tosink.lengthbytes from this and copies them intosink. Returns the number of bytes read, or -1 if this source is exhausted.- Specified by:
readin interfaceBufferedSource
-
readFully
public void readFully(byte[] sink) throws EOFExceptionDescription copied from interface:BufferedSourceRemoves exactlysink.lengthbytes from this and copies them intosink. Throws anEOFExceptionif the requested number of bytes cannot be read.- Specified by:
readFullyin interfaceBufferedSource- Throws:
EOFException
-
read
public int read(byte[] sink, int offset, int byteCount)Description copied from interface:BufferedSourceRemoves up tobyteCountbytes from this and copies them intosinkatoffset. Returns the number of bytes read, or -1 if this source is exhausted.- Specified by:
readin interfaceBufferedSource
-
clear
public void clear()
Discards all bytes in this buffer. Calling this method when you're done with a buffer will return its segments to the pool.
-
skip
public void skip(long byteCount) throws EOFExceptionDiscardsbyteCountbytes from the head of this buffer.- Specified by:
skipin interfaceBufferedSource- Throws:
EOFException
-
write
public Buffer write(ByteString byteString)
- Specified by:
writein interfaceBufferedSink
-
writeUtf8
public Buffer writeUtf8(String string)
Description copied from interface:BufferedSinkEncodesstringin UTF-8 and writes it to this sink.- Specified by:
writeUtf8in interfaceBufferedSink
-
writeUtf8
public Buffer writeUtf8(String string, int beginIndex, int endIndex)
Description copied from interface:BufferedSinkEncodes the characters atbeginIndexup toendIndexfromstringin UTF-8 and writes it to this sink.- Specified by:
writeUtf8in interfaceBufferedSink
-
writeUtf8CodePoint
public Buffer writeUtf8CodePoint(int codePoint)
Description copied from interface:BufferedSinkEncodescodePointin UTF-8 and writes it to this sink.- Specified by:
writeUtf8CodePointin interfaceBufferedSink
-
writeString
public Buffer writeString(String string, Charset charset)
Description copied from interface:BufferedSinkEncodesstringincharsetand writes it to this sink.- Specified by:
writeStringin interfaceBufferedSink
-
writeString
public Buffer writeString(String string, int beginIndex, int endIndex, Charset charset)
Description copied from interface:BufferedSinkEncodes the characters atbeginIndexup toendIndexfromstringincharsetand writes it to this sink.- Specified by:
writeStringin interfaceBufferedSink
-
write
public Buffer write(byte[] source)
Description copied from interface:BufferedSinkLikeOutputStream.write(byte[]), this writes a complete byte array to this sink.- Specified by:
writein interfaceBufferedSink
-
write
public Buffer write(byte[] source, int offset, int byteCount)
Description copied from interface:BufferedSinkLikeOutputStream.write(byte[], int, int), this writesbyteCountbytes ofsource, starting atoffset.- Specified by:
writein interfaceBufferedSink
-
writeAll
public long writeAll(Source source) throws IOException
Description copied from interface:BufferedSinkRemoves all bytes fromsourceand appends them to this sink. Returns the number of bytes read which will be 0 ifsourceis exhausted.- Specified by:
writeAllin interfaceBufferedSink- Throws:
IOException
-
write
public BufferedSink write(Source source, long byteCount) throws IOException
Description copied from interface:BufferedSinkRemovesbyteCountbytes fromsourceand appends them to this sink.- Specified by:
writein interfaceBufferedSink- Throws:
IOException
-
writeByte
public Buffer writeByte(int b)
Description copied from interface:BufferedSinkWrites a byte to this sink.- Specified by:
writeBytein interfaceBufferedSink
-
writeShort
public Buffer writeShort(int s)
Description copied from interface:BufferedSinkWrites a big-endian short to this sink using two bytes.- Specified by:
writeShortin interfaceBufferedSink
-
writeShortLe
public Buffer writeShortLe(int s)
Description copied from interface:BufferedSinkWrites a little-endian short to this sink using two bytes.- Specified by:
writeShortLein interfaceBufferedSink
-
writeInt
public Buffer writeInt(int i)
Description copied from interface:BufferedSinkWrites a big-endian int to this sink using four bytes.- Specified by:
writeIntin interfaceBufferedSink
-
writeIntLe
public Buffer writeIntLe(int i)
Description copied from interface:BufferedSinkWrites a little-endian int to this sink using four bytes.- Specified by:
writeIntLein interfaceBufferedSink
-
writeLong
public Buffer writeLong(long v)
Description copied from interface:BufferedSinkWrites a big-endian long to this sink using eight bytes.- Specified by:
writeLongin interfaceBufferedSink
-
writeLongLe
public Buffer writeLongLe(long v)
Description copied from interface:BufferedSinkWrites a little-endian long to this sink using eight bytes.- Specified by:
writeLongLein interfaceBufferedSink
-
writeDecimalLong
public Buffer writeDecimalLong(long v)
Description copied from interface:BufferedSinkWrites a long to this sink in signed decimal form (i.e., as a string in base 10).- Specified by:
writeDecimalLongin interfaceBufferedSink
-
writeHexadecimalUnsignedLong
public Buffer writeHexadecimalUnsignedLong(long v)
Description copied from interface:BufferedSinkWrites a long to this sink in hexadecimal form (i.e., as a string in base 16).- Specified by:
writeHexadecimalUnsignedLongin interfaceBufferedSink
-
write
public void write(Buffer source, long byteCount)
Description copied from interface:SinkRemovesbyteCountbytes fromsourceand appends them to this.
-
read
public long read(Buffer sink, long byteCount)
Description copied from interface:SourceRemoves at least 1, and up tobyteCountbytes from this and appends them tosink. Returns the number of bytes read, or -1 if this source is exhausted.
-
indexOf
public long indexOf(byte b)
Description copied from interface:BufferedSourceReturns the index of the firstbin the buffer. This expands the buffer as necessary untilbis found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested byte is found.- Specified by:
indexOfin interfaceBufferedSource
-
indexOf
public long indexOf(byte b, long fromIndex)Returns the index ofbin this at or beyondfromIndex, or -1 if this buffer does not containbin that range.- Specified by:
indexOfin interfaceBufferedSource
-
indexOf
public long indexOf(ByteString bytes) throws IOException
Description copied from interface:BufferedSourceReturns the index of the first match forbytesin the buffer. This expands the buffer as necessary untilbytesis found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are found.- Specified by:
indexOfin interfaceBufferedSource- Throws:
IOException
-
indexOf
public long indexOf(ByteString bytes, long fromIndex) throws IOException
Description copied from interface:BufferedSourceReturns the index of the first match forbytesin the buffer at or afterfromIndex. This expands the buffer as necessary untilbytesis found. This reads an unbounded number of bytes into the buffer. Returns -1 if the stream is exhausted before the requested bytes are found.- Specified by:
indexOfin interfaceBufferedSource- Throws:
IOException
-
indexOfElement
public long indexOfElement(ByteString targetBytes)
Description copied from interface:BufferedSourceReturns the index of the first byte intargetBytesin 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.- Specified by:
indexOfElementin interfaceBufferedSource
-
indexOfElement
public long indexOfElement(ByteString targetBytes, long fromIndex)
Description copied from interface:BufferedSourceReturns the index of the first byte intargetBytesin the buffer at or afterfromIndex. 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.- Specified by:
indexOfElementin interfaceBufferedSource
-
flush
public void flush()
Description copied from interface:SinkPushes all buffered bytes to their final destination.
-
close
public void close()
Description copied from interface:SourceCloses 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.
-
timeout
public Timeout timeout()
Description copied from interface:SourceReturns the timeout for this source.
-
equals
public boolean equals(Object o)
Description copied from class:ObjectCompares this instance with the specified object and indicates if they are equal. In order to be equal,omust represent the same object as this instance using a class-specific comparison. The general contract is that this comparison should be reflexive, symmetric, and transitive. Also, no object reference other than null is equal to null.The default implementation returns
trueonly ifthis == o. See Writing a correctequalsmethod if you intend implementing your ownequalsmethod.The general contract for the
equalsandObject.hashCode()methods is that ifequalsreturnstruefor any two objects, thenhashCode()must return the same value for these objects. This means that subclasses ofObjectusually override either both methods or neither of them.- Overrides:
equalsin classObject- Parameters:
o- the object to compare this instance with.- Returns:
trueif the specified object is equal to thisObject;falseotherwise.- See Also:
Object.hashCode()
-
hashCode
public int hashCode()
Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually override both methods or neither method.Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
toString
public String toString()
Description copied from class:ObjectReturns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod.
-
clone
public Buffer clone()
Returns a deep copy of this buffer.
-
snapshot
public ByteString snapshot()
Returns an immutable copy of this buffer as a byte string.
-
snapshot
public ByteString snapshot(int byteCount)
Returns an immutable copy of the firstbyteCountbytes of this buffer as a byte string.
-
-