JAPI 0.9.0
Yet another Java API
API Documentation

net.sf.japi.io
Class Nibbles

java.lang.Object
  extended by net.sf.japi.io.Nibbles

public final class Nibbles
extends Object

A class to get nibbles from byte sequences. This class works in sequentially numbered big endian (network byte) order, which means that the first nibble (0-nibble) is the high nibble of the first byte (high byte high nibble). You may also call this "high nibble first". The long value 0x0123456789ABCDEFl reflects the nibble indices in longs. Other datatypes work similarly: The int value 0x01234567 reflects the nibble indices in ints.

Binary nibbles are returned as ints because the general contract of I/O-methods as in package java.io is to expect and return single bytes being stored in ints and it saves neither space nor performance to return bytes instead of ints.

When needing chars, you should invoke those methods returning chars directly (single method invocation) instead of first getting the nibble and then converting it to a char (two method invocations) because inlining compilers will give you a better performance then.

Everything in this class is final for performance reasons: Final methods can be sort of inlined by some compilers.

Author:
Christian Hujer

Method Summary
static int getNibble(byte[] data, int index)
          Get a nibble from a byte array.
static int getNibble(byte data, int index)
          Get a nibble from a byte value.
static int getNibble(char data, int index)
          Get a nibble from a char value.
static int getNibble(double data, int index)
          Get a nibble from a double value (raw format).
static int getNibble(float data, int index)
          Get a nibble from a float value (raw format).
static int getNibble(int data, int index)
          Get a nibble from an int value.
static int getNibble(long data, int index)
          Get a nibble from a long value.
static int getNibble(short data, int index)
          Get a nibble from a short value.
static char getNibbleLC(byte[] data, int index)
          Get a lowercase character reflecting a nibble from a byte array.
static char getNibbleLC(byte data, int index)
          Get a lowercase character reflecting a nibble from a byte.
static char getNibbleLC(char data, int index)
          Get a lowercase character reflecting a nibble from a char.
static char getNibbleLC(double data, int index)
          Get a lowercase character reflecting a nibble from a double.
static char getNibbleLC(float data, int index)
          Get a lowercase character reflecting a nibble from a float.
static char getNibbleLC(int nibble)
          Get a lowercase character for a nibble.
static char getNibbleLC(int data, int index)
          Get a lowercase character reflecting a nibble from a int.
static char getNibbleLC(long data, int index)
          Get a lowercase character reflecting a nibble from a long.
static char getNibbleLC(short data, int index)
          Get a lowercase character reflecting a nibble from a short.
static byte[] getNibbles(byte[] data)
          Get all nibbles from a byte array.
static byte[] getNibbles(byte[] data, int startIndex, int length)
          Get some nibbles from a byte array.
static char getNibbleUC(byte[] data, int index)
          Get an uppercase character reflecting a nibble from a byte array.
static char getNibbleUC(byte data, int index)
          Get an uppercase character reflecting a nibble from a byte.
static char getNibbleUC(char data, int index)
          Get an uppercase character reflecting a nibble from a char.
static char getNibbleUC(double data, int index)
          Get an uppercase character reflecting a nibble from a double.
static char getNibbleUC(float data, int index)
          Get an uppercase character reflecting a nibble from a float.
static char getNibbleUC(int nibble)
          Get a uppercase character for a nibble.
static char getNibbleUC(int data, int index)
          Get an uppercase character reflecting a nibble from a int.
static char getNibbleUC(long data, int index)
          Get an uppercase character reflecting a nibble from a long.
static char getNibbleUC(short data, int index)
          Get an uppercase character reflecting a nibble from a short.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getNibble

public static int getNibble(byte[] data,
                            int index)
Get a nibble from a byte array.

Parameters:
data - byte array to get nibble from
index - nibble number
Returns:
nibble value with nibble number

getNibbles

public static byte[] getNibbles(byte[] data)
Get all nibbles from a byte array.

Parameters:
data - byte array to get nibbles from
Returns:
byte array with nibbles; the length of the returned byte array is twice the length of the argument byte array

getNibbles

public static byte[] getNibbles(byte[] data,
                                int startIndex,
                                int length)
Get some nibbles from a byte array.

Parameters:
data - byte array to get nibbles from
startIndex - first nibble index to get nibble for
length - number of nibbles to get
Returns:
byte array with nibbles

getNibble

public static int getNibble(byte data,
                            int index)
Get a nibble from a byte value.

Parameters:
data - byte value to get nibble from
index - nibble number
Returns:
nibble value with nibble number

getNibble

public static int getNibble(short data,
                            int index)
Get a nibble from a short value.

Parameters:
data - short value to get nibble from
index - nibble number
Returns:
nibble value with nibble number

getNibble

public static int getNibble(int data,
                            int index)
Get a nibble from an int value.

Parameters:
data - int value to get nibble from
index - nibble number
Returns:
nibble value with nibble number

getNibble

public static int getNibble(long data,
                            int index)
Get a nibble from a long value.

Parameters:
data - int value to get nibble from
index - nibble number
Returns:
nibble value with nibble number

getNibble

public static int getNibble(char data,
                            int index)
Get a nibble from a char value.

Parameters:
data - char value to get nibble from
index - nibble nubmer
Returns:
nibble value with nibble number

getNibble

public static int getNibble(float data,
                            int index)
Get a nibble from a float value (raw format). To get the nibble from a float value in logical format, convert the float to an int yourself using Float.floatToIntBits(float).

Parameters:
data - float value to get nibble from
index - nibble nubmer
Returns:
nibble value with nibble number

getNibble

public static int getNibble(double data,
                            int index)
Get a nibble from a double value (raw format). To get the nibble from a double value in logical format, convert the float to an int yourself using Double.doubleToLongBits(double).

Parameters:
data - double value to get nibble from
index - nibble nubmer
Returns:
nibble value with nibble number

getNibbleLC

public static char getNibbleLC(int nibble)
Get a lowercase character for a nibble.

Parameters:
nibble - nibble to get character for
Returns:
lowercase character for data
Throws:
IllegalArgumentException - if data isn't a single nibble

getNibbleUC

public static char getNibbleUC(int nibble)
Get a uppercase character for a nibble.

Parameters:
nibble - nibble to get character for
Returns:
uppercase character for data
Throws:
IllegalArgumentException - if data isn't a single nibble

getNibbleLC

public static char getNibbleLC(byte[] data,
                               int index)
Get a lowercase character reflecting a nibble from a byte array. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - byte array to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(byte[] data,
                               int index)
Get an uppercase character reflecting a nibble from a byte array.

Parameters:
data - byte array to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(byte data,
                               int index)
Get a lowercase character reflecting a nibble from a byte. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - byte to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(byte data,
                               int index)
Get an uppercase character reflecting a nibble from a byte.

Parameters:
data - byte to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(short data,
                               int index)
Get a lowercase character reflecting a nibble from a short. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - short to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(short data,
                               int index)
Get an uppercase character reflecting a nibble from a short.

Parameters:
data - short to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(int data,
                               int index)
Get a lowercase character reflecting a nibble from a int. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - int to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(int data,
                               int index)
Get an uppercase character reflecting a nibble from a int.

Parameters:
data - int to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(long data,
                               int index)
Get a lowercase character reflecting a nibble from a long. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - long to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(long data,
                               int index)
Get an uppercase character reflecting a nibble from a long.

Parameters:
data - long to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(char data,
                               int index)
Get a lowercase character reflecting a nibble from a char. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - char to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(char data,
                               int index)
Get an uppercase character reflecting a nibble from a char.

Parameters:
data - char to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(float data,
                               int index)
Get a lowercase character reflecting a nibble from a float. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - float to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(float data,
                               int index)
Get an uppercase character reflecting a nibble from a float.

Parameters:
data - float to get nibble from
index - nibble number
Returns:
nibble character

getNibbleLC

public static char getNibbleLC(double data,
                               int index)
Get a lowercase character reflecting a nibble from a double. Shorthand for getNibbleLC(getNibble(data, index)).

Parameters:
data - double to get nibble from
index - nibble number
Returns:
nibble character

getNibbleUC

public static char getNibbleUC(double data,
                               int index)
Get an uppercase character reflecting a nibble from a double.

Parameters:
data - double to get nibble from
index - nibble number
Returns:
nibble character

JAPI
Yet another Java API
API Documentation

© 2005-2006 Christian Hujer. All rights reserved. See copyright