ByteString

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.

open class ByteString : Serializable, Comparable<ByteString>

Types

Companion
Link copied to clipboard
common
object Companion

Functions

asByteBuffer
Link copied to clipboard
open fun asByteBuffer(): ByteBuffer
Returns a ByteBuffer view of the bytes in this ByteString.
base64
Link copied to clipboard
common
fun base64(): String
Returns this byte string encoded as Base64.
open fun base64(): String
base64Url
Link copied to clipboard
common
fun base64Url(): String
Returns this byte string encoded as URL-safe Base64.
open fun base64Url(): String
compareTo
Link copied to clipboard
common
open operator override fun compareTo(other: ByteString): Int
endsWith
Link copied to clipboard
common
fun endsWith(suffix: ByteArray): Boolean
fun endsWith(suffix: ByteString): Boolean
equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
get
Link copied to clipboard
common
@JvmName(name = "getByte")
operator fun get(index: Int): Byte
Returns the byte at index.
@JvmName(name = "getByte")
operator fun get(index: Int): Byte
hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
hex
Link copied to clipboard
common
fun hex(): String
Returns this byte string encoded in hexadecimal.
open fun hex(): String
hmacSha1
Link copied to clipboard
common
fun hmacSha1(key: ByteString): ByteString
Returns the 160-bit SHA-1 HMAC of this byte string.
open fun hmacSha1(key: ByteString): ByteString
Returns the 160-bit SHA-1 HMAC of this byte string.
hmacSha256
Link copied to clipboard
common
fun hmacSha256(key: ByteString): ByteString
Returns the 256-bit SHA-256 HMAC of this byte string.
open fun hmacSha256(key: ByteString): ByteString
Returns the 256-bit SHA-256 HMAC of this byte string.
hmacSha512
Link copied to clipboard
common
fun hmacSha512(key: ByteString): ByteString
Returns the 512-bit SHA-512 HMAC of this byte string.
open fun hmacSha512(key: ByteString): ByteString
Returns the 512-bit SHA-512 HMAC of this byte string.
indexOf
Link copied to clipboard
fun indexOf(other: ByteArray, fromIndex: Int = 0): Int
fun indexOf(other: ByteString, fromIndex: Int = 0): Int
open fun indexOf(other: ByteArray, fromIndex: Int = 0): Int
fun indexOf(other: ByteString, fromIndex: Int = 0): Int
lastIndexOf
Link copied to clipboard
fun lastIndexOf(other: ByteArray, fromIndex: Int = DEFAULT__ByteString_size): Int
fun lastIndexOf(other: ByteString, fromIndex: Int = DEFAULT__ByteString_size): Int
open fun lastIndexOf(other: ByteArray, fromIndex: Int = DEFAULT__ByteString_size): Int
fun lastIndexOf(other: ByteString, fromIndex: Int = DEFAULT__ByteString_size): Int
md5
Link copied to clipboard
common
fun md5(): ByteString
Returns the 128-bit MD5 hash of this byte string.
fun md5(): ByteString
rangeEquals
Link copied to clipboard
common
fun rangeEquals(offset: Int, other: ByteArray, otherOffset: Int, byteCount: Int): Boolean
Returns true if the bytes of this in [offset..offset+byteCount) equal the bytes of other in [otherOffset..otherOffset+byteCount).
open fun rangeEquals(offset: Int, other: ByteArray, otherOffset: Int, byteCount: Int): Boolean
common
fun rangeEquals(offset: Int, other: ByteString, otherOffset: Int, byteCount: Int): Boolean
Returns true if the bytes of this in [offset..offset+byteCount) equal the bytes of other in [otherOffset..otherOffset+byteCount).
open fun rangeEquals(offset: Int, other: ByteString, otherOffset: Int, byteCount: Int): Boolean
sha1
Link copied to clipboard
common
fun sha1(): ByteString
Returns the 160-bit SHA-1 hash of this byte string.
fun sha1(): ByteString
sha256
Link copied to clipboard
common
fun sha256(): ByteString
Returns the 256-bit SHA-256 hash of this byte string.
fun sha256(): ByteString
sha512
Link copied to clipboard
common
fun sha512(): ByteString
Returns the 512-bit SHA-512 hash of this byte string.
fun sha512(): ByteString
startsWith
Link copied to clipboard
common
fun startsWith(prefix: ByteArray): Boolean
fun startsWith(prefix: ByteString): Boolean
string
Link copied to clipboard
open fun string(charset: Charset): String
Constructs a new String by decoding the bytes using charset.
substring
Link copied to clipboard
common
fun substring(beginIndex: Int = 0, endIndex: Int = DEFAULT__ByteString_size): ByteString
Returns a byte string that is a substring of this byte string, beginning at the specified beginIndex and ends at the specified endIndex.
open fun substring(beginIndex: Int = 0, endIndex: Int = DEFAULT__ByteString_size): ByteString
toAsciiLowercase
Link copied to clipboard
common
fun toAsciiLowercase(): ByteString
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'.
open fun toAsciiLowercase(): ByteString
toAsciiUppercase
Link copied to clipboard
common
fun toAsciiUppercase(): ByteString
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'.
open fun toAsciiUppercase(): ByteString
toByteArray
Link copied to clipboard
common
fun toByteArray(): ByteArray
Returns a byte array containing a copy of the bytes in this ByteString.
open fun toByteArray(): ByteArray
toString
Link copied to clipboard
common
open override fun toString(): String
Returns a human-readable string that describes the contents of this byte string.
open override fun toString(): String
utf8
Link copied to clipboard
common
fun utf8(): String
Constructs a new String by decoding the bytes as UTF-8.
open fun utf8(): String
write
Link copied to clipboard
open fun write(out: OutputStream)
Writes the contents of this byte string to out.

Properties

size
Link copied to clipboard
val size: Int
Returns the number of bytes in this ByteString.
val size: Int