org.objectweb.proactive.mpi.control.util
Class ProActiveMPIUtil

java.lang.Object
  extended by org.objectweb.proactive.mpi.control.util.ProActiveMPIUtil

public class ProActiveMPIUtil
extends java.lang.Object

Provides functions to easily convert short, int float into/from byte[]


Field Summary
static int BYTE_LEN
           
static int DOUBLE_LEN
           
static int FLOAT_LEN
           
static int INT_LEN
           
static int LONG_LEN
           
static int SHORT_LEN
           
 
Constructor Summary
ProActiveMPIUtil()
           
 
Method Summary
static double bytesToDouble(byte[] bytes, int startIndex)
          Given an array of bytes, convert it to a double, least significant byte is stored in the beginning.
static float bytesToFloat(byte[] bytes, int startIndex)
          Given a byte array, restore it as an float
static int bytesToInt(byte[] bytes, int startIndex)
          Given a byte array, restore it as an int
static long bytesToLong(byte[] bytes, int startIndex)
          Given an array of bytes, convert it to a long, least significant byte is stored in the beginning.
static short bytesToShort(byte[] bytes, int startIndex)
          Given a byte array, restore it as a short
static java.lang.String bytesToString(byte[] bytes, int startIndex)
          Given a byte array, restore a String out of it.
static int doubleToBytes(double dnum, byte[] bytes, int startIndex)
          Given a double, convert it into a byte array
static int floatToBytes(float fnum, byte[] bytes, int startIndex)
          translate float into bytes, stored in byte array starting from startIndex
static int intToBytes(int num, byte[] bytes, int startIndex)
          translate int into bytes, stored in byte array starting from startIndex
static int longToBytes(long lnum, byte[] bytes, int startIndex)
          Given a long, convert it into a byte array
static int shortToBytes(short num, byte[] bytes, int startIndex)
          translate short into bytes, stored in byte array starting from startIndex
static int stringToBytes(java.lang.String str, byte[] bytes, int startIndex)
          Give a String less than 255 bytes, store it as byte array, starting with the length of the string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BYTE_LEN

public static final int BYTE_LEN
See Also:
Constant Field Values

SHORT_LEN

public static final int SHORT_LEN
See Also:
Constant Field Values

INT_LEN

public static final int INT_LEN
See Also:
Constant Field Values

FLOAT_LEN

public static final int FLOAT_LEN
See Also:
Constant Field Values

LONG_LEN

public static final int LONG_LEN
See Also:
Constant Field Values

DOUBLE_LEN

public static final int DOUBLE_LEN
See Also:
Constant Field Values
Constructor Detail

ProActiveMPIUtil

public ProActiveMPIUtil()
Method Detail

intToBytes

public static int intToBytes(int num,
                             byte[] bytes,
                             int startIndex)
translate int into bytes, stored in byte array starting from startIndex

Parameters:
num - the integer to be translated
bytes[] - the byte array
startIndex - starting to store in this index

bytesToInt

public static int bytesToInt(byte[] bytes,
                             int startIndex)
Given a byte array, restore it as an int

Parameters:
bytes - the byte array
startIndex - the starting index of the place the int is stored

floatToBytes

public static int floatToBytes(float fnum,
                               byte[] bytes,
                               int startIndex)
translate float into bytes, stored in byte array starting from startIndex

Parameters:
num - the float to be translated
bytes[] - the byte array
startIndex - starting to store in this index

bytesToFloat

public static float bytesToFloat(byte[] bytes,
                                 int startIndex)
Given a byte array, restore it as an float

Parameters:
bytes - the byte array
startIndex - the starting index of the place the int is stored

shortToBytes

public static int shortToBytes(short num,
                               byte[] bytes,
                               int startIndex)
translate short into bytes, stored in byte array starting from startIndex

Parameters:
num - the short to be translated
bytes[] - the byte array
startIndex - starting to store in this index

bytesToShort

public static short bytesToShort(byte[] bytes,
                                 int startIndex)
Given a byte array, restore it as a short

Parameters:
bytes - the byte array
startIndex - the starting index of the place the int is stored

stringToBytes

public static int stringToBytes(java.lang.String str,
                                byte[] bytes,
                                int startIndex)
Give a String less than 255 bytes, store it as byte array, starting with the length of the string. If the length of the String is longer than 255, a warning is generated, and the string will be truncated.

Parameters:
str - the string that is less than 255 bytes
bytes - the byte array
startIndex - the starting index where the string will be stored.

bytesToString

public static java.lang.String bytesToString(byte[] bytes,
                                             int startIndex)
Given a byte array, restore a String out of it. the first cell stores the length of the String

Parameters:
bytes - the byte array
startIndex - the starting index where the string is stored, the first cell stores the length

longToBytes

public static int longToBytes(long lnum,
                              byte[] bytes,
                              int startIndex)
Given a long, convert it into a byte array

Parameters:
lnum - the long given to convert
bytes - the bytes where to store the result
startIndex - the starting index of the array where the result is stored.

bytesToLong

public static long bytesToLong(byte[] bytes,
                               int startIndex)
Given an array of bytes, convert it to a long, least significant byte is stored in the beginning.

Parameters:
bytes - the byte array
startIndex - the starting index of the array where the long is stored.

doubleToBytes

public static int doubleToBytes(double dnum,
                                byte[] bytes,
                                int startIndex)
Given a double, convert it into a byte array

Parameters:
dnum - the double given to convert
bytes - the bytes where to store the result
startIndex - the starting index of the array where the result is stored.

bytesToDouble

public static double bytesToDouble(byte[] bytes,
                                   int startIndex)
Given an array of bytes, convert it to a double, least significant byte is stored in the beginning.

Parameters:
bytes - the byte array
startIndex - the starting index of the array where the long is stored.


Copyright 2001-2007 INRIA All Rights Reserved.