org.neodatis.odb.impl.core.layers.layer3.engine
Class DefaultByteArrayConverter

java.lang.Object
  extended by org.neodatis.odb.impl.core.layers.layer3.engine.DefaultByteArrayConverter
All Implemented Interfaces:
ITwoPhaseInit, IByteArrayConverter

public class DefaultByteArrayConverter
extends java.lang.Object
implements IByteArrayConverter

Converts array of bytes into native objects and native objects into array of bytes

Author:
osmadja

Constructor Summary
DefaultByteArrayConverter()
           
 
Method Summary
 byte[] bigDecimalToByteArray(java.math.BigDecimal bigDecimal, boolean withSize)
           
 byte[] bigIntegerToByteArray(java.math.BigInteger bigInteger, boolean withSize)
           
 byte[] booleanToByteArray(boolean b)
           
 void booleanToByteArray(boolean b, byte[] arrayWhereToWrite, int offset)
           
 java.math.BigDecimal byteArrayToBigDecimal(byte[] bytes, boolean hasSize)
           
 java.math.BigInteger byteArrayToBigInteger(byte[] bytes, boolean hasSize)
           
 boolean byteArrayToBoolean(byte[] bytes, int offset)
           
 char byteArrayToChar(byte[] bytes)
           
 java.util.Date byteArrayToDate(byte[] bytes)
           
 double byteArrayToDouble(byte[] bytes)
           
 float byteArrayToFloat(byte[] bytes)
           
 int byteArrayToInt(byte[] bytes, int offset)
           
 long byteArrayToLong(byte[] bytes, int offset)
           
 short byteArrayToShort(byte[] bytes)
           
 java.lang.String byteArrayToString(byte[] bytes, boolean hasSize, boolean useEncoding)
           
 byte[] charToByteArray(char c)
           
 byte[] dateToByteArray(java.util.Date date)
           
 byte[] doubleToByteArray(double d)
           
 byte[] floatToByteArray(float f)
           
 int getNumberOfBytesOfAString(java.lang.String s, boolean useEncoding)
           
 void init2()
          Two Phase Init method
 byte[] intToByteArray(int l)
           
 void intToByteArray(int l, byte[] arrayWhereToWrite, int offset)
          This method writes the byte directly to the array parameter
 byte[] longToByteArray(long l)
           
 void longToByteArray(long l, byte[] arrayWhereToWrite, int offset)
          This method writes the byte directly to the array parameter
 void setDatabaseCharacterEncoding(java.lang.String databaseCharacterEncoding)
           
 byte[] shortToByteArray(short s)
           
 byte[] stringToByteArray(java.lang.String s, boolean withSize, int totalSpace, boolean withEncoding)
           
 void testEncoding(java.lang.String encoding)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultByteArrayConverter

public DefaultByteArrayConverter()
Method Detail

init2

public void init2()
Two Phase Init method

Specified by:
init2 in interface ITwoPhaseInit

booleanToByteArray

public byte[] booleanToByteArray(boolean b)
Specified by:
booleanToByteArray in interface IByteArrayConverter

booleanToByteArray

public void booleanToByteArray(boolean b,
                               byte[] arrayWhereToWrite,
                               int offset)
Specified by:
booleanToByteArray in interface IByteArrayConverter

byteArrayToBoolean

public boolean byteArrayToBoolean(byte[] bytes,
                                  int offset)
Specified by:
byteArrayToBoolean in interface IByteArrayConverter

shortToByteArray

public byte[] shortToByteArray(short s)
Specified by:
shortToByteArray in interface IByteArrayConverter

byteArrayToShort

public short byteArrayToShort(byte[] bytes)
Specified by:
byteArrayToShort in interface IByteArrayConverter

charToByteArray

public byte[] charToByteArray(char c)
Specified by:
charToByteArray in interface IByteArrayConverter

byteArrayToChar

public char byteArrayToChar(byte[] bytes)
Specified by:
byteArrayToChar in interface IByteArrayConverter

getNumberOfBytesOfAString

public int getNumberOfBytesOfAString(java.lang.String s,
                                     boolean useEncoding)
Specified by:
getNumberOfBytesOfAString in interface IByteArrayConverter

stringToByteArray

public byte[] stringToByteArray(java.lang.String s,
                                boolean withSize,
                                int totalSpace,
                                boolean withEncoding)
Specified by:
stringToByteArray in interface IByteArrayConverter
withSize - if true, returns an array with an initial int with its size
totalSpace - The total space of the string (can be bigger that the real string size - to support later in place update)
withEncoding - To specify if SPECIFIC encoding must be used
Returns:
The byte array that represent the string

byteArrayToString

public java.lang.String byteArrayToString(byte[] bytes,
                                          boolean hasSize,
                                          boolean useEncoding)
Specified by:
byteArrayToString in interface IByteArrayConverter
hasSize - If hasSize is true, the first four bytes are the size of the string
Returns:
The String represented by the byte array

bigDecimalToByteArray

public byte[] bigDecimalToByteArray(java.math.BigDecimal bigDecimal,
                                    boolean withSize)
Specified by:
bigDecimalToByteArray in interface IByteArrayConverter

byteArrayToBigDecimal

public java.math.BigDecimal byteArrayToBigDecimal(byte[] bytes,
                                                  boolean hasSize)
Specified by:
byteArrayToBigDecimal in interface IByteArrayConverter

bigIntegerToByteArray

public byte[] bigIntegerToByteArray(java.math.BigInteger bigInteger,
                                    boolean withSize)
Specified by:
bigIntegerToByteArray in interface IByteArrayConverter

byteArrayToBigInteger

public java.math.BigInteger byteArrayToBigInteger(byte[] bytes,
                                                  boolean hasSize)
Specified by:
byteArrayToBigInteger in interface IByteArrayConverter

intToByteArray

public byte[] intToByteArray(int l)
Specified by:
intToByteArray in interface IByteArrayConverter

intToByteArray

public void intToByteArray(int l,
                           byte[] arrayWhereToWrite,
                           int offset)
This method writes the byte directly to the array parameter

Specified by:
intToByteArray in interface IByteArrayConverter

byteArrayToInt

public int byteArrayToInt(byte[] bytes,
                          int offset)
Specified by:
byteArrayToInt in interface IByteArrayConverter

longToByteArray

public byte[] longToByteArray(long l)
Specified by:
longToByteArray in interface IByteArrayConverter

longToByteArray

public void longToByteArray(long l,
                            byte[] arrayWhereToWrite,
                            int offset)
This method writes the byte directly to the array parameter

Specified by:
longToByteArray in interface IByteArrayConverter

byteArrayToLong

public long byteArrayToLong(byte[] bytes,
                            int offset)
Specified by:
byteArrayToLong in interface IByteArrayConverter

dateToByteArray

public byte[] dateToByteArray(java.util.Date date)
Specified by:
dateToByteArray in interface IByteArrayConverter

byteArrayToDate

public java.util.Date byteArrayToDate(byte[] bytes)
Specified by:
byteArrayToDate in interface IByteArrayConverter

floatToByteArray

public byte[] floatToByteArray(float f)
Specified by:
floatToByteArray in interface IByteArrayConverter

byteArrayToFloat

public float byteArrayToFloat(byte[] bytes)
Specified by:
byteArrayToFloat in interface IByteArrayConverter

doubleToByteArray

public byte[] doubleToByteArray(double d)
Specified by:
doubleToByteArray in interface IByteArrayConverter

byteArrayToDouble

public double byteArrayToDouble(byte[] bytes)
Specified by:
byteArrayToDouble in interface IByteArrayConverter

setDatabaseCharacterEncoding

public void setDatabaseCharacterEncoding(java.lang.String databaseCharacterEncoding)
Specified by:
setDatabaseCharacterEncoding in interface IByteArrayConverter

testEncoding

public void testEncoding(java.lang.String encoding)
                  throws java.io.UnsupportedEncodingException
Specified by:
testEncoding in interface IByteArrayConverter
Throws:
java.io.UnsupportedEncodingException