Class ByteString
- All Implemented Interfaces:
scala.collection.immutable.IndexedSeq<Object>,scala.collection.immutable.IndexedSeqOps<Object,,scala.collection.immutable.IndexedSeq, scala.collection.immutable.IndexedSeq<Object>> scala.collection.immutable.Iterable<Object>,scala.collection.immutable.Seq<Object>,scala.collection.immutable.SeqOps<Object,,scala.collection.immutable.Seq, scala.collection.immutable.Seq<Object>> scala.collection.immutable.StrictOptimizedSeqOps<Object,,scala.collection.immutable.IndexedSeq, ByteString> scala.collection.IndexedSeq<Object>,scala.collection.IndexedSeqOps<Object,,scala.collection.IndexedSeq, scala.collection.IndexedSeq<Object>> scala.collection.Iterable<Object>,scala.collection.IterableFactoryDefaults<Object,,scala.collection.Iterable> scala.collection.IterableOnce<Object>,scala.collection.IterableOnceOps<Object,,scala.collection.Iterable, scala.collection.Iterable> scala.collection.IterableOps<Object,,scala.collection.Iterable, scala.collection.Iterable> scala.collection.Seq<Object>,scala.collection.SeqOps<Object,,scala.collection.Seq, scala.collection.Seq<Object>> scala.collection.StrictOptimizedIterableOps<Object,,scala.collection.immutable.IndexedSeq, ByteString> scala.collection.StrictOptimizedSeqOps<Object,,scala.collection.immutable.IndexedSeq, ByteString> scala.Equals,scala.Function1<Object,,Object> scala.PartialFunction<Object,Object>
- Direct Known Subclasses:
ByteString.ByteString1,ByteString.ByteStrings,CompactByteString
TODO: Add performance characteristics
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAn unfragmented ByteString.static classINTERNAL API: ByteString backed by exactly one array, with start / end markersstatic final classA compact (unsliced) and unfragmented ByteString, implementation of ByteString1C.static classstatic final classA ByteString with 2 or more fragments.static classstatic interfacestatic classNested classes/interfaces inherited from interface scala.Function1
scala.Function1.UnliftOps<A extends Object,B extends Object>, scala.Function1.UnliftOps$ -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ByteString$plus$plus(ByteString that) Efficiently concatenate another ByteString.abstract byteapply(int idx) abstract ByteBufferReturns a read-only ByteBuffer that directly wraps this ByteString if it is not fragmented.abstract scala.collection.immutable.Iterable<ByteBuffer>Scala API: Returns an immutable Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments.abstract InputStreamReturn the bytes in this ByteString as an InputStream.final Stringabstract CompactByteStringcompact()Create a new ByteString with all contents compacted into a single, full byte array.concat(ByteString that) Java API: efficiently concatenate another ByteString.booleancontains(byte elem) Checks if this ByteString contains a specific byte.<B> booleancontains(B elem) final <B> intcopyToArray(Object xs, int start) <B> intcopyToArray(Object xs, int start, int len) abstract intcopyToBuffer(ByteBuffer buffer) Copy as many bytes as possible to a ByteBuffer, starting from it's current position.static ByteStringBuilderJava APIabstract ByteStringReturns a ByteString which is the binary representation of this ByteString if this ByteString is Base64-encoded.abstract StringdecodeString(String charset) Decodes this ByteString using a charset to produce a String.abstract StringdecodeString(Charset charset) Decodes this ByteString using a charset to produce a String.drop(int n) dropRight(int n) empty()static ByteStringJava APIabstract ByteStringReturns a ByteString which is the Base64 representation of this ByteString<U> voidstatic ByteStringfromArray(byte[] array) Creates a new ByteString by copying a byte array.static ByteStringfromArray(byte[] array, int offset, int length) Creates a new ByteString by copying length bytes starting at offset from an Array.static ByteStringfromArrayUnsafe(byte[] array) Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.static ByteStringfromArrayUnsafe(byte[] array, int offset, int length) Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.static ByteStringfromByteBuffer(ByteBuffer buffer) Creates a new ByteString by copying bytes out of a ByteBuffer.static ByteStringfromInts(int... array) JAVA API Creates a new ByteString by copying an int array by converting from integral numbers to bytes.static ByteStringJAVA API Creates a new ByteString by copying an int array by converting from integral numbers to bytes.protected ByteStringfromSpecific(scala.collection.IterableOnce<Object> coll) static ByteStringfromString(String string) Creates a new ByteString which will contain the UTF-8 representation of the given Stringstatic ByteStringfromString(String string, String charset) Creates a new ByteString which will contain the representation of the given String in the given charsetstatic ByteStringfromString(String string, Charset charset) Creates a new ByteString which will contain the representation of the given String in the given charsetJava API: Returns an Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments.scala.collection.Iterator<ByteString>grouped(int size) bytehead()intindexOf(byte elem) Finds index of first occurrence of some byte in this ByteString.intindexOf(byte elem, int from) Finds index of first occurrence of some byte in this ByteString after or at some start index.abstract intindexOf(byte elem, int from, int to) Finds index of first occurrence of some byte in this ByteString after or at some start index.<B> intindexOf(B elem, int from) intindexOfSlice(byte[] slice) Finds index of first occurrence of some slice in this ByteString.intindexOfSlice(byte[] slice, int from) Finds index of first occurrence of some slice in this ByteString.<B> intindexOfSlice(scala.collection.Seq<B> slice, int from) intindexWhere(scala.Function1<Object, Object> p, int from) init()abstract booleanCheck whether this ByteString is compact in memory.booleanisEmpty()iterator()bytelast()<A> ByteStringfinal ByteStringmap method that will automatically cast Int back into Byte.static ByteStringBuilderprotected scala.collection.mutable.Builder<Object,ByteString> slice(int from, int until) scala.Tuple2<ByteString,ByteString> scala.Tuple2<ByteString,ByteString> splitAt(int n) booleanstartsWith(byte[] bytes) Tests whether this ByteString starts with the given slice.booleanstartsWith(byte[] bytes, int offset) Tests whether this ByteString starts with the given slice.tail()take(int n) takeRight(int n) protected byte[]toArray()Java API: copy this ByteString into a fresh byte arrayfinal <B> ObjecttoArray(scala.reflect.ClassTag<B> arg0) byte[]Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.Creates a new ByteBuffer with a copy of all bytes contained in this ByteString.toString()static StringUTF_8()Standard "UTF-8" charsetfinal StringDecodes this ByteString as a UTF-8 encoded String.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface scala.Function1
apply, apply$mcDD$sp, apply$mcDF$sp, apply$mcDI$sp, apply$mcDJ$sp, apply$mcFD$sp, apply$mcFF$sp, apply$mcFI$sp, apply$mcFJ$sp, apply$mcID$sp, apply$mcIF$sp, apply$mcII$sp, apply$mcIJ$sp, apply$mcJD$sp, apply$mcJF$sp, apply$mcJI$sp, apply$mcJJ$sp, apply$mcVD$sp, apply$mcVF$sp, apply$mcVI$sp, apply$mcVJ$sp, apply$mcZD$sp, apply$mcZF$sp, apply$mcZI$sp, apply$mcZJ$sp, composeMethods inherited from interface scala.collection.immutable.IndexedSeq
applyPreferredMaxLength, canEqual, iterableFactory, sameElements, toIndexedSeqMethods inherited from interface scala.collection.IndexedSeq
stringPrefixMethods inherited from interface scala.collection.IndexedSeqOps
foldRight, headOption, knownSize, lengthCompare, lengthCompare, map, prepended, reverse, reversed, reverseIterator, search, search, sliding, stepper, view, viewMethods inherited from interface scala.collection.Iterable
coll, collectionClassName, lazyZip, seq, toIterableMethods inherited from interface scala.collection.IterableOnceOps
$colon$bslash, $div$colon, addString, addString, addString, aggregate, collectFirst, copyToArray, copyToBuffer, corresponds, count, exists, find, fold, foldLeft, forall, hasDefiniteSize, max, maxBy, maxByOption, maxOption, min, minBy, minByOption, minOption, mkString, mkString, mkString, nonEmpty, product, reduce, reduceLeft, reduceLeftOption, reduceOption, reduceRight, reduceRightOption, sum, to, toBuffer, toIterator, toList, toMap, toSet, toStream, toVectorMethods inherited from interface scala.collection.IterableOps
$plus$plus, companion, groupBy, groupMap, groupMapReduce, inits, isTraversableAgain, lastOption, repr, scan, scanRight, sizeIs, sliding, tails, toTraversable, transpose, withFilter, zipAllMethods inherited from interface scala.PartialFunction
andThen, andThen, applyOrElse, compose, elementWise, isDefinedAt, lift, orElse, runWith, unapplyMethods inherited from interface scala.collection.immutable.Seq
toSeqMethods inherited from interface scala.collection.Seq
equals, hashCodeMethods inherited from interface scala.collection.SeqOps
$colon$plus, $colon$plus$plus, $plus$colon, $plus$plus$colon, combinations, concat, containsSlice, corresponds, distinct, endsWith, findLast, indexOf, indexOfSlice, indexWhere, indices, isDefinedAt, lastIndexOf, lastIndexOf$default$2, lastIndexOfSlice, lastIndexOfSlice, lastIndexWhere, lastIndexWhere, length, lengthIs, occCounts, permutations, prefixLength, reverseMap, scala$collection$SeqOps$$toGenericSeq, segmentLength, segmentLength, size, sizeCompare, sizeCompare, sortBy, sortWith, startsWith, startsWith$default$2, unionMethods inherited from interface scala.collection.StrictOptimizedIterableOps
collect, filter, filterImpl, filterNot, flatMap, flatten, map, partition, partitionMap, scanLeft, strictOptimizedCollect, strictOptimizedConcat, strictOptimizedFlatMap, strictOptimizedFlatten, strictOptimizedMap, strictOptimizedZip, tapEach, unzip, unzip3, zip, zipWithIndexMethods inherited from interface scala.collection.immutable.StrictOptimizedSeqOps
distinctBy, patch, sorted, updatedMethods inherited from interface scala.collection.StrictOptimizedSeqOps
appended, appendedAll, diff, intersect, padTo, prepended, prependedAll
-
Constructor Details
-
ByteString
public ByteString()
-
-
Method Details
-
fromInts
JAVA API Creates a new ByteString by copying an int array by converting from integral numbers to bytes. -
fromArray
Creates a new ByteString by copying a byte array. -
fromArrayUnsafe
Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.Creates a ByteString without copying the passed in byte array, unlike other factory methods defined on ByteString. This method of creating a ByteString saves one array copy and allocation and therefore can lead to better performance, however it also means that one MUST NOT modify the passed in array, or unexpected immutable data structure contract-breaking behavior will manifest itself.
This API is intended for users who have obtained an byte array from some other API, and want wrap it into an ByteArray, and from there on only use that reference (the ByteString) to operate on the wrapped data. For all other intents and purposes, please use the usual apply and create methods - which provide the immutability guarantees by copying the array.
-
fromArray
Creates a new ByteString by copying length bytes starting at offset from an Array. -
fromArrayUnsafe
Unsafe API: Use only in situations you are completely confident that this is what you need, and that you understand the implications documented below.Creates a ByteString without copying the passed in byte array, unlike other factory methods defined on ByteString. This method of creating a ByteString saves one array copy and allocation and therefore can lead to better performance, however it also means that one MUST NOT modify the passed in array, or unexpected immutable data structure contract-breaking behavior will manifest itself.
This API is intended for users who have obtained an byte array from some other API, and want wrap it into an ByteArray, and from there on only use that reference (the ByteString) to operate on the wrapped data. For all other intents and purposes, please use the usual apply and create methods - which provide the immutability guarantees by copying the array.
-
fromInts
JAVA API Creates a new ByteString by copying an int array by converting from integral numbers to bytes. -
fromString
Creates a new ByteString which will contain the UTF-8 representation of the given String -
fromString
Creates a new ByteString which will contain the representation of the given String in the given charset -
fromString
Creates a new ByteString which will contain the representation of the given String in the given charset -
UTF_8
Standard "UTF-8" charset -
fromByteBuffer
Creates a new ByteString by copying bytes out of a ByteBuffer. -
emptyByteString
Java API -
newBuilder
-
createBuilder
Java API -
fromSpecific
-
newSpecificBuilder
-
empty
-
apply
public abstract byte apply(int idx) -
className
- Specified by:
classNamein interfacescala.collection.Iterable<Object>
-
isEmpty
public boolean isEmpty() -
iterator
-
head
public byte head() -
tail
- Specified by:
tailin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
last
public byte last() -
init
- Specified by:
initin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
take
- Specified by:
takein interfacescala.collection.IndexedSeqOps<Object,scala.collection.IndexedSeq, scala.collection.IndexedSeq<Object>> - Specified by:
takein interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
takein interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
takeRight
- Specified by:
takeRightin interfacescala.collection.IndexedSeqOps<Object,scala.collection.IndexedSeq, scala.collection.IndexedSeq<Object>> - Specified by:
takeRightin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
takeRightin interfacescala.collection.StrictOptimizedIterableOps<Object,scala.collection.immutable.IndexedSeq, ByteString>
-
slice
- Specified by:
slicein interfacescala.collection.immutable.IndexedSeqOps<Object,scala.collection.immutable.IndexedSeq, scala.collection.immutable.IndexedSeq<Object>> - Specified by:
slicein interfacescala.collection.IndexedSeqOps<Object,scala.collection.IndexedSeq, scala.collection.IndexedSeq<Object>> - Specified by:
slicein interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
slicein interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
drop
- Specified by:
dropin interfacescala.collection.IndexedSeqOps<Object,scala.collection.IndexedSeq, scala.collection.IndexedSeq<Object>> - Specified by:
dropin interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
dropin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
dropRight
- Specified by:
dropRightin interfacescala.collection.IndexedSeqOps<Object,scala.collection.IndexedSeq, scala.collection.IndexedSeq<Object>> - Specified by:
dropRightin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
dropRightin interfacescala.collection.StrictOptimizedIterableOps<Object,scala.collection.immutable.IndexedSeq, ByteString>
-
takeWhile
-
dropWhile
-
span
- Specified by:
spanin interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
spanin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable> - Specified by:
spanin interfacescala.collection.StrictOptimizedIterableOps<Object,scala.collection.immutable.IndexedSeq, ByteString>
-
splitAt
-
indexWhere
-
indexOf
public <B> int indexOf(B elem, int from) -
indexOf
public abstract int indexOf(byte elem, int from, int to) Finds index of first occurrence of some byte in this ByteString after or at some start index. This overload allows you to specify an end index (exclusive).- Parameters:
elem- the element value to search for.from- the start indexto- the end index (exclusive)- Returns:
- the index
>= fromand< toof the first element of this ByteString that is equal (as determined by==) toelem, or-1, if none exists. - Since:
- 1.3.0
-
indexOf
public int indexOf(byte elem, int from) Finds index of first occurrence of some byte in this ByteString after or at some start index.Similar to Seq's indexOf, but it avoids boxing if the value is already a byte.
- Parameters:
elem- the element value to search for.from- the start index- Returns:
- the index
>= fromof the first element of this ByteString that is equal (as determined by==) toelem, or-1, if none exists. - Since:
- 1.1.0
-
indexOf
public int indexOf(byte elem) Finds index of first occurrence of some byte in this ByteString.Similar to Seq's indexOf, but it avoids boxing if the value is already a byte.
- Parameters:
elem- the element value to search for.- Returns:
- the index
>= fromof the first element of this ByteString that is equal (as determined by==) toelem, or-1, if none exists. - Since:
- 1.1.0
-
indexOfSlice
public <B> int indexOfSlice(scala.collection.Seq<B> slice, int from) -
indexOfSlice
public int indexOfSlice(byte[] slice, int from) Finds index of first occurrence of some slice in this ByteString.- Parameters:
slice- the slice to search for.from- the start index- Returns:
- the index greater than or equal to
fromof the first element of this ByteString that starts a slice equal (as determined by==) toslice, or-1, if none exists. - Since:
- 2.0.0
-
indexOfSlice
public int indexOfSlice(byte[] slice) Finds index of first occurrence of some slice in this ByteString.- Parameters:
slice- the slice to search for.- Returns:
- the index of the first element of this
ByteString that starts a slice equal (as determined by
==) toslice, or-1, if none exists. - Since:
- 2.0.0
-
contains
public <B> boolean contains(B elem) -
contains
public boolean contains(byte elem) Checks if this ByteString contains a specific byte. Similar to Seq's contains function, but it avoids boxing if the value is already a byte.- Since:
- 2.0.0
-
startsWith
public boolean startsWith(byte[] bytes, int offset) Tests whether this ByteString starts with the given slice.- Parameters:
bytes- the slice to testoffset- the offset to start testing from- Returns:
- true if this ByteString starts with the given slice
- Since:
- 2.0.0
-
startsWith
public boolean startsWith(byte[] bytes) Tests whether this ByteString starts with the given slice.- Parameters:
bytes- the slice to test- Returns:
- true if this ByteString starts with the given slice
- Since:
- 2.0.0
-
grouped
- Specified by:
groupedin interfacescala.collection.IterableOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
toString
-
toArray
protected byte[] toArray()Java API: copy this ByteString into a fresh byte array- Returns:
- this ByteString copied into a byte array
-
toArray
- Specified by:
toArrayin interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
copyToArray
- Specified by:
copyToArrayin interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
copyToArray
- Specified by:
copyToArrayin interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
toArrayUnsafe
public byte[] toArrayUnsafe()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.
-
asInputStream
Return the bytes in this ByteString as an InputStream.- Returns:
- the bytes in this ByteString accessible as an InputStream
- Since:
- 1.1.0
- See Also:
-
foreach
- Specified by:
foreachin interfacescala.collection.IterableOnceOps<Object,scala.collection.Iterable, scala.collection.Iterable>
-
$plus$plus
Efficiently concatenate another ByteString. -
concat
Java API: efficiently concatenate another ByteString. -
copyToBuffer
Copy as many bytes as possible to a ByteBuffer, starting from it's current position. This method will not overflow the buffer.- Parameters:
buffer- a ByteBuffer to copy bytes to- Returns:
- the number of bytes actually copied
-
compact
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. -
isCompact
public abstract boolean isCompact()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. -
asByteBuffer
Returns a read-only ByteBuffer that directly wraps this ByteString if it is not fragmented. -
asByteBuffers
Scala API: Returns an immutable Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments. Will always have at least one entry. -
getByteBuffers
Java API: Returns an Iterable of read-only ByteBuffers that directly wraps this ByteStrings all fragments. Will always have at least one entry. -
toByteBuffer
Creates a new ByteBuffer with a copy of all bytes contained in this ByteString. -
utf8String
Decodes this ByteString as a UTF-8 encoded String. -
decodeString
Decodes this ByteString using a charset to produce a String. If you have aCharsetinstance available, usedecodeString(charset: java.nio.charset.Charsetinstead. -
decodeString
Decodes this ByteString using a charset to produce a String. Avoids Charset.forName lookup in String internals, thus is preferable todecodeString(charset: String). -
decodeBase64
Returns a ByteString which is the binary representation of this ByteString if this ByteString is Base64-encoded. -
encodeBase64
Returns a ByteString which is the Base64 representation of this ByteString -
mapI
map method that will automatically cast Int back into Byte. -
map
-