net.obsearch.utils.bytes
Class ByteConversion

java.lang.Object
  extended by net.obsearch.utils.bytes.ByteConversion

public class ByteConversion
extends Object

ByteConversion. Utilities to convert primitive types from and to byte arrays.

Author:
Arnoldo Jose Muller Molina

Field Summary
static ByteOrder ORDERING
           
 
Constructor Summary
ByteConversion()
           
 
Method Summary
static byte byteBufferToByte(ByteBuffer data)
          Reads a(n) Byte from the beginning of the given ByteBuffer.
static double byteBufferToDouble(ByteBuffer data)
          Reads a(n) Double from the beginning of the given ByteBuffer.
static float byteBufferToFloat(ByteBuffer data)
          Reads a(n) Float from the beginning of the given ByteBuffer.
static int byteBufferToInt(ByteBuffer data)
          Reads a(n) Int from the beginning of the given ByteBuffer.
static long byteBufferToLong(ByteBuffer data)
          Reads a(n) Long from the beginning of the given ByteBuffer.
static short byteBufferToShort(ByteBuffer data)
          Reads a(n) Short from the beginning of the given ByteBuffer.
static byte bytesToByte(byte[] data)
          Reads a(n) Byte from the beginning of the given data array.
static double bytesToDouble(byte[] data)
          Reads a(n) Double from the beginning of the given data array.
static float bytesToFloat(byte[] data)
          Reads a(n) Float from the beginning of the given data array.
static int bytesToInt(byte[] data)
          Reads a(n) Int from the beginning of the given data array.
static long bytesToLong(byte[] data)
          Reads a(n) Long from the beginning of the given data array.
static short bytesToShort(byte[] data)
          Reads a(n) Short from the beginning of the given data array.
static ByteBuffer byteToByteBuffer(byte i)
          Convert a(n) Byte into bytes.
static byte[] byteToBytes(byte i)
          Convert a(n) Byte into bytes.
static ByteBuffer createByteBuffer(byte[] data)
          Create a ByteBuffer from the given byte array.
static ByteBuffer createByteBuffer(int n)
          Create a ByteBuffer of size n.
static ByteBuffer doubleToByteBuffer(double i)
          Convert a(n) Double into bytes.
static byte[] doubleToBytes(double i)
          Convert a(n) Double into bytes.
static ByteBuffer floatToByteBuffer(float i)
          Convert a(n) Float into bytes.
static byte[] floatToBytes(float i)
          Convert a(n) Float into bytes.
static ByteBuffer intToByteBuffer(int i)
          Convert a(n) Int into bytes.
static byte[] intToBytes(int i)
          Convert a(n) Int into bytes.
static ByteBuffer longToByteBuffer(long i)
          Convert a(n) Long into bytes.
static byte[] longToBytes(long i)
          Convert a(n) Long into bytes.
static ByteBuffer shortToByteBuffer(short i)
          Convert a(n) Short into bytes.
static byte[] shortToBytes(short i)
          Convert a(n) Short into bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORDERING

public static final ByteOrder ORDERING
Constructor Detail

ByteConversion

public ByteConversion()
Method Detail

createByteBuffer

public static ByteBuffer createByteBuffer(int n)
Create a ByteBuffer of size n.

Parameters:
n - size of the new buffer.
Returns:
The buffer.

createByteBuffer

public static ByteBuffer createByteBuffer(byte[] data)
Create a ByteBuffer from the given byte array.

Parameters:
n - size of the new buffer.
Returns:
The buffer.

bytesToByte

public static byte bytesToByte(byte[] data)
Reads a(n) Byte from the beginning of the given data array. No size checks are performed.

Parameters:
data - Data that holds the encoded byte.
Returns:
byte parsed from data.

byteToBytes

public static byte[] byteToBytes(byte i)
Convert a(n) Byte into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

byteBufferToByte

public static byte byteBufferToByte(ByteBuffer data)
Reads a(n) Byte from the beginning of the given ByteBuffer. No size checks are performed.

Parameters:
data - Data that holds the encoded byte.
Returns:
byte parsed from data.

byteToByteBuffer

public static ByteBuffer byteToByteBuffer(byte i)
Convert a(n) Byte into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

bytesToShort

public static short bytesToShort(byte[] data)
Reads a(n) Short from the beginning of the given data array. No size checks are performed.

Parameters:
data - Data that holds the encoded short.
Returns:
short parsed from data.

shortToBytes

public static byte[] shortToBytes(short i)
Convert a(n) Short into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

byteBufferToShort

public static short byteBufferToShort(ByteBuffer data)
Reads a(n) Short from the beginning of the given ByteBuffer. No size checks are performed.

Parameters:
data - Data that holds the encoded short.
Returns:
short parsed from data.

shortToByteBuffer

public static ByteBuffer shortToByteBuffer(short i)
Convert a(n) Short into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

bytesToInt

public static int bytesToInt(byte[] data)
Reads a(n) Int from the beginning of the given data array. No size checks are performed.

Parameters:
data - Data that holds the encoded int.
Returns:
int parsed from data.

intToBytes

public static byte[] intToBytes(int i)
Convert a(n) Int into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

byteBufferToInt

public static int byteBufferToInt(ByteBuffer data)
Reads a(n) Int from the beginning of the given ByteBuffer. No size checks are performed.

Parameters:
data - Data that holds the encoded int.
Returns:
int parsed from data.

intToByteBuffer

public static ByteBuffer intToByteBuffer(int i)
Convert a(n) Int into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

bytesToLong

public static long bytesToLong(byte[] data)
Reads a(n) Long from the beginning of the given data array. No size checks are performed.

Parameters:
data - Data that holds the encoded long.
Returns:
long parsed from data.

longToBytes

public static byte[] longToBytes(long i)
Convert a(n) Long into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

byteBufferToLong

public static long byteBufferToLong(ByteBuffer data)
Reads a(n) Long from the beginning of the given ByteBuffer. No size checks are performed.

Parameters:
data - Data that holds the encoded long.
Returns:
long parsed from data.

longToByteBuffer

public static ByteBuffer longToByteBuffer(long i)
Convert a(n) Long into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

bytesToFloat

public static float bytesToFloat(byte[] data)
Reads a(n) Float from the beginning of the given data array. No size checks are performed.

Parameters:
data - Data that holds the encoded float.
Returns:
float parsed from data.

floatToBytes

public static byte[] floatToBytes(float i)
Convert a(n) Float into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

byteBufferToFloat

public static float byteBufferToFloat(ByteBuffer data)
Reads a(n) Float from the beginning of the given ByteBuffer. No size checks are performed.

Parameters:
data - Data that holds the encoded float.
Returns:
float parsed from data.

floatToByteBuffer

public static ByteBuffer floatToByteBuffer(float i)
Convert a(n) Float into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

bytesToDouble

public static double bytesToDouble(byte[] data)
Reads a(n) Double from the beginning of the given data array. No size checks are performed.

Parameters:
data - Data that holds the encoded double.
Returns:
double parsed from data.

doubleToBytes

public static byte[] doubleToBytes(double i)
Convert a(n) Double into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.

byteBufferToDouble

public static double byteBufferToDouble(ByteBuffer data)
Reads a(n) Double from the beginning of the given ByteBuffer. No size checks are performed.

Parameters:
data - Data that holds the encoded double.
Returns:
double parsed from data.

doubleToByteBuffer

public static ByteBuffer doubleToByteBuffer(double i)
Convert a(n) Double into bytes.

Parameters:
i - value to convert.
Returns:
The byte array that represents the value.


Copyright © 2007-2011 Arnoldo Jose Muller Molina. All Rights Reserved.