API: hex
Source:
utils/hex.ts
Utility class for performing Hexadecimal encoding and decoding of data. It handles conversion between JavaScript strings, JavaScript byte arrays (any[]), and the native Java byte arrays required by the underlying HexFacade.
Usage
import { hex } from "sdk/utils";
import { response } from "sdk/http";
response.println(hex.encode("Hex Encoded"));
response.println(hex.decode("48657820456e636f646564"));
response.flush();
response.close();Classes
Hex
Utility class for performing Hexadecimal encoding and decoding of data.
It handles conversion between JavaScript strings, JavaScript byte arrays (any[]),
and the native Java byte arrays required by the underlying HexFacade.
Methods
encode
encode (input:string|any[]):stringHexadecimal encoding: Converts the input data (text or byte array) into a
standard hexadecimal string representation.
@param input The data to encode, either as a string or a JavaScript byte array (any[]).
@returns The resulting hexadecimal string.
encodeAsBytes
encodeAsBytes (input:string|any[]):any[]Hexadecimal encoding: Converts the input data (text or byte array) into a
JavaScript byte array (any[]) containing the hexadecimal representation.
@param input The data to encode, either as a string or a JavaScript byte array (any[]).
@returns The resulting byte array containing the hexadecimal data.
encodeAsNativeBytes
encodeAsNativeBytes (input:string|any[]):any[]Hexadecimal encoding: Converts the input data (text or byte array) into a
native Java byte array containing the hexadecimal representation.
This method is generally for internal use.
@param input The data to encode, either as a string or a JavaScript byte array (any[]).
@returns The resulting native Java byte array.
decode
decode (input:string|any[]):any[]Hexadecimal decoding: Converts a hexadecimal input (text or byte array) back into
the original raw byte array (JavaScript any[]).
@param input The hexadecimal data to decode, either as a string or a JavaScript byte array (any[]).
@returns The decoded raw byte array (any[]). Returns null if decoding fails or input is null.
decodeAsNativeBytes
decodeAsNativeBytes (input:string|any[]):string|any[])Hexadecimal decoding: Converts a hexadecimal input (text or byte array) back into
the original native Java raw byte array. This method is generally for internal use.
@param input The hexadecimal data to decode, either as a string or a JavaScript byte array (any[]).
@returns The decoded native Java byte array.