API: bytes
Source:
io/bytes.ts
Provides utilities for converting and manipulating byte arrays, facilitating conversions between JavaScript arrays, Java arrays, text, and integers.
Usage
import { bytes } from "sdk/io"
console.log(bytes.textToByteArray("Hello World"));
console.log(bytes.byteArrayToText([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]));Classes
Bytes
The Bytes class provides static methods for byte array operations, primarily
used to bridge data types between the JavaScript environment and native Java components.
Methods
toJavaBytes
toJavaBytes (bytes:any[]):any[]Converts a native JavaScript byte array (an array of numbers) to a Java byte array.
This is used internally by the API layer to pass data to Java methods.
@param bytes The JavaScript array of bytes (e.g., [104, 101, 108, 108, 111]).
@returns A native Java byte array (internal representation).
toJavaScriptBytes
toJavaScriptBytes (internalBytes:any[]):any[]Converts a native Java byte array back to a JavaScript array of numbers.
This is used internally by the API layer to retrieve data from Java methods.
@param internalBytes The native Java byte array.
@returns A JavaScript array containing the byte values (numbers).
textToByteArray
textToByteArray (text:string):any[]Converts a standard text string into a byte array using the default platform encoding.
@param text The input text string.
@returns A JavaScript array representing the bytes of the text.
byteArrayToText
byteArrayToText (data:any[]):stringConverts a byte array back into a text string.
@param data The JavaScript array of bytes.
@returns The reconstructed text string.
intToByteArray
intToByteArray (value:number, byteOrder:"BIG_ENDIAN"|"LITTLE_ENDIAN"):any[]Converts a 32-bit integer value into a byte array, respecting the specified byte order.
@param value The integer value to convert.
@param byteOrder Specifies the byte ordering: "BIG_ENDIAN" (most significant byte first) or "LITTLE_ENDIAN" (least significant byte first).
@returns A JavaScript array representing the 4-byte integer.
byteArrayToInt
byteArrayToInt (data:any[], byteOrder:"BIG_ENDIAN"|"LITTLE_ENDIAN"):numberConverts a 4-byte array back into a 32-bit integer value, respecting the specified byte order.
@param data The 4-byte array (JavaScript array of numbers).
@param byteOrder Specifies the byte ordering used during conversion.
@returns The reconstructed integer value.