An immutable vector of bytes, backed by a balanced binary tree of
chunks. Most operations are logarithmic in the depth of this tree,
including ++
, :+
, +:
, update
, and insert
. Where possible,
operations return lazy views rather than copying any underlying bytes.
Use copy
to copy all underlying bytes to a fresh, array-backed ByteVector
.
An immutable vector of bytes, backed by a balanced binary tree of
chunks. Most operations are logarithmic in the depth of this tree,
including ++
, :+
, +:
, update
, and insert
. Where possible,
operations return lazy views rather than copying any underlying bytes.
Use copy
to copy all underlying bytes to a fresh, array-backed ByteVector
.
Unless otherwise noted, operations follow the same naming as the scala
standard library collections, though this class does not extend any of the
standard scala collections. Use toIndexedSeq
, toSeq
, or toIterable
to obtain a regular scala.collection
type.
- Companion
- object
Document{}
Returns the number of bytes in this vector, or None
if the size does not
fit into an Int
.
Returns the number of bytes in this vector, or None
if the size does not
fit into an Int
.
Returns true if this vector has a non-zero number of bytes.
Returns true if this vector has a non-zero number of bytes.
Gets the byte at the specified index.
Gets the byte at the specified index.
- Throws
- IndexOutOfBoundsException
if the specified index is not in
[0, size)
Returns the byte at the specified index, or None
if the index is out of range.
Returns the byte at the specified index, or None
if the index is out of range.
Returns a vector with the byte at the specified index replaced with the specified byte.
Returns a vector with the byte at the specified index replaced with the specified byte.
Returns a vector with the specified byte inserted at the specified index.
Returns a vector with the specified byte inserted at the specified index.
Returns a vector with the specified byte vector inserted at the specified index.
Returns a vector with the specified byte vector inserted at the specified index.
Returns a vector with the specified byte vector replacing bytes [idx, idx + b.size]
.
Returns a vector with the specified byte vector replacing bytes [idx, idx + b.size]
.
Returns a new byte vector representing this vector's contents followed by the specified vector's contents.
Returns a new byte vector representing this vector's contents followed by the specified vector's contents.
Returns a new vector with the specified byte prepended.
Returns a new vector with the specified byte prepended.
Returns a new vector with the specified byte appended.
Returns a new vector with the specified byte appended.
Returns a vector of all bytes in this vector except the first n
bytes.
Returns a vector of all bytes in this vector except the first n
bytes.
The resulting vector's size is 0 max (size - n)
.
Returns a vector of all bytes in this vector except the last n
bytes.
Returns a vector of all bytes in this vector except the last n
bytes.
The resulting vector's size is 0 max (size - n)
.
Drops the longest prefix of this vector such that every byte of the prefix satisfies the specific predicate.
Drops the longest prefix of this vector such that every byte of the prefix satisfies the specific predicate.
Returns a vector of the first n
bytes of this vector.
Returns a vector of the first n
bytes of this vector.
The resulting vector's size is n min size
.
Note: if an n
-byte vector is required, use the acquire
method instead.
- See also
acquire
Returns a vector of the last n
bytes of this vector.
Returns a vector of the last n
bytes of this vector.
The resulting vector's size is n min size
.
Returns the longest prefix of this vector such that every byte satisfies the specific predicate.
Returns the longest prefix of this vector such that every byte satisfies the specific predicate.
Returns a pair of vectors that is equal to (take(n), drop(n))
.
Returns a pair of vectors that is equal to (take(n), drop(n))
.
Returns a vector made up of the bytes starting at index from
up to index until
.
Returns a vector made up of the bytes starting at index from
up to index until
.
Returns a vector whose contents are the results of taking the first n
bytes of this vector.
Returns a vector whose contents are the results of taking the first n
bytes of this vector.
If this vector does not contain at least n
bytes, an error message is returned.
- See also
take
Consumes the first n
bytes of this vector and decodes them with the specified function,
resulting in a vector of the remaining bytes and the decoded value. If this vector
does not have n
bytes or an error occurs while decoding, an error is returned instead.
Consumes the first n
bytes of this vector and decodes them with the specified function,
resulting in a vector of the remaining bytes and the decoded value. If this vector
does not have n
bytes or an error occurs while decoding, an error is returned instead.
Applies a binary operator to a start value and all elements of this vector, going left to right.
Applies a binary operator to a start value and all elements of this vector, going left to right.
- Value Params
- f
operator to apply
- z
starting value
Applies a binary operator to a start value and all elements of this vector, going right to left.
Applies a binary operator to a start value and all elements of this vector, going right to left.
- Value Params
- f
operator to apply
- z
starting value
Applies a binary operator to a start value and all segments(views) of this ByteVector expressed as read-only ByteBuffer, going left to right.
Applies a binary operator to a start value and all segments(views) of this ByteVector expressed as read-only ByteBuffer, going left to right.
- Value Params
- f
operator to apply
- z
Starting value
Applies a binary operator to a start value and all segments(views) of this ByteVector expressed as read-only ByteBuffer, going right ot left.
Applies a binary operator to a start value and all segments(views) of this ByteVector expressed as read-only ByteBuffer, going right ot left.
- Value Params
- f
operator to apply
- z
Starting value
Applies the specified function to each element of this vector.
Applies the specified function to each element of this vector.
Returns true if this byte vector starts with the specified vector.
Returns true if this byte vector starts with the specified vector.
Returns true if this byte vector ends with the specified vector.
Returns true if this byte vector ends with the specified vector.
Finds the first index of the specified byte pattern in this vector.
Finds the first index of the specified byte pattern in this vector.
- Returns
index of slice or -1 if not found
Finds the first index after from
of the specified byte pattern in this vector.
Finds the first index after from
of the specified byte pattern in this vector.
- Returns
index of slice or -1 if not found
Determines if the specified slice is in this vector.
Determines if the specified slice is in this vector.
Returns the first byte of this vector or throws if vector is emtpy.
Returns the first byte of this vector or throws if vector is emtpy.
Returns the first byte of this vector or None
if vector is emtpy.
Returns the first byte of this vector or None
if vector is emtpy.
Returns a vector of all bytes in this vector except the first byte.
Returns a vector of all bytes in this vector except the first byte.
Returns a vector of all bytes in this vector except the last byte.
Returns a vector of all bytes in this vector except the last byte.
Returns the last byte in this vector or throws if vector is empty.
Returns the last byte in this vector or throws if vector is empty.
Returns the last byte in this vector or returns None
if vector is empty.
Returns the last byte in this vector or returns None
if vector is empty.
Returns an n
-byte vector whose contents are this vector's contents followed by 0 or more zero bytes.
Returns an n
-byte vector whose contents are this vector's contents followed by 0 or more zero bytes.
- Throws
- IllegalArgumentException
if
n < size
Returns an n
-bytes vector whose contents are 0 or more zero bytes followed by this vector's contents.
Returns an n
-bytes vector whose contents are 0 or more zero bytes followed by this vector's contents.
- Throws
- IllegalArgumentException
if
n < size
Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector. This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector. This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector. Only the least significant byte is used (the three most significant bytes are ignored). This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a vector where each byte is the result of applying the specified function to the corresponding byte in this vector. Only the least significant byte is used (the three most significant bytes are ignored). This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a vector with the bytes of this vector in reverse order. This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a vector with the bytes of this vector in reverse order. This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a vector with the same contents but represented as a single tree node internally.
Returns a vector with the same contents but represented as a single tree node internally.
This may involve copying data, but has the advantage that lookups index directly into a single node rather than traversing a logarithmic number of nodes in this tree.
Calling this method on an already compacted vector is a no-op.
Invokes compact
on any subtrees whose size is <= chunkSize
.
Invokes compact
on any subtrees whose size is <= chunkSize
.
Returns a vector with the same contents as this vector but with a single compacted node made up by evaluating all internal nodes and concatenating their values.
Returns a vector with the same contents as this vector but with a single compacted node made up by evaluating all internal nodes and concatenating their values.
Converts the contents of this vector to a byte array.
Converts the contents of this vector to a byte array.
Copies the contents of this vector to array xs
, beginning at index start
.
Copies the contents of this vector to array xs
, beginning at index start
.
Copies size
bytes of this vector, starting at index offset
, to array xs
, beginning at index start
.
Copies size
bytes of this vector, starting at index offset
, to array xs
, beginning at index start
.
Copies as many bytes as possible to the given ByteBuffer, starting from its current position. This method will not overflow the buffer.
Copies as many bytes as possible to the given ByteBuffer, starting from its current position. This method will not overflow the buffer.
- Value Params
- buffer
a ByteBuffer to copy bytes to
- Returns
the number of bytes actually copied
Copies the contents of this vector to OutputStream s
.
Copies the contents of this vector to OutputStream s
.
Converts the contents of this vector to an IndexedSeq
.
Converts the contents of this vector to an IndexedSeq
.
Converts the contents of this vector to an Iterable
.
Converts the contents of this vector to an Iterable
.
Converts the contents of this vector to a bit vector of size * 8
bits.
Converts the contents of this vector to a bit vector of size * 8
bits.
Allocate (unobservable) mutable scratch space at the end of this
ByteVector
, which will be used to support fast :+
and ++
of small vectors. A default chunk size is used.
Allocate (unobservable) mutable scratch space at the end of this
ByteVector
, which will be used to support fast :+
and ++
of small vectors. A default chunk size is used.
Note that :+
, ++
, and drop
on the result of a call to buffer
are guaranteed to return another buffered ByteVector
.
Allocate (unobservable) mutable scratch space at the end of this
ByteVector
, with chunks of the given size, which will be used to
support fast :+
and ++
of small vectors.
Allocate (unobservable) mutable scratch space at the end of this
ByteVector
, with chunks of the given size, which will be used to
support fast :+
and ++
of small vectors.
Note that :+
, ++
, and drop
on the result of a call to buffer
are guaranteed to return another buffered ByteVector
, with the
same size scratch space.
Collapse any buffered chunks at the end of this ByteVector
,
resulting in an unbuffered ByteVector
.
Collapse any buffered chunks at the end of this ByteVector
,
resulting in an unbuffered ByteVector
.
Represents the contents of this vector as a read-only java.nio.ByteBuffer
.
Represents the contents of this vector as a read-only java.nio.ByteBuffer
.
The returned buffer is read-only with limit set to the minimum number of bytes needed to represent the contents of this vector, position set to zero, and remaining set to the limit.
Converts the contents of this byte vector to a binary string of size * 8
digits.
Converts the contents of this byte vector to a binary string of size * 8
digits.
Converts the contents of this byte vector to a binary string of size * 8
digits.
Converts the contents of this byte vector to a binary string of size * 8
digits.
Converts the contents of this byte vector to a hexadecimal string of size * 2
nibbles.
Converts the contents of this byte vector to a hexadecimal string of size * 2
nibbles.
Converts the contents of this byte vector to a hexadecimal string of size * 2
nibbles.
Converts the contents of this byte vector to a hexadecimal string of size * 2
nibbles.
Converts the contents of this vector to a base 32 string.
Converts the contents of this vector to a base 32 string.
Converts the contents of this vector to a base 32 string using the specified alphabet.
Converts the contents of this vector to a base 32 string using the specified alphabet.
Converts the contents of this vector to a base 58 string.
Converts the contents of this vector to a base 58 string.
Converts the contents of this vector to a base 58 string using the specified alphabet.
Converts the contents of this vector to a base 58 string using the specified alphabet.
Converts the contents of this vector to a base 64 string.
Converts the contents of this vector to a base 64 string.
Converts the contents of this vector to a base 64 string using the specified alphabet.
Converts the contents of this vector to a base 64 string using the specified alphabet.
Converts the contents of this vector to a base 64 string without padding.
Converts the contents of this vector to a base 64 string without padding.
Converts the contents of this vector to a base 64 url string with padding.
Converts the contents of this vector to a base 64 url string with padding.
Converts the contents of this vector to a base 64 url string without padding.
Converts the contents of this vector to a base 64 url string without padding.
Converts the contents of this vector to a byte.
Converts the contents of this vector to a byte.
- Value Params
- signed
whether sign extension should be performed
- Throws
- IllegalArgumentException
if size is greater than 8
Converts the contents of this vector to a short.
Converts the contents of this vector to a short.
- Value Params
- ordering
order bytes should be processed in
- signed
whether sign extension should be performed
- Throws
- IllegalArgumentException
if size is greater than 16
Converts the contents of this vector to an int.
Converts the contents of this vector to an int.
- Value Params
- ordering
order bytes should be processed in
- signed
whether sign extension should be performed
- Throws
- IllegalArgumentException
if size is greater than 32
Converts the contents of this vector to an int.
Converts the contents of this vector to an int.
- Value Params
- ordering
order bytes should be processed in
- signed
whether sign extension should be performed
- Throws
- IllegalArgumentException
if size is greater than 64
Converts the contents of this byte vector to a UUID.
Converts the contents of this byte vector to a UUID.
- Throws
- IllegalArgumentException
if size is not exactly 16.
Decodes this vector as a string using the implicitly available charset.
Decodes this vector as a string using the implicitly available charset.
Decodes this vector as a string using the UTF-8 charset.
Decodes this vector as a string using the UTF-8 charset.
Decodes this vector as a string using the US-ASCII charset.
Decodes this vector as a string using the US-ASCII charset.
Returns a new vector where each byte is the result of evaluating the specified function
against the bytes of this vector and the specified vector at the corresponding index.
The resulting vector has size this.size min other.size
.
This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a new vector where each byte is the result of evaluating the specified function
against the bytes of this vector and the specified vector at the corresponding index.
The resulting vector has size this.size min other.size
.
This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a new vector where each byte is the result of evaluating the specified function
against the bytes of this vector and the specified vector at the corresponding index.
The resulting vector has size this.size min other.size
.
Only the least significant byte is used (the three most significant bytes are ignored).
This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Returns a new vector where each byte is the result of evaluating the specified function
against the bytes of this vector and the specified vector at the corresponding index.
The resulting vector has size this.size min other.size
.
Only the least significant byte is used (the three most significant bytes are ignored).
This method returns a view and hence, is O(1). Call compact to generate a new strict vector.
Compresses this vector using ZLIB.
Compresses this vector using ZLIB.
- Value Params
- chunkSize
buffer size, in bytes, to use when compressing
- level
compression level, 0-9, with 0 disabling compression and 9 being highest level of compression -- see
java.util.zip.Deflater
for details- nowrap
if true, ZLIB header and checksum will not be used
- strategy
compression strategy -- see
java.util.zip.Deflater
for details
Decompresses this vector using ZLIB.
Decompresses this vector using ZLIB.
- Value Params
- chunkSize
buffer size, in bytes, to use when compressing
- nowrap
if true, will assume no ZLIB header and checksum
Computes a digest of this byte vector.
Computes a digest of this byte vector.
- Value Params
- algorithm
digest algorithm to use
Computes a digest of this byte vector.
Computes a digest of this byte vector.
- Value Params
- digest
digest to use
Encrypts this byte vector using the specified cipher and key.
Encrypts this byte vector using the specified cipher and key.
- Value Params
- aparams
optional algorithm paramaters used for encryption (e.g., initialization vector)
- ci
cipher to use for encryption
- key
key to encrypt with
- sr
secure random
Decrypts this byte vector using the specified cipher and key.
Decrypts this byte vector using the specified cipher and key.
- Value Params
- aparams
optional algorithm paramaters used for decryption (e.g., initialization vector)
- ci
cipher to use for decryption
- key
key to decrypt with
- sr
secure random
Calculates the hash code of this vector. The result is cached.
Calculates the hash code of this vector. The result is cached.
Returns true if the specified ByteVector
has the same contents as this vector.
Returns true if the specified ByteVector
has the same contents as this vector.
Returns true if the specified value is a ByteVector
with the same contents as this vector.
Returns true if the specified value is a ByteVector
with the same contents as this vector.
- See also
- Definition Classes
- Any
Display the size and bytes of this ByteVector
.
For bit vectors beyond a certain size, only a hash of the
contents are shown.
Display the size and bytes of this ByteVector
.
For bit vectors beyond a certain size, only a hash of the
contents are shown.
- Definition Classes
- Any
Returns a bitwise XOR of this value with the specified value.
Returns a bitwise XOR of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations
Returns a bitwise complement of this value.
Returns a bitwise complement of this value.
- Inherited from
- BitwiseOperations
Returns a value of the same size with each bit shifted to the left n
bits.
Returns a value of the same size with each bit shifted to the left n
bits.
- Inherited from
- BitwiseOperations
Returns a bitwise if-and-only-if of this value with the specified value.
Returns a bitwise if-and-only-if of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations
Returns a value of the same size with each bit shifted to the right n
bits where the n
left-most bits are sign extended.
Returns a value of the same size with each bit shifted to the right n
bits where the n
left-most bits are sign extended.
- Inherited from
- BitwiseOperations
Returns a bitwise AND of this value with the specified value.
Returns a bitwise AND of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations
Returns a bitwise OR of this value with the specified value.
Returns a bitwise OR of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations
Returns a bitwise NOR of this value with the specified value.
Returns a bitwise NOR of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations
Returns a value of the same size with each bit shifted to the right n
bits where the n
left-most bits are low.
Returns a value of the same size with each bit shifted to the right n
bits where the n
left-most bits are low.
- Inherited from
- BitwiseOperations
Returns a bitwise NAND of this value with the specified value.
Returns a bitwise NAND of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations
Returns a bitwise implication of this value with the specified value.
Returns a bitwise implication of this value with the specified value.
The resulting value's size is the minimum of this value's size and the specified value's size.
- Inherited from
- BitwiseOperations