com.mymed.utils
Class MConverter

java.lang.Object
  extended by com.mymed.utils.MConverter

public final class MConverter
extends java.lang.Object

Convenience class to convert to and from ByteBuffer for the most used data types.

Author:
Milo Casagrande

Method Summary
static java.nio.ByteBuffer booleanToByteBuffer(boolean value)
          Convert a boolean value into a fictitious ByteBuffer
static boolean byteBufferToBoolean(java.nio.ByteBuffer buffer)
          Convert a boolean value contained in a ByteBuffer into a boolean
static byte byteBufferToByte(java.nio.ByteBuffer buffer)
          Convert a ByteBuffer into a byte No assumptions are made on the value stored in the ByteBuffer, it has to be a byte
static double byteBufferToDouble(java.nio.ByteBuffer buffer)
          Convert a ByteBuffer into an double No assumptions are made on the value stored in the ByteBuffer, it has to be a double
static int byteBufferToInteger(java.nio.ByteBuffer buffer)
          Convert a ByteBuffer into an integer No assumptions are made on the value stored in the ByteBuffer, it has to be an integer
static long byteBufferToLong(java.nio.ByteBuffer buffer)
          Convert a ByteBuffer into an long No assumptions are made on the value stored in the ByteBuffer, it has to be a long
static java.lang.String byteBufferToString(java.nio.ByteBuffer buffer)
          Convert a ByteBuffer back into a string
static java.nio.ByteBuffer byteToByteBuffer(byte value)
          Convert a byte value into a ByteBuffer
static java.nio.ByteBuffer byteToByteBuffer(java.lang.Byte value)
          Convert a byte value into a ByteBuffer
static java.lang.String convertStreamToString(java.io.InputStream is, int length)
          Given an InputStream reads the bytes as UTF8 chars and return a String.
static java.nio.ByteBuffer doubleToByteBuffer(double value)
          Convert a double value into a ByteBuffer
static java.nio.ByteBuffer doubleToByteBuffer(java.lang.Double value)
          Convert a double value into a ByteBuffer
static java.nio.ByteBuffer intToByteBuffer(int value)
          Convert an integer value into a ByteBuffer
static java.nio.ByteBuffer intToByteBuffer(java.lang.Integer value)
          Convert an integer value into a ByteBuffer
static java.nio.ByteBuffer longToByteBuffer(long value)
          Convert a long value into a ByteBuffer
static java.nio.ByteBuffer longToByteBuffer(java.lang.Long value)
          Convert a long value into a ByteBuffer
static java.util.List<java.nio.ByteBuffer> stringToByteBuffer(java.util.List<java.lang.String> list)
          Convert a list of strings in a list with the strings converted into ByteBuffer
static java.nio.ByteBuffer stringToByteBuffer(java.lang.String string)
          Convert a string into a ByteBuffer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

stringToByteBuffer

public static java.nio.ByteBuffer stringToByteBuffer(java.lang.String string)
                                              throws InternalBackEndException
Convert a string into a ByteBuffer. If the String object passed is null, it is treated as an empty string

Parameters:
string - the string to convert
Returns:
the string converted into a ByteBuffer
Throws:
InternalBackEndException - when a wrong encoding is used

stringToByteBuffer

public static java.util.List<java.nio.ByteBuffer> stringToByteBuffer(java.util.List<java.lang.String> list)
                                                              throws InternalBackEndException
Convert a list of strings in a list with the strings converted into ByteBuffer

Parameters:
list - the list with the strings to convert
Returns:
the list with the strings converted
Throws:
InternalBackEndException - if one of the strings is null, or when a wrong encoding is used

byteBufferToString

public static java.lang.String byteBufferToString(java.nio.ByteBuffer buffer)
                                           throws InternalBackEndException
Convert a ByteBuffer back into a string

Parameters:
buffer - the ByteBuffer to convert
Returns:
the string
Throws:
InternalBackEndException - if the buffer is null, or when a wrong encoding is used

intToByteBuffer

public static java.nio.ByteBuffer intToByteBuffer(int value)
Convert an integer value into a ByteBuffer

Parameters:
value - the integer to convert
Returns:
the ByteBuffer value

intToByteBuffer

public static java.nio.ByteBuffer intToByteBuffer(java.lang.Integer value)
Convert an integer value into a ByteBuffer

Parameters:
value - the integer to convert
Returns:
the ByteBuffer value

byteBufferToInteger

public static int byteBufferToInteger(java.nio.ByteBuffer buffer)
Convert a ByteBuffer into an integer

No assumptions are made on the value stored in the ByteBuffer, it has to be an integer

Parameters:
buffer - the ByteBuffer that holds the integer value
Returns:
the integer value

longToByteBuffer

public static java.nio.ByteBuffer longToByteBuffer(long value)
Convert a long value into a ByteBuffer

Parameters:
value - the long to convert
Returns:
the ByteBuffer value

longToByteBuffer

public static java.nio.ByteBuffer longToByteBuffer(java.lang.Long value)
Convert a long value into a ByteBuffer

Parameters:
value - the long to convert
Returns:
the ByteBuffer value

byteBufferToLong

public static long byteBufferToLong(java.nio.ByteBuffer buffer)
Convert a ByteBuffer into an long

No assumptions are made on the value stored in the ByteBuffer, it has to be a long

Parameters:
buffer - the ByteBuffer that holds the long value
Returns:
the long value

byteToByteBuffer

public static java.nio.ByteBuffer byteToByteBuffer(byte value)
Convert a byte value into a ByteBuffer

Parameters:
value - the byte value to convert
Returns:
the ByteBuffer value

byteToByteBuffer

public static java.nio.ByteBuffer byteToByteBuffer(java.lang.Byte value)
Convert a byte value into a ByteBuffer

Parameters:
value - the byte value to convert
Returns:
the ByteBuffer value

byteBufferToByte

public static byte byteBufferToByte(java.nio.ByteBuffer buffer)
Convert a ByteBuffer into a byte

No assumptions are made on the value stored in the ByteBuffer, it has to be a byte

Parameters:
buffer - the ByteBuffer that holds the byte value
Returns:
the byte value

doubleToByteBuffer

public static java.nio.ByteBuffer doubleToByteBuffer(double value)
Convert a double value into a ByteBuffer

Parameters:
value - the double to convert
Returns:
the ByteBuffer value

doubleToByteBuffer

public static java.nio.ByteBuffer doubleToByteBuffer(java.lang.Double value)
Convert a double value into a ByteBuffer

Parameters:
value - the double to convert
Returns:
the ByteBuffer value

byteBufferToDouble

public static double byteBufferToDouble(java.nio.ByteBuffer buffer)
Convert a ByteBuffer into an double

No assumptions are made on the value stored in the ByteBuffer, it has to be a double

Parameters:
buffer - the ByteBuffer that holds the double value
Returns:
the long value

booleanToByteBuffer

public static java.nio.ByteBuffer booleanToByteBuffer(boolean value)
Convert a boolean value into a fictitious ByteBuffer

Parameters:
value - the boolean to convert
Returns:
a ByteBuffer representation of the boolean value

byteBufferToBoolean

public static boolean byteBufferToBoolean(java.nio.ByteBuffer buffer)
Convert a boolean value contained in a ByteBuffer into a boolean

Parameters:
buffer - the buffer with the boolean value
Returns:
the boolean value

convertStreamToString

public static java.lang.String convertStreamToString(java.io.InputStream is,
                                                     int length)
                                              throws InternalBackEndException
Given an InputStream reads the bytes as UTF8 chars and return a String.

Parameters:
is - Input stream.
length - Length of the stream in bytes.
Returns:
The string
Throws:
InternalBackEndException - Format is not correct or the length less then the real wrong.