com.amazon.carbonado.raw
Class DataDecoder

java.lang.Object
  extended by com.amazon.carbonado.raw.DataDecoder

public class DataDecoder
extends Object

A very low-level class that decodes key components encoded by methods of DataEncoder.

Author:
Brian S O'Neill
See Also:
KeyDecoder

Constructor Summary
DataDecoder()
           
 
Method Summary
static int decode(byte[] src, int srcOffset, BigDecimal[] valueRef)
          Decodes a BigDecimal.
static int decode(byte[] src, int srcOffset, BigInteger[] valueRef)
          Decodes a BigInteger.
static int decode(byte[] src, int srcOffset, byte[][] valueRef)
          Decodes the given byte array.
static boolean decodeBoolean(byte[] src, int srcOffset)
          Decodes a boolean from exactly 1 byte.
static Boolean decodeBooleanObj(byte[] src, int srcOffset)
          Decodes a Boolean object from exactly 1 byte.
static byte decodeByte(byte[] src, int srcOffset)
          Decodes a signed byte from exactly 1 byte.
static Byte decodeByteObj(byte[] src, int srcOffset)
          Decodes a signed Byte object from exactly 1 or 2 bytes.
static char decodeChar(byte[] src, int srcOffset)
          Decodes a char from exactly 2 bytes.
static Character decodeCharacterObj(byte[] src, int srcOffset)
          Decodes a Character object from exactly 1 or 3 bytes.
static double decodeDouble(byte[] src, int srcOffset)
          Decodes a double from exactly 8 bytes.
protected static long decodeDoubleBits(byte[] src, int srcOffset)
           
static Double decodeDoubleObj(byte[] src, int srcOffset)
          Decodes a Double object from exactly 8 bytes.
static float decodeFloat(byte[] src, int srcOffset)
          Decodes a float from exactly 4 bytes.
protected static int decodeFloatBits(byte[] src, int srcOffset)
           
static Float decodeFloatObj(byte[] src, int srcOffset)
          Decodes a Float object from exactly 4 bytes.
static int decodeInt(byte[] src, int srcOffset)
          Decodes a signed integer from exactly 4 bytes.
static Integer decodeIntegerObj(byte[] src, int srcOffset)
          Decodes a signed Integer object from exactly 1 or 5 bytes.
static long decodeLong(byte[] src, int srcOffset)
          Decodes a signed long from exactly 8 bytes.
static Long decodeLongObj(byte[] src, int srcOffset)
          Decodes a signed Long object from exactly 1 or 9 bytes.
static short decodeShort(byte[] src, int srcOffset)
          Decodes a signed short from exactly 2 bytes.
static Short decodeShortObj(byte[] src, int srcOffset)
          Decodes a signed Short object from exactly 1 or 3 bytes.
static byte[] decodeSingle(byte[] src, int prefixPadding, int suffixPadding)
          Decodes the given byte array which was encoded by DataEncoder.encodeSingle(byte[], int, int).
static byte[] decodeSingleNullable(byte[] src)
          Decodes the given byte array which was encoded by DataEncoder.encodeSingleNullable(byte[]).
static byte[] decodeSingleNullable(byte[] src, int prefixPadding, int suffixPadding)
          Decodes the given byte array which was encoded by DataEncoder.encodeSingleNullable(byte[]).
static int decodeString(byte[] src, int srcOffset, String[] valueRef)
          Decodes an encoded string from the given byte array.
static void readFully(InputStream in, byte[] b)
          Reads as many bytes from the stream as is necessary to fill the given byte array.
static int readLength(InputStream in)
          Decodes a length value which was encoded by DataEncoder.writeLength(int, java.io.OutputStream).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataDecoder

public DataDecoder()
Method Detail

decodeInt

public static int decodeInt(byte[] src,
                            int srcOffset)
                     throws CorruptEncodingException
Decodes a signed integer from exactly 4 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed integer value
Throws:
CorruptEncodingException

decodeIntegerObj

public static Integer decodeIntegerObj(byte[] src,
                                       int srcOffset)
                                throws CorruptEncodingException
Decodes a signed Integer object from exactly 1 or 5 bytes. If null is returned, then 1 byte was read.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed Integer object or null
Throws:
CorruptEncodingException

decodeLong

public static long decodeLong(byte[] src,
                              int srcOffset)
                       throws CorruptEncodingException
Decodes a signed long from exactly 8 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed long value
Throws:
CorruptEncodingException

decodeLongObj

public static Long decodeLongObj(byte[] src,
                                 int srcOffset)
                          throws CorruptEncodingException
Decodes a signed Long object from exactly 1 or 9 bytes. If null is returned, then 1 byte was read.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed Long object or null
Throws:
CorruptEncodingException

decodeByte

public static byte decodeByte(byte[] src,
                              int srcOffset)
                       throws CorruptEncodingException
Decodes a signed byte from exactly 1 byte.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed byte value
Throws:
CorruptEncodingException

decodeByteObj

public static Byte decodeByteObj(byte[] src,
                                 int srcOffset)
                          throws CorruptEncodingException
Decodes a signed Byte object from exactly 1 or 2 bytes. If null is returned, then 1 byte was read.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed Byte object or null
Throws:
CorruptEncodingException

decodeShort

public static short decodeShort(byte[] src,
                                int srcOffset)
                         throws CorruptEncodingException
Decodes a signed short from exactly 2 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed short value
Throws:
CorruptEncodingException

decodeShortObj

public static Short decodeShortObj(byte[] src,
                                   int srcOffset)
                            throws CorruptEncodingException
Decodes a signed Short object from exactly 1 or 3 bytes. If null is returned, then 1 byte was read.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
signed Short object or null
Throws:
CorruptEncodingException

decodeChar

public static char decodeChar(byte[] src,
                              int srcOffset)
                       throws CorruptEncodingException
Decodes a char from exactly 2 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
char value
Throws:
CorruptEncodingException

decodeCharacterObj

public static Character decodeCharacterObj(byte[] src,
                                           int srcOffset)
                                    throws CorruptEncodingException
Decodes a Character object from exactly 1 or 3 bytes. If null is returned, then 1 byte was read.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
Character object or null
Throws:
CorruptEncodingException

decodeBoolean

public static boolean decodeBoolean(byte[] src,
                                    int srcOffset)
                             throws CorruptEncodingException
Decodes a boolean from exactly 1 byte.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
boolean value
Throws:
CorruptEncodingException

decodeBooleanObj

public static Boolean decodeBooleanObj(byte[] src,
                                       int srcOffset)
                                throws CorruptEncodingException
Decodes a Boolean object from exactly 1 byte.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
Boolean object or null
Throws:
CorruptEncodingException

decodeFloat

public static float decodeFloat(byte[] src,
                                int srcOffset)
                         throws CorruptEncodingException
Decodes a float from exactly 4 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
float value
Throws:
CorruptEncodingException

decodeFloatObj

public static Float decodeFloatObj(byte[] src,
                                   int srcOffset)
                            throws CorruptEncodingException
Decodes a Float object from exactly 4 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
Float object or null
Throws:
CorruptEncodingException

decodeFloatBits

protected static int decodeFloatBits(byte[] src,
                                     int srcOffset)
                              throws CorruptEncodingException
Throws:
CorruptEncodingException

decodeDouble

public static double decodeDouble(byte[] src,
                                  int srcOffset)
                           throws CorruptEncodingException
Decodes a double from exactly 8 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
double value
Throws:
CorruptEncodingException

decodeDoubleObj

public static Double decodeDoubleObj(byte[] src,
                                     int srcOffset)
                              throws CorruptEncodingException
Decodes a Double object from exactly 8 bytes.

Parameters:
src - source of encoded bytes
srcOffset - offset into source array
Returns:
Double object or null
Throws:
CorruptEncodingException

decodeDoubleBits

protected static long decodeDoubleBits(byte[] src,
                                       int srcOffset)
                                throws CorruptEncodingException
Throws:
CorruptEncodingException

decode

public static int decode(byte[] src,
                         int srcOffset,
                         BigInteger[] valueRef)
                  throws CorruptEncodingException
Decodes a BigInteger.

Parameters:
src - source of encoded data
srcOffset - offset into encoded data
valueRef - decoded BigInteger is stored in element 0, which may be null
Returns:
amount of bytes read from source
Throws:
CorruptEncodingException - if source data is corrupt
Since:
1.2

decode

public static int decode(byte[] src,
                         int srcOffset,
                         BigDecimal[] valueRef)
                  throws CorruptEncodingException
Decodes a BigDecimal.

Parameters:
src - source of encoded data
srcOffset - offset into encoded data
valueRef - decoded BigDecimal is stored in element 0, which may be null
Returns:
amount of bytes read from source
Throws:
CorruptEncodingException - if source data is corrupt
Since:
1.2

decode

public static int decode(byte[] src,
                         int srcOffset,
                         byte[][] valueRef)
                  throws CorruptEncodingException
Decodes the given byte array.

Parameters:
src - source of encoded data
srcOffset - offset into encoded data
valueRef - decoded byte array is stored in element 0, which may be null
Returns:
amount of bytes read from source
Throws:
CorruptEncodingException - if source data is corrupt

decodeString

public static int decodeString(byte[] src,
                               int srcOffset,
                               String[] valueRef)
                        throws CorruptEncodingException
Decodes an encoded string from the given byte array.

Parameters:
src - source of encoded data
srcOffset - offset into encoded data
valueRef - decoded string is stored in element 0, which may be null
Returns:
amount of bytes read from source
Throws:
CorruptEncodingException - if source data is corrupt

readLength

public static int readLength(InputStream in)
                      throws IOException,
                             EOFException
Decodes a length value which was encoded by DataEncoder.writeLength(int, java.io.OutputStream).

Returns:
length value
Throws:
IOException
EOFException
Since:
1.2

readFully

public static void readFully(InputStream in,
                             byte[] b)
                      throws IOException,
                             EOFException
Reads as many bytes from the stream as is necessary to fill the given byte array. An EOFException is thrown if the stream end is encountered.

Throws:
IOException
EOFException
Since:
1.2

decodeSingle

public static byte[] decodeSingle(byte[] src,
                                  int prefixPadding,
                                  int suffixPadding)
                           throws CorruptEncodingException
Decodes the given byte array which was encoded by DataEncoder.encodeSingle(byte[], int, int). Always returns a new byte array instance.

Parameters:
prefixPadding - amount of extra bytes to skip from start of encoded byte array
suffixPadding - amount of extra bytes to skip at end of encoded byte array
Throws:
CorruptEncodingException

decodeSingleNullable

public static byte[] decodeSingleNullable(byte[] src)
                                   throws CorruptEncodingException
Decodes the given byte array which was encoded by DataEncoder.encodeSingleNullable(byte[]). Always returns a new byte array instance.

Throws:
CorruptEncodingException

decodeSingleNullable

public static byte[] decodeSingleNullable(byte[] src,
                                          int prefixPadding,
                                          int suffixPadding)
                                   throws CorruptEncodingException
Decodes the given byte array which was encoded by DataEncoder.encodeSingleNullable(byte[]). Always returns a new byte array instance.

Parameters:
prefixPadding - amount of extra bytes to skip from start of encoded byte array
suffixPadding - amount of extra bytes to skip at end of encoded byte array
Throws:
CorruptEncodingException


Copyright © 2006-2009 Amazon Technologies, Inc.. All Rights Reserved.