A rope-like immutable data structure containing bytes. The goal of this structure is to reduce copying of arrays when concatenating and slicing sequences of bytes, and also providing a thread safe way of working with bytes.
TODO: Add performance characteristics
- Companion:
- object
- Source:
- ByteString.scala
Value members
Abstract methods
Efficiently concatenate another ByteString.
Efficiently concatenate another ByteString.
- Source:
- ByteString.scala
Returns a read-only ByteBuffer that directly wraps this ByteString if it is not fragmented.
Returns a read-only ByteBuffer that directly wraps this ByteString if it is not fragmented.
- Source:
- ByteString.scala
Scala API: Returns an immutable Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments. Will always have at least one entry.
Scala API: Returns an immutable Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments. Will always have at least one entry.
- Source:
- ByteString.scala
Create a new ByteString with all contents compacted into a single, full byte array. If isCompact returns true, compact is an O(1) operation, but might return a different object with an optimized implementation.
Create a new ByteString with all contents compacted into a single, full byte array. If isCompact returns true, compact is an O(1) operation, but might return a different object with an optimized implementation.
- Source:
- ByteString.scala
Copy as many bytes as possible to a ByteBuffer, starting from it's current position. This method will not overflow the buffer.
Copy as many bytes as possible to a ByteBuffer, starting from it's current position. This method will not overflow the buffer.
- Value parameters:
- buffer
a ByteBuffer to copy bytes to
- Returns:
the number of bytes actually copied
- Source:
- ByteString.scala
Decodes this ByteString using a charset to produce a String.
If you have a Charset instance available, use decodeString(charset: java.nio.charset.Charset
instead.
Decodes this ByteString using a charset to produce a String.
If you have a Charset instance available, use decodeString(charset: java.nio.charset.Charset
instead.
- Source:
- ByteString.scala
Decodes this ByteString using a charset to produce a String.
Avoids Charset.forName lookup in String internals, thus is preferable to decodeString(charset: String)
.
Decodes this ByteString using a charset to produce a String.
Avoids Charset.forName lookup in String internals, thus is preferable to decodeString(charset: String)
.
- Source:
- ByteString.scala
Returns a ByteString which is the Base64 representation of this ByteString
Returns a ByteString which is the Base64 representation of this ByteString
- Source:
- ByteString.scala
Check whether this ByteString is compact in memory. If the ByteString is compact, it might, however, not be represented by an object that takes full advantage of that fact. Use compact to get such an object.
Check whether this ByteString is compact in memory. If the ByteString is compact, it might, however, not be represented by an object that takes full advantage of that fact. Use compact to get such an object.
- Source:
- ByteString.scala
Concrete methods
Java API: efficiently concatenate another ByteString.
Java API: efficiently concatenate another ByteString.
- Source:
- ByteString.scala
Java API: Returns an Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments. Will always have at least one entry.
Java API: Returns an Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments. Will always have at least one entry.
- Source:
- ByteString.scala
map method that will automatically cast Int back into Byte.
map method that will automatically cast Int back into Byte.
- Source:
- ByteString.scala
Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.
Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.
If the ByteString is backed by a single array it is returned without any copy. If it is backed by a rope of multiple ByteString instances a new array will be allocated and the contents will be copied into it before returning it.
This method of exposing the bytes of a ByteString can save one array copy and allocation in the happy path scenario which can lead to better performance, however it also means that one MUST NOT modify the returned array, or unexpected immutable data structure contract-breaking behavior will manifest itself.
This API is intended for users who need to pass the byte array to some other API, which will only read the bytes and never mutate then. For all other intents and purposes, please use the usual toArray method - which provide the immutability guarantees by copying the backing array.
- Source:
- ByteString.scala
Creates a new ByteBuffer with a copy of all bytes contained in this ByteString.
Creates a new ByteBuffer with a copy of all bytes contained in this ByteString.
- Source:
- ByteString.scala
Decodes this ByteString as a UTF-8 encoded String.
Decodes this ByteString as a UTF-8 encoded String.
- Source:
- ByteString.scala
Inherited methods
- Inherited from:
- IterableOnceOps
- Inherited from:
- SeqOps
- Inherited from:
- SeqOps
- Inherited from:
- SeqOps
- Inherited from:
- SeqOps
- Inherited from:
- SeqOps
- Inherited from:
- IterableOnceOps
- Inherited from:
- IndexedSeq
- Inherited from:
- StrictOptimizedSeqOps
- Definition Classes
- Inherited from:
- StrictOptimizedIterableOps
Deprecated and Inherited methods
- Deprecated
[Since version 2.13.0]
Use foldLeft instead of /:- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
Use foldRight instead of :\\- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
`aggregate` is not relevant for sequential collections. Use `foldLeft(z)(seqop)` instead.- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
Use iterableFactory instead- Inherited from:
- IterableOps
- Deprecated
[Since version 2.13.0]
Use `dest ++= coll` instead- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
Check .knownSize instead of .hasDefiniteSize for more actionable information (see scaladoc for details)- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
Use segmentLength instead of prefixLength- Inherited from:
- SeqOps
- Deprecated
[Since version 2.13.0]
Use coll instead of repr in a collection implementation, use the collection value itself from the outside- Inherited from:
- IterableOps
- Deprecated
[Since version 2.13.0]
Use .reverseIterator.map(f).to(...) instead of .reverseMap(f)- Inherited from:
- SeqOps
- Deprecated
[Since version 2.13.0]
Iterable.seq always returns the iterable itself- Inherited from:
- Iterable
- Deprecated
[Since version 2.13.0]
Use .iterator instead of .toIterator- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
Use .to(LazyList) instead of .toStream- Inherited from:
- IterableOnceOps
- Deprecated
[Since version 2.13.0]
Use toIterable instead- Inherited from:
- IterableOps
- Deprecated
[Since version 2.13.0]
Use `concat` instead- Inherited from:
- SeqOps
- Deprecated
[Since version 2.13.0]
Use .view.slice(from, until) instead of .view(from, until)- Definition Classes
- Inherited from:
- IndexedSeqOps