Loading…

Kryptel/Java

Conversions class

Declaration

package com.kryptel.bslx;

public final class Conversions {

    public static void ToBytes(byte[] dest, int to, short[] src, int from, int len)

    public static void ToBytes(byte[] dest, int to, int[] src, int from, int len)

    public static void ToBytes(byte[] dest, int to, long[] src, int from, int len)

    public static void FromBytes(short[] dest, int to, byte[] src, int from, int len)

    public static void FromBytes(int[] dest, int to, byte[] src, int from, int len)

    public static void FromBytes(long[] dest, int to, byte[] src, int from, int len)


    public static byte[] UuidToBytes(UUID uuid)

    public static void UuidToBytes(byte[] dest, int start, UUID uuid)

    public static UUID UuidFromBytes(byte[] src, int start)


    public static short GetAsShort(byte[] src, int start)

    public static int GetAsInt(byte[] src, int start)

    public static long GetAsLong(byte[] src, int start)
}

Description

This class provides conversions to and from byte array missing in the standard Java library.

ToBytes / FromBytes

public static void ToBytes(byte[] dest, int to, short[] src, int from, int len)

public static void ToBytes(byte[] dest, int to, int[] src, int from, int len)

public static void ToBytes(byte[] dest, int to, long[] src, int from, int len)

public static void FromBytes(short[] dest, int to, byte[] src, int from, int len)

public static void FromBytes(int[] dest, int to, byte[] src, int from, int len)

public static void FromBytes(long[] dest, int to, byte[] src, int from, int len)

Functions in this group convert a short, int, or long array to an array of bytes and back. Note that position arguments to and from specify bytes, not elements. For example, if dest is array of ints, and to is 5, then the data will by stored starting from the second byte of the second array element,

UuidToBytes / UuidFromBytes

public static byte[] UuidToBytes(UUID uuid)

public static void UuidToBytes(byte[] dest, int start, UUID uuid)

public static UUID UuidFromBytes(byte[] src, int start)

UuidToBytes functions convert UUID to a 16-byte array; UuidFromBytes constructs UUID from sixteen bytes.

GetAs*

public static short GetAsShort(byte[] src, int start)

public static int GetAsInt(byte[] src, int start)

public static long GetAsLong(byte[] src, int start)

These functions are simplified forms of corresponding FromBytes functions, returning a single scalar value. They accept 2, 4, or 8 bytes and return short, int, or long, respectively.