abstract class Buf extends AnyRef
Buf represents a fixed, immutable byte buffer with efficient positional access. Buffers may be sliced and concatenated, and thus be used to implement bytestreams.
- Self Type
- Buf
- See also
com.twitter.io.Buf.ByteArray for an
Array[Byte]
backed implementation.com.twitter.io.Buf.ByteBuffer for a
java.nio.ByteBuffer
backed implementation.com.twitter.io.Buf.apply for creating a
Buf
from otherBufs
com.twitter.io.Buf.Empty for an empty
Buf
.
- Alphabetic
- By Inheritance
- Buf
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new Buf()
Abstract Value Members
- abstract def get(index: Int): Byte
Returns the byte at the given index.
- abstract def length: Int
The number of bytes in the buffer
- abstract def process(from: Int, until: Int, processor: Processor): Int
Process the
Buf
1-byte at a time using the given Buf.Processor, starting at indexfrom
until indexuntil
.Process the
Buf
1-byte at a time using the given Buf.Processor, starting at indexfrom
until indexuntil
. Processing will halt if the processor returnsfalse
or after processing the final byte.- from
the starting index, inclusive. Must be non-negative.
- until
the ending index, exclusive. Must be non-negative.
- returns
-1 if the processor processed all bytes or the last processed index if the processor returns
false
. Will return -1 iffrom
is greater than or equal tountil
or length. Will return -1 ifuntil
is greater than or equal to length.
- Note
this mimics the design of Netty 4's
io.netty.buffer.ByteBuf.forEachByte
- abstract def slice(from: Int, until: Int): Buf
Returns a new buffer representing a slice of this buffer, delimited by the indices
from
inclusive anduntil
exclusive:[from, until)
.Returns a new buffer representing a slice of this buffer, delimited by the indices
from
inclusive anduntil
exclusive:[from, until)
. Out of bounds indices are truncated. Negative indices are not accepted.- Note
Buf implementors should use the helpers Buf.checkSliceArgs, isSliceEmpty, and isSliceIdentity.
- abstract def unsafeByteArrayBuf: Option[ByteArray]
Helper to support 0-copy coercion to Buf.ByteArray.
Helper to support 0-copy coercion to Buf.ByteArray.
- Attributes
- protected
- abstract def write(output: ByteBuffer): Unit
Write the entire contents of this
Buf
into the given nio buffer.Write the entire contents of this
Buf
into the given nio buffer. Partial writes aren't supported directly through this API; they can be accomplished by first slicing the buffer. This method should be preferred overBuf.ByteBuffer.extract
,Buf.ByteArray.Owned
, etc family of functions when you want to control the destination of the data, as opposed to letting theBuf
implementation manage the destination. For example, if the data is destined for an IO operation, it may be preferable to provide a direct nioByteBuffer
to ensure the avoidance of intermediate heap-based representations.- Annotations
- @throws(classOf[IllegalArgumentException]) @throws(classOf[ReadOnlyBufferException])
- Note
Throws
,java.lang.IllegalArgumentException
whenoutput
doesn't have enough space as defined byByteBuffer.remaining()
to hold the contents of thisBuf
.Throws
,ReadOnlyBufferException
if the provided buffer is read-only.Buf implementors should use the helper checkWriteArgs.
- See also
write(Array[Byte],Int) for writing to byte arrays.
- abstract def write(output: Array[Byte], off: Int): Unit
Write the entire contents of this
Buf
into the given array at the given offset.Write the entire contents of this
Buf
into the given array at the given offset. Partial writes aren't supported directly through this API; they can be accomplished by first slicing the buffer. This method should be preferred over theBuf.ByteArray.extract
,Buf.ByteArray.Owned
, etc family of functions when you want to control the destination of the data, as opposed to letting theBuf
implementation manage the destination. For example, if you want to manually set the first bytes of anArray[Byte]
and then efficiently copy the contents of thisBuf
to the remaining space.- Annotations
- @throws(classOf[IllegalArgumentException])
- Note
Throws
,IllegalArgumentException
whenoutput
is too small to contain all the data.Buf implementors should use the helper checkWriteArgs.
- See also
write(ByteBuffer) for writing to nio buffers.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def checkWriteArgs(outputLen: Int, outputOff: Int): Unit
Helps implementations validate the arguments to Buf.write(output:Array[Byte],off:Int):Unit*.
Helps implementations validate the arguments to Buf.write(output:Array[Byte],off:Int):Unit*.
- Attributes
- protected[this]
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def computeHashCode: Int
Compute the 32-bit FNV-1 hash code of this buf.
Compute the 32-bit FNV-1 hash code of this buf.
- Attributes
- protected
- final def concat(right: Buf): Buf
Concatenate this buffer with the given buffer.
- def copiedByteArray: Array[Byte]
Definitely requires copying.
Definitely requires copying.
- Attributes
- protected
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(other: Any): Boolean
- Definition Classes
- Buf → AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def hashCode(): Int
- Definition Classes
- Buf → AnyRef → Any
- def isEmpty: Boolean
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isSliceEmpty(from: Int, until: Int): Boolean
Helps implementations of slice.
Helps implementations of slice.
- Attributes
- protected[this]
- def isSliceIdentity(from: Int, until: Int): Boolean
Helps implementations of slice.
Helps implementations of slice.
- Attributes
- protected[this]
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def process(processor: Processor): Int
Process the
Buf
1-byte at a time using the given Buf.Processor, starting at index0
until index length.Process the
Buf
1-byte at a time using the given Buf.Processor, starting at index0
until index length. Processing will halt if the processor returnsfalse
or after processing the final byte.- returns
-1 if the processor processed all bytes or the last processed index if the processor returns
false
.
- Note
this mimics the design of Netty 4's
io.netty.buffer.ByteBuf.forEachByte
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unsafeByteArray: Array[Byte]
May require copying.
May require copying.
- Attributes
- protected
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()