Skip to content

okio / okio / ByteString

ByteString

(js, jvm, native) open class ByteString :Comparable<ByteString>

An immutable sequence of bytes.

Byte strings compare lexicographically as a sequence of unsigned bytes. That is, the byte string ff sorts after 00. This is counter to the sort order of the corresponding bytes, where -1 sorts before 0.

Full disclosure: this class provides untrusted input and output streams with raw access to the underlying byte array. A hostile stream implementation could keep a reference to the mutable byte string, violating the immutable guarantee of this class. For this reason a byte string’s immutability guarantee cannot be relied upon for security in applets and other environments that run both trusted and untrusted code in the same process.

Properties

Name Summary
size Returns the number of bytes in this ByteString.(js, jvm) val size:Int
(native) val size: <ERROR CLASS>

Functions

Name Summary
(jvm) asByteBuffer Returns a ByteBuffer view of the bytes in this ByteString.open fun asByteBuffer():ByteBuffer
base64 Returns this byte string encoded as Base64. In violation of the RFC, the returned string does not wrap lines at 76 columns.(js, jvm) fun base64():String
(native) open fun base64():String
base64Url Returns this byte string encoded as URL-safe Base64.(js, jvm) fun base64Url():String
(native) open fun base64Url():String
compareTo (js, jvm) open fun compareTo(other:ByteString):Int
(native) open fun compareTo(other:ByteString): <ERROR CLASS>
endsWith (js, jvm) fun endsWith(suffix:ByteString):Boolean
(native) fun endsWith(suffix:ByteString): <ERROR CLASS>
(js, jvm) fun endsWith(suffix:ByteArray):Boolean
(native) fun endsWith(suffix:ByteArray): <ERROR CLASS>
equals (js, jvm) open fun equals(other:Any?):Boolean
(native) open fun equals(other:Any?): <ERROR CLASS>
(js, jvm, native) get Returns the byte at index.operator fun get(index:Int):Byte
(jvm) getByte fun ~~getByte~~(index:Int):Byte
hashCode (js, jvm) open fun hashCode():Int
(native) open fun hashCode(): <ERROR CLASS>
hex Returns this byte string encoded in hexadecimal.(js, jvm) fun hex():String
(native) open fun hex():String
(jvm) hmacSha1 Returns the 160-bit SHA-1 HMAC of this byte string.open fun hmacSha1(key:ByteString):ByteString
(jvm) hmacSha256 Returns the 256-bit SHA-256 HMAC of this byte string.open fun hmacSha256(key:ByteString):ByteString
(jvm) hmacSha512 Returns the 512-bit SHA-512 HMAC of this byte string.open fun hmacSha512(key:ByteString):ByteString
indexOf (js, jvm) fun indexOf(other:ByteString, fromIndex:Int= 0):Int
(native) fun indexOf(other:ByteString, fromIndex:Int): <ERROR CLASS>
(js, jvm) fun indexOf(other:ByteArray, fromIndex:Int= 0):Int
(native) open fun indexOf(other:ByteArray, fromIndex:Int): <ERROR CLASS>
lastIndexOf (js, jvm) fun lastIndexOf(other:ByteString, fromIndex:Int= size):Int
(native) fun lastIndexOf(other:ByteString, fromIndex:Int): <ERROR CLASS>
(js, jvm) fun lastIndexOf(other:ByteArray, fromIndex:Int= size):Int
(native) open fun lastIndexOf(other:ByteArray, fromIndex:Int): <ERROR CLASS>
(jvm) md5 Returns the 128-bit MD5 hash of this byte string.open fun md5():ByteString
rangeEquals Returns true if the bytes of this in [offset..offset+byteCount) equal the bytes of other in [otherOffset..otherOffset+byteCount). Returns false if either range is out of bounds.(js, jvm) fun rangeEquals(offset:Int, other:ByteString, otherOffset:Int, byteCount:Int):Boolean
(native) open fun rangeEquals(offset:Int, other:ByteString, otherOffset:Int, byteCount:Int):Boolean
(js, jvm) fun rangeEquals(offset:Int, other:ByteArray, otherOffset:Int, byteCount:Int):Boolean
(native) open fun rangeEquals(offset:Int, other:ByteArray, otherOffset:Int, byteCount:Int):Boolean
(jvm) sha1 Returns the 160-bit SHA-1 hash of this byte string.open fun sha1():ByteString
(jvm) sha256 Returns the 256-bit SHA-256 hash of this byte string.open fun sha256():ByteString
(jvm) sha512 Returns the 512-bit SHA-512 hash of this byte string.open fun sha512():ByteString
(jvm) size fun ~~size~~():Int
startsWith (js, jvm) fun startsWith(prefix:ByteString):Boolean
(native) fun startsWith(prefix:ByteString): <ERROR CLASS>
(js, jvm) fun startsWith(prefix:ByteArray):Boolean
(native) fun startsWith(prefix:ByteArray): <ERROR CLASS>
(jvm) string Constructs a new String by decoding the bytes using charset.open fun string(charset:Charset):String
substring Returns a byte string that is a substring of this byte string, beginning at the specified beginIndex and ends at the specified endIndex. Returns this byte string if beginIndex is 0 and endIndex is the length of this byte string.(js, jvm) fun substring(beginIndex:Int= 0, endIndex:Int= size):ByteString
(native) open fun substring(beginIndex:Int, endIndex:Int):ByteString
toAsciiLowercase Returns a byte string equal to this byte string, but with the bytes ‘A’ through ‘Z’ replaced with the corresponding byte in ‘a’ through ‘z’. Returns this byte string if it contains no bytes in ‘A’ through ‘Z’.(js, jvm) fun toAsciiLowercase():ByteString
(native) open fun toAsciiLowercase():ByteString
toAsciiUppercase Returns a byte string equal to this byte string, but with the bytes ‘a’ through ‘z’ replaced with the corresponding byte in ‘A’ through ‘Z’. Returns this byte string if it contains no bytes in ‘a’ through ‘z’.(js, jvm) fun toAsciiUppercase():ByteString
(native) open fun toAsciiUppercase():ByteString
toByteArray Returns a byte array containing a copy of the bytes in this ByteString.(js, jvm) fun toByteArray():ByteArray
(native) open fun toByteArray(): <ERROR CLASS>
toString Returns a human-readable string that describes the contents of this byte string. Typically this is a string like [text=Hello] or [hex=0000ffff].(js, jvm) open fun toString():String
(native) open fun toString(): <ERROR CLASS>
utf8 Constructs a new String by decoding the bytes as UTF-8.(js, jvm) fun utf8():String
(native) open fun utf8():String
(jvm) write Writes the contents of this byte string to out.open fun write(out:OutputStream):Unit

Companion Object Properties

Name Summary
(js, jvm, native) EMPTY A singleton empty ByteString.val EMPTY:ByteString

Companion Object Functions

Name Summary
(js, jvm, native) decodeBase64 Decodes the Base64-encoded bytes and returns their value as a byte string. Returns null if this is not a Base64-encoded sequence of bytes.funString.decodeBase64():ByteString?
decodeHex Decodes the hex-encoded bytes and returns their value a byte string.(js, jvm) funString.decodeHex():ByteString
(native) funString.decodeHex(): <ERROR CLASS>
(jvm) encode Returns a new ByteString containing the charset-encoded bytes of this String.funString.encode(charset:Charset= Charsets.UTF_8):ByteString
(jvm) encodeString fun ~~encodeString~~(string:String, charset:Charset):ByteString
(js, jvm, native) encodeUtf8 Returns a new byte string containing the UTF-8 bytes of this String.funString.encodeUtf8():ByteString
of (jvm) fun ~~of~~(buffer:ByteBuffer):ByteString
(jvm) fun ~~of~~(array:ByteArray, offset:Int, byteCount:Int):ByteString
Returns a new byte string containing a clone of the bytes of data.(js, jvm) fun of(vararg data:Byte):ByteString
(native) fun of(vararg data:Byte): <ERROR CLASS>
(jvm) read fun ~~read~~(inputstream:InputStream, byteCount:Int):ByteString
(jvm) readByteString Reads count bytes from this InputStream and returns the result.funInputStream.readByteString(byteCount:Int):ByteString
toByteString Returns a ByteString containing a copy of this ByteBuffer.(jvm) funByteBuffer.toByteString():ByteString
Returns a new ByteString containing a copy of byteCount bytes of this ByteArray starting at offset.(js, jvm) funByteArray.toByteString(offset:Int= 0, byteCount:Int= size):ByteString
(native) funByteArray.toByteString(offset:Int, byteCount:Int):ByteString