kotlinx-io-bytestring
The module provides the ByteString - an immutable sequence of bytes, and extensions facilitating work with it.
The module provides the ByteString - an immutable sequence of bytes, and extensions facilitating work with it.
The module provides the ByteString - an immutable sequence of bytes, and extensions facilitating work with it.
The module provides the ByteString - an immutable sequence of bytes, and extensions facilitating work with it.
The module provides the ByteString - an immutable sequence of bytes, and extensions facilitating work with it.
Packages
-ByteString
Wraps given bytes into a byte string.
Parameters
a sequence of bytes to be wrapped.
Samples
import kotlinx.io.bytestring.*
+ Wraps given bytes into a byte string.
Parameters
bytesa sequence of bytes to be wrapped.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -76,7 +76,16 @@ ByteString
assertFalse(byteStringFromBytes.isEmpty())
assertEquals(3, byteStringFromBytes.size)
//sampleEnd
-}
+}
Wraps given bytes into a byte string.
Internally, bytes will be stored as ByteArray, and accesses to individual ByteString's bytes will return a signed Byte as if someone call bytes[i].toByte()
.
Parameters
a sequence of bytes to be wrapped.
Samples
import kotlinx.io.bytestring.*
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val byteStringFromBytes = ByteString(0xCAu, 0xFEu)
+assertFalse(byteStringFromBytes.isEmpty())
+assertEquals(2, byteStringFromBytes.size)
+ //sampleEnd
+}
ByteString
Wraps a copy of data subarray starting at startIndex and ending at endIndex into a byte string.
Parameters
the array whose subarray should be copied and wrapped into a byte string.
the start index (inclusive) of a subarray to copy, 0
by default.
the end index (exclusive) of a subarray to copy, data.size
be default.
Throws
when startIndex or endIndex is out of range of data array indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
+ Wraps a copy of data subarray starting at startIndex and ending at endIndex into a byte string.
Parameters
datathe array whose subarray should be copied and wrapped into a byte string.
startIndex the start index (inclusive) of a subarray to copy, 0
by default.
endIndex the end index (exclusive) of a subarray to copy, data.size
be default.
Throws
when startIndex or endIndex is out of range of data array indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/-companion/index.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/-companion/index.html
index 769cf99f..897eb4e3 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/-companion/index.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/-companion/index.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -62,7 +62,7 @@
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/compare-to.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/compare-to.html
index 70593e15..a750addd 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/compare-to.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/compare-to.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
compareTo
- Compares a byte sequence wrapped by this byte string to a byte sequence wrapped by other in lexicographical order. Byte values are compared as unsigned integers.
The behavior is similar to String.compareTo.
Parameters
otherthe byte string to compare this string to.
Samples
import kotlinx.io.bytestring.*
+ Compares a byte sequence wrapped by this byte string to a byte sequence wrapped by other in lexicographical order. Byte values are compared as unsigned integers.
The behavior is similar to String.compareTo.
Parameters
otherthe byte string to compare this string to.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/copy-into.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/copy-into.html
index 4641ea39..16bb7c62 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/copy-into.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/copy-into.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
copyInto
- fun copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size)(source)Copies a subsequence starting at startIndex and ending at endIndex of a byte sequence wrapped by this byte string and writes it into destination array starting at destinationOffset offset.
Parameters
destinationthe array to copy data into.
destinationOffset the offset starting from which data copy should be written to destination.
startIndex the start index (inclusive) of a subsequence to copy, 0
by default.
endIndex the end index (exclusive) of a subsequence to copy, size be default.
Throws
when the subrange doesn't fit into the destination array starting at the specified destinationOffset, or when that index is out of the destination array indices range.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
+ fun copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size)(source)Copies a subsequence starting at startIndex and ending at endIndex of a byte sequence wrapped by this byte string and writes it into destination array starting at destinationOffset offset.
Parameters
destinationthe array to copy data into.
destinationOffset the offset starting from which data copy should be written to destination.
startIndex the start index (inclusive) of a subsequence to copy, 0
by default.
endIndex the end index (exclusive) of a subsequence to copy, size be default.
Throws
when the subrange doesn't fit into the destination array starting at the specified destinationOffset, or when that index is out of the destination array indices range.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/equals.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/equals.html
index 4c5e9a76..6d7e8091 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/equals.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/equals.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
equals
-
+
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
get
-
+
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
hashCode
-
+
- 0.5.3
+ 0.5.4
+
@@ -63,7 +64,7 @@
ByteString
- An immutable wrapper around a byte sequence providing String like functionality.
ByteString allows treating binary data as a value and passing it to other functions without worrying about data modification. The class facilitates various operations on binary data, like comparison or testing for subsequence inclusion.
ByteString is a good fit for untyped binary data that could not be represented as String, like hashes, payload of network packets, encrypted data, etc.
ByteString copies data on creation as well as on conversion back to ByteArray, thus guaranteeing that subsequent modification of source data or data returned from toByteArray won't mutate the string itself.
+ An immutable wrapper around a byte sequence providing String like functionality.
ByteString allows treating binary data as a value and passing it to other functions without worrying about data modification. The class facilitates various operations on binary data, like comparison or testing for subsequence inclusion.
ByteString is a good fit for untyped binary data that could not be represented as String, like hashes, payload of network packets, encrypted data, etc.
ByteString copies data on creation as well as on conversion back to ByteArray, thus guaranteeing that subsequent modification of source data or data returned from toByteArray won't mutate the string itself.
@@ -142,7 +143,24 @@ Properties
Functions
-
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+Returns a new read-only heap ByteBuffer wrapping this ByteString's content.
+
+
+
+
+
@@ -384,6 +402,23 @@ Functions
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+Returns a new NSData instance initialized with bytes copied from this ByteString.
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/size.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/size.html
index ea229c12..d6165692 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/size.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/size.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
size
-
+
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
substring
- Returns a new byte string wrapping a subsequence of bytes wrapped by this byte string starting from startIndex and ending at endIndex.
Parameters
startIndex the start index (inclusive) of a subsequence to copy.
endIndex the end index (exclusive) of a subsequence to copy, size be default.
Throws
when startIndex or endIndex is out of range of byte string indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
+ Returns a new byte string wrapping a subsequence of bytes wrapped by this byte string starting from startIndex and ending at endIndex.
Parameters
startIndex the start index (inclusive) of a subsequence to copy.
endIndex the end index (exclusive) of a subsequence to copy, size be default.
Throws
when startIndex or endIndex is out of range of byte string indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-byte-array.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-byte-array.html
index 346b20be..d57e56ab 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-byte-array.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-byte-array.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
toByteArray
- Returns a copy of subsequence starting at startIndex and ending at endIndex of a byte sequence wrapped by this byte string.
Parameters
startIndex the start index (inclusive) of a subsequence to copy, 0
by default.
endIndex the end index (exclusive) of a subsequence to copy, size be default.
Throws
when startIndex or endIndex is out of range of byte string indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
+ Returns a copy of subsequence starting at startIndex and ending at endIndex of a byte sequence wrapped by this byte string.
Parameters
startIndex the start index (inclusive) of a subsequence to copy, 0
by default.
endIndex the end index (exclusive) of a subsequence to copy, size be default.
Throws
when startIndex or endIndex is out of range of byte string indices.
when startIndex > endIndex
.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-string.html
index 0076afb7..12d1863f 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/-byte-string/to-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
toString
- Returns a string representation of this byte string. A string representation consists of size and a hexadecimal-encoded string of a byte sequence wrapped by this byte string.
The string representation has the following format ByteString(size=3 hex=ABCDEF)
, for empty strings it's always ByteString(size=0)
.
Note that a string representation includes the whole byte string content encoded. Due to limitations exposed for the maximum string length, an attempt to return a string representation of too long byte string may fail.
Samples
import kotlinx.io.bytestring.*
+ Returns a string representation of this byte string. A string representation consists of size and a hexadecimal-encoded string of a byte sequence wrapped by this byte string.
The string representation has the following format ByteString(size=3 hex=ABCDEF)
, for empty strings it's always ByteString(size=0)
.
Note that a string representation includes the whole byte string content encoded. Due to limitations exposed for the maximum string length, an attempt to return a string representation of too long byte string may fail.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/append.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/append.html
index 73e38779..591ae09d 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/append.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/append.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/as-read-only-byte-buffer.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/as-read-only-byte-buffer.html
new file mode 100644
index 00000000..ae8d5483
--- /dev/null
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/as-read-only-byte-buffer.html
@@ -0,0 +1,94 @@
+
+
+
+
+ asReadOnlyByteBuffer
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ asReadOnlyByteBuffer
+
+
+
+Returns a new read-only heap ByteBuffer wrapping this ByteString's content.
Samples
import kotlinx.io.bytestring.*
+import java.nio.ByteBuffer
+import java.nio.ReadOnlyBufferException
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val str = "Hello World".encodeToByteString()
+val buffer = str.asReadOnlyByteBuffer()
+
+assertEquals(11, buffer.remaining())
+assertEquals(0x48656c6c, buffer.getInt())
+
+buffer.flip()
+assertFailsWith<ReadOnlyBufferException> { buffer.put(42) }
+ //sampleEnd
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/build-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/build-byte-string.html
index 774c8f9d..dbc1a119 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/build-byte-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/build-byte-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/content-equals.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/content-equals.html
index de10a7b4..e7157ed0 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/content-equals.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/content-equals.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
contentEquals
- Returns true
if the content of this byte string equals to the array.
Parameters
arraythe array to test this byte string's content against.
+ Returns true
if the content of this byte string equals to the array.
Parameters
arraythe array to test this byte string's content against.
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-byte-string.html
index 2ff3098d..b9d4b063 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-byte-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-byte-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-string.html
index 31d2154d..d171d61e 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/decode-to-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -66,7 +66,7 @@ decodeToString
-Decodes content of a byte string into a string using UTF-8 encoding.
Samples
import kotlinx.io.bytestring.*
+Decodes content of a byte string into a string using UTF-8 encoding.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -83,7 +83,7 @@ decodeToString
)
assertEquals("hello", helloAsByteString.decodeToString())
//sampleEnd
-}
Decodes the content of a byte string to a string using given charset.
Parameters
charsetthe charset to decode data into a string.
+}Decodes the content of a byte string to a string using given charset.
Parameters
charsetthe charset to decode data into a string.
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-into-byte-array.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-into-byte-array.html
index a5d49be7..0f23418b 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-into-byte-array.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-into-byte-array.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-appendable.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-appendable.html
index ac27a918..f020aadf 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-appendable.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-appendable.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-array.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-array.html
index 3a906478..cf7730ec 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-array.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-array.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-string.html
index 3a8ed917..e5a044e7 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/encode-to-byte-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -66,7 +66,7 @@ encodeToByte<
-Encodes a string into a byte sequence using UTF8-encoding and wraps it into a byte string.
Samples
import kotlinx.io.bytestring.*
+Encodes a string into a byte sequence using UTF8-encoding and wraps it into a byte string.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -83,7 +83,7 @@ encodeToByte<
)
assertEquals("hello", helloAsByteString.decodeToString())
//sampleEnd
-}
+}
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/ends-with.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/ends-with.html
index 9004d277..483173dc 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/ends-with.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/ends-with.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
endsWith
- Returns true if this byte string ends with the suffix specified by the byteArray.
Behavior of this method is compatible with CharSequence.endsWith.
Parameters
byteArray the suffix to check for.
Samples
import kotlinx.io.bytestring.*
+ Returns true if this byte string ends with the suffix specified by the byteArray.
Behavior of this method is compatible with CharSequence.endsWith.
Parameters
byteArray the suffix to check for.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -76,7 +76,7 @@ endsWith
assertFalse(string.endsWith(byteArrayOf(2, 4, 5)))
assertFalse(string.endsWith(byteArrayOf(0, 1, 2, 3, 4, 5)))
//sampleEnd
-}
Returns true if this byte string ends with the suffix specified by the byteString.
Behavior of this method is compatible with CharSequence.endsWith.
Parameters
byteString the suffix to check for.
Samples
import kotlinx.io.bytestring.*
+}
Returns true if this byte string ends with the suffix specified by the byteString.
Behavior of this method is compatible with CharSequence.endsWith.
Parameters
byteString the suffix to check for.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/get-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/get-byte-string.html
new file mode 100644
index 00000000..98fb6d33
--- /dev/null
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/get-byte-string.html
@@ -0,0 +1,112 @@
+
+
+
+
+ getByteString
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ getByteString
+
+
+
+Reads length bytes of data from this ByteBuffer starting from the current position and wraps them into a new ByteString.
Upon successful execution, current position will advance by length.
Throws
when length has negative value or its value exceeds ByteBuffer.remaining
Samples
import kotlinx.io.bytestring.*
+import java.nio.ByteBuffer
+import java.nio.ReadOnlyBufferException
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val buffer = ByteBuffer.wrap("Hello World".encodeToByteArray())
+
+// Consume the whole buffer
+val byteString = buffer.getByteString()
+assertEquals(0, buffer.remaining())
+assertEquals("Hello World".encodeToByteString(), byteString)
+
+// Reset the buffer
+buffer.flip()
+// Consume only first 5 bytes from the buffer
+assertEquals("Hello".encodeToByteString(), buffer.getByteString(length = 5))
+ //sampleEnd
+}
Reads length bytes of data from this ByteBuffer starting from at index and wraps them into a new ByteString.
This function does not update ByteBuffer.position.
Throws
when at is negative, greater or equal to ByteBuffer.limit or at + length exceeds ByteBuffer.limit.
Samples
import kotlinx.io.bytestring.*
+import java.nio.ByteBuffer
+import java.nio.ReadOnlyBufferException
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val buffer = ByteBuffer.wrap("Hello World".encodeToByteArray())
+
+// Read 2 bytes starting from offset 6
+val byteString = buffer.getByteString(at = 6, length = 2)
+// Buffer's position is not affected
+assertEquals(11, buffer.remaining())
+assertEquals(byteString, "Wo".encodeToByteString())
+ //sampleEnd
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/hex-to-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/hex-to-byte-string.html
index 49556a78..8ffbdd45 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/hex-to-byte-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/hex-to-byte-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index-of.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index-of.html
index 672d7c26..fa8b9117 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index-of.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index-of.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
indexOf
- Returns the index within this byte string of the first occurrence of the specified byte, starting from the specified startIndex. If the byte not found, -1
is returned.
Behavior of this method is compatible with CharSequence.indexOf.
Parameters
bytethe value to search for.
startIndex the index (inclusive) starting from which the byte should be searched.
Samples
import kotlinx.io.bytestring.*
+ Returns the index within this byte string of the first occurrence of the specified byte, starting from the specified startIndex. If the byte not found, -1
is returned.
Behavior of this method is compatible with CharSequence.indexOf.
Parameters
bytethe value to search for.
startIndex the index (inclusive) starting from which the byte should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -74,7 +74,7 @@ indexOf
assertEquals(3, string.indexOf(2, startIndex = 2))
assertEquals(-1, string.indexOf(0))
//sampleEnd
-}
Returns the index within this byte string of the first occurrence of the specified byteString, starting from the specified startIndex. If the byteString not found, -1
is returned.
Behavior of this method is compatible with CharSequence.indexOf.
Parameters
byteString the value to search for.
startIndex the index (inclusive) starting from which the byteString should be searched.
Samples
import kotlinx.io.bytestring.*
+}
Returns the index within this byte string of the first occurrence of the specified byteString, starting from the specified startIndex. If the byteString not found, -1
is returned.
Behavior of this method is compatible with CharSequence.indexOf.
Parameters
byteString the value to search for.
startIndex the index (inclusive) starting from which the byteString should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -87,7 +87,7 @@ indexOf
assertEquals(-1, string.indexOf(ByteString(1, 3, 4, 5)))
assertEquals(0, string.indexOf(ByteString(/* empty byte string */)))
//sampleEnd
-}
Returns the index within this byte string of the first occurrence of the specified byteArray, starting from the specified startIndex. If the byteArray not found, -1
is returned.
Behavior of this method is compatible with CharSequence.indexOf.
Parameters
byteArray the value to search for.
startIndex the index (inclusive) starting from which the byteArray should be searched.
Samples
import kotlinx.io.bytestring.*
+}
Returns the index within this byte string of the first occurrence of the specified byteArray, starting from the specified startIndex. If the byteArray not found, -1
is returned.
Behavior of this method is compatible with CharSequence.indexOf.
Parameters
byteArray the value to search for.
startIndex the index (inclusive) starting from which the byteArray should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index.html
index 0ff872ff..3cf4d997 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/index.html
@@ -41,10 +41,11 @@
kotlinx-io
- 0.5.3
+ 0.5.4
+
@@ -59,7 +60,7 @@
-
+
Package-level declarations
@@ -137,6 +138,23 @@ Functions
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+Returns a new read-only heap ByteBuffer wrapping this ByteString's content.
+
+
+
+
@@ -152,17 +170,17 @@ Functions
-
+
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+Reads length bytes of data from this ByteBuffer starting from the current position and wraps them into a new ByteString.
Reads length bytes of data from this ByteBuffer starting from at index and wraps them into a new ByteString.
+
+
+
+
@@ -411,6 +446,23 @@ Functions
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+
+
+
+
+
@@ -426,6 +478,23 @@ Functions
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+Returns a new ByteString holding data copied from this NSData.
+
+
+
+
@@ -441,6 +510,23 @@ Functions
+
+
+
+
+
+
+ Link copied to clipboard
+
+
+
+
+
+Returns a new NSData instance initialized with bytes copied from this ByteString.
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/indices.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/indices.html
index c8b1092b..9e783c3d 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/indices.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/indices.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
indices
- Returns the range of valid byte indices for this byte string.
+ Returns the range of valid byte indices for this byte string.
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
isEmpty
- Returns true
if this byte string is empty.
+ Returns true
if this byte string is empty.
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
isNotEmpty
- Returns true
if this byte string is not empty.
+ Returns true
if this byte string is not empty.
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
lastIndexOf
- Returns the index within this char sequence of the last occurrence of the specified byte, starting from the specified startIndex. If the byte not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
bytethe value to search for.
startIndex the index (inclusive) starting from which the byte should be searched.
Samples
import kotlinx.io.bytestring.*
+ Returns the index within this char sequence of the last occurrence of the specified byte, starting from the specified startIndex. If the byte not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
bytethe value to search for.
startIndex the index (inclusive) starting from which the byte should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -74,7 +74,7 @@ lastIndexOf
Returns the index within this char sequence of the last occurrence of the specified byteString, starting from the specified startIndex. If the byteString not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
byteString the value to search for.
startIndex the index (inclusive) starting from which the byteString should be searched.
Samples
import kotlinx.io.bytestring.*
+}
Returns the index within this char sequence of the last occurrence of the specified byteString, starting from the specified startIndex. If the byteString not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
byteString the value to search for.
startIndex the index (inclusive) starting from which the byteString should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -87,7 +87,7 @@ lastIndexOf
Returns the index within this char sequence of the last occurrence of the specified byteArray, starting from the specified startIndex. If the byteArray not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
byteArray the value to search for.
startIndex the index (inclusive) starting from which the byteArray should be searched.
Samples
import kotlinx.io.bytestring.*
+}
Returns the index within this char sequence of the last occurrence of the specified byteArray, starting from the specified startIndex. If the byteArray not found, -1
is returned.
Behavior of this method is compatible with CharSequence.lastIndexOf.
Parameters
byteArray the value to search for.
startIndex the index (inclusive) starting from which the byteArray should be searched.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/put-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/put-byte-string.html
new file mode 100644
index 00000000..e4901ea0
--- /dev/null
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/put-byte-string.html
@@ -0,0 +1,113 @@
+
+
+
+
+ putByteString
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ putByteString
+
+
+
+Writes string into this ByteBuffer starting from the current position.
Upon successfully execution ByteBuffer.position will advance by the length of string.
Throws
Samples
import kotlinx.io.bytestring.*
+import java.nio.ByteBuffer
+import java.nio.ReadOnlyBufferException
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val buffer = ByteBuffer.allocate(32)
+val byteString = ByteString(0x66, 0xdb.toByte(), 0x11, 0x50)
+
+// Putting a ByteString into a buffer will advance its position
+buffer.putByteString(byteString)
+assertEquals(4, buffer.position())
+
+buffer.flip()
+assertEquals(1725632848, buffer.getInt())
+ //sampleEnd
+}
Writes string into this ByteBuffer starting from position at.
This function does not update ByteBuffer.position.
Throws
when this buffer is read-only
when at is negative, exceeds ByteBuffer.limit, or at + ByteString.size exceeds ByteBuffer.limit
Samples
import kotlinx.io.bytestring.*
+import java.nio.ByteBuffer
+import java.nio.ReadOnlyBufferException
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val buffer = ByteBuffer.allocate(8)
+val byteString = ByteString(0x78, 0x5e)
+
+// Putting a ByteString into a buffer using an absolute offset
+// won't change buffer's position.
+buffer.putByteString(at = 3, string = byteString)
+assertEquals(0, buffer.position())
+assertEquals(8, buffer.remaining())
+
+assertEquals(0x000000785e000000L, buffer.getLong())
+ //sampleEnd
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/starts-with.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/starts-with.html
index e93148b0..30effebb 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/starts-with.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/starts-with.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
@@ -63,7 +63,7 @@
startsWith
- Returns true if this byte string starts with the prefix specified by the byteArray.
Behavior of this method is compatible with CharSequence.startsWith.
Parameters
byteArray the prefix to check for.
Samples
import kotlinx.io.bytestring.*
+ Returns true if this byte string starts with the prefix specified by the byteArray.
Behavior of this method is compatible with CharSequence.startsWith.
Parameters
byteArray the prefix to check for.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
@@ -76,7 +76,7 @@ startsWith
assertFalse(string.startsWith(byteArrayOf(1, 3, 4)))
assertFalse(string.startsWith(byteArrayOf(1, 2, 3, 4, 5, 6)))
//sampleEnd
-}
Returns true if this byte string starts with the prefix specified by the byteString.
Behavior of this method is compatible with CharSequence.startsWith.
Parameters
byteString the prefix to check for.
Samples
import kotlinx.io.bytestring.*
+}
Returns true if this byte string starts with the prefix specified by the byteString.
Behavior of this method is compatible with CharSequence.startsWith.
Parameters
byteString the prefix to check for.
Samples
import kotlinx.io.bytestring.*
import kotlin.test.*
fun main() {
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-byte-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-byte-string.html
new file mode 100644
index 00000000..11f44b9d
--- /dev/null
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-byte-string.html
@@ -0,0 +1,98 @@
+
+
+
+
+ toByteString
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ toByteString
+
+
+
+Returns a new ByteString holding data copied from this NSData.
Samples
import kotlinx.cinterop.ExperimentalForeignApi
+import kotlinx.cinterop.UnsafeNumber
+import kotlinx.io.bytestring.*
+import platform.Foundation.*
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val originalByteString: ByteString = "Compress me, please!".encodeToByteString()
+
+val compressedNSData: NSData = originalByteString.toNSData().compressedDataUsingAlgorithm(
+ algorithm = NSDataCompressionAlgorithmZlib,
+ error = null
+)!!
+
+val compressedByteString: ByteString = compressedNSData.toByteString()
+assertEquals("73cecf2d284a2d2e56c84dd55128c8494d2c4e550400", compressedByteString.toHexString())
+// If there's no zlib-flate on your path, you can test it using:
+// zlib.decompress(binascii.unhexlify("73cecf2d284a2d2e56c84dd55128c8494d2c4e550400"), -15)
+ //sampleEnd
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-hex-string.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-hex-string.html
index 1c14dc02..e4c2be44 100644
--- a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-hex-string.html
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-hex-string.html
@@ -41,7 +41,7 @@
kotlinx-io
- 0.5.3
+ 0.5.4
diff --git a/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-n-s-data.html b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-n-s-data.html
new file mode 100644
index 00000000..eaac2c98
--- /dev/null
+++ b/docs/kotlinx-io-bytestring/kotlinx.io.bytestring/to-n-s-data.html
@@ -0,0 +1,98 @@
+
+
+
+
+ toNSData
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ toNSData
+
+
+
+Returns a new NSData instance initialized with bytes copied from this ByteString.
Samples
import kotlinx.cinterop.ExperimentalForeignApi
+import kotlinx.cinterop.UnsafeNumber
+import kotlinx.io.bytestring.*
+import platform.Foundation.*
+import kotlin.test.*
+
+fun main() {
+ //sampleStart
+ val originalByteString: ByteString = "Compress me, please!".encodeToByteString()
+
+val compressedNSData: NSData = originalByteString.toNSData().compressedDataUsingAlgorithm(
+ algorithm = NSDataCompressionAlgorithmZlib,
+ error = null
+)!!
+
+val compressedByteString: ByteString = compressedNSData.toByteString()
+assertEquals("73cecf2d284a2d2e56c84dd55128c8494d2c4e550400", compressedByteString.toHexString())
+// If there's no zlib-flate on your path, you can test it using:
+// zlib.decompress(binascii.unhexlify("73cecf2d284a2d2e56c84dd55128c8494d2c4e550400"), -15)
+ //sampleEnd
+}
+
+
+
+
+
+
+
+
+
+
diff --git a/docs/kotlinx-io-bytestring/navigation.html b/docs/kotlinx-io-bytestring/navigation.html
index ccb42c9d..5ad33a39 100644
--- a/docs/kotlinx-io-bytestring/navigation.html
+++ b/docs/kotlinx-io-bytestring/navigation.html
@@ -1,9 +1,9 @@
-