| 
 | |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectnet.sourceforge.apphere.util.BytesUtil
Provides functions to easily convert short, int, string and 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 | |
| BytesUtil() | |
| 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 int | 
| 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 | 
| equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
public static final int BYTE_LEN
public static final int SHORT_LEN
public static final int INT_LEN
public static final int FLOAT_LEN
public static final int LONG_LEN
public static final int DOUBLE_LEN
| Constructor Detail | 
public BytesUtil()
| Method Detail | 
public static int intToBytes(int num,
                             byte[] bytes,
                             int startIndex)
num - the integer to be translatedstartIndex - starting to store in this index
public static int bytesToInt(byte[] bytes,
                             int startIndex)
bytes - the byte arraystartIndex - the starting index of the place the int is stored
public static int floatToBytes(float fnum,
                               byte[] bytes,
                               int startIndex)
startIndex - starting to store in this index
public static float bytesToFloat(byte[] bytes,
                                 int startIndex)
bytes - the byte arraystartIndex - the starting index of the place the int is stored
public static int shortToBytes(short num,
                               byte[] bytes,
                               int startIndex)
num - the short to be translatedstartIndex - starting to store in this index
public static short bytesToShort(byte[] bytes,
                                 int startIndex)
bytes - the byte arraystartIndex - the starting index of the place the int is stored
public static int stringToBytes(java.lang.String str,
                                byte[] bytes,
                                int startIndex)
str - the string that is less than 255 bytesbytes - the byte arraystartIndex - the starting index where the string will be stored.
public static java.lang.String bytesToString(byte[] bytes,
                                             int startIndex)
bytes - the byte arraystartIndex - the starting index where the string is stored, the first cell stores the length
public static int longToBytes(long lnum,
                              byte[] bytes,
                              int startIndex)
lnum - the long given to convertbytes - the bytes where to store the resultstartIndex - the starting index of the array where the result is stored.
public static long bytesToLong(byte[] bytes,
                               int startIndex)
bytes - the byte arraystartIndex - the starting index of the array where the long is stored.
public static int doubleToBytes(double dnum,
                                byte[] bytes,
                                int startIndex)
dnum - the double given to convertbytes - the bytes where to store the resultstartIndex - the starting index of the array where the result is stored.
public static double bytesToDouble(byte[] bytes,
                                   int startIndex)
bytes - the byte arraystartIndex - the starting index of the array where the long is stored.
| 
 | |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||