com.myjavatools.lib
Class Bytes

java.lang.Object
  extended by com.myjavatools.lib.Bytes

public abstract class Bytes
extends java.lang.Object


Constructor Summary
Bytes()
           
 
Method Summary
static long crc32(byte[] data)
          Calculates crc32 on a byte array
static long crc32(byte[] data, int off, int len)
          Calculates crc32 on a byte array
static byte[] toBytes(char[] from)
          Converts char array to byte array (per-element casting)
static byte[] toBytes(long from)
          Converts long to byte array (lower bytes first)
static char[] toChars(byte[] from)
          Converts byte array to char array (per-element casting)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Bytes

public Bytes()
Method Detail

toBytes

public static final byte[] toBytes(char[] from)
Converts char array to byte array (per-element casting)

Parameters:
from - char array
Returns:
byte array

Example:
  • toBytes(new char[] {0x0123, 0x4567, 0x89ab, 0xcdef}) returns {0x23, 0x67, (byte)0xab, (byte)0xef}.

  • toChars

    public static final char[] toChars(byte[] from)
    Converts byte array to char array (per-element casting)

    Parameters:
    from - byte array
    Returns:
    char array

    Example:
  • toChars(new byte[] {0x23, 0x67, (byte)0xab, (byte)0xef}) returns new char[] {0x23, 0x67, 0xab, 0xef}.

  • crc32

    public static final long crc32(byte[] data)
    Calculates crc32 on a byte array

    Parameters:
    data - source bytes
    Returns:
    its crc32

    Example:
  • crc32(new byte[] {1, 2, 3}) returns 1438416925.

  • crc32

    public static final long crc32(byte[] data,
                                   int off,
                                   int len)
    Calculates crc32 on a byte array

    Parameters:
    data - source bytes
    off - offset in the array
    len - length of the area to crc
    Returns:
    its crc32

    Example:
  • crc32(new byte[] {0, 1, 2, 3, 4}, 1, 3) returns 1438416925.

  • toBytes

    public static final byte[] toBytes(long from)
    Converts long to byte array (lower bytes first)

    Parameters:
    from - the long value
    Returns:
    byte array

    Example:
  • toBytes(0x0123456789abcdefl) returns {(byte)0xef, (byte)0xcd, (byte)0xab, (byte)0x89, 0x67, 0x45, 0x23, 0x01}.