Top Description Inners Fields Constructors Methods
org.postgresql.util

public Class ByteConverter

extends Object
Class Inheritance
Imports
java.math.BigDecimal, .BigInteger, java.util.Arrays

Helper methods to parse java base types from byte arrays.
Authors
Mikko Tiihonen, Brett Okken

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
ByteConverter.PositiveShorts

Simple stack structure for non-negative short values.

Field Summary

Modifier and TypeField and Description
private static final BigInteger
private static final BigInteger[]
private static final BigInteger
private static final int[]
private static final int
private static final long[]
private static final int
private static final short
private static final short
private static final short
private static final int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

parsed boolean value.
bool
(byte[]
The byte array to parse.
bytes
,
int
The starting index to read from bytes.
idx
)

Parses a boolean value from the byte array.

public static void
bool(byte[]
The byte array to encode to.
target
,
int
The starting index in the byte array.
idx
,
boolean
The value to encode.
value
)

Encodes a boolean value to the byte array.

public static int

Returns:

integer
bytesToInt
(byte[]
array of bytes that can be decoded as an integer
bytes
)

Convert a variable length array of bytes to an integer

public static float

Returns:

parsed float value.
float4
(byte[]
The byte array to parse.
bytes
,
int
The starting index of the parse in the byte array.
idx
)

Parses a float value from the byte array.

public static void
float4(byte[]
The byte array to encode to.
target
,
int
The starting index in the byte array.
idx
,
float
The value to encode.
value
)

Encodes a int value to the byte array.

public static double

Returns:

parsed double value.
float8
(byte[]
The byte array to parse.
bytes
,
int
The starting index of the parse in the byte array.
idx
)

Parses a double value from the byte array.

public static void
float8(byte[]
The byte array to encode to.
target
,
int
The starting index in the byte array.
idx
,
double
The value to encode.
value
)

Encodes a int value to the byte array.

public static short

Returns:

parsed short value.
int2
(byte[]
The byte array to parse.
bytes
,
int
The starting index of the parse in the byte array.
idx
)

Parses a short value from the byte array.

public static void
int2(byte[]
The byte array to encode to.
target
,
int
The starting index in the byte array.
idx
,
int
The value to encode.
value
)

Encodes a int value to the byte array.

public static int

Returns:

parsed int value.
int4
(byte[]
The byte array to parse.
bytes
,
int
The starting index of the parse in the byte array.
idx
)

Parses an int value from the byte array.

public static void
int4(byte[]
The byte array to encode to.
target
,
int
The starting index in the byte array.
idx
,
int
The value to encode.
value
)

Encodes a int value to the byte array.

public static long

Returns:

parsed long value.
int8
(byte[]
The byte array to parse.
bytes
,
int
The starting index of the parse in the byte array.
idx
)

Parses a long value from the byte array.

public static void
int8(byte[]
The byte array to encode to.
target
,
int
The starting index in the byte array.
idx
,
long
The value to encode.
value
)

Encodes a long value to the byte array.

public static Number

Returns:

integer
numeric
(byte[]
array of bytes that can be decoded as an integer
bytes
)

Convert a variable length array of bytes to an integer

public static Number

Returns:

BigDecimal representation of numeric or Double#NaN.
numeric
(byte[]
array of bytes to be decoded from binary numeric representation.
bytes
,
int
index of the start position of the bytes array for number
pos
,
int
number of bytes to use, length is already encoded in the binary format but this is used for double checking
numBytes
)

Convert a variable length array of bytes to a Number.

public static byte[]

Returns:

The binary representation of nbr.
numeric
(BigDecimal
The instance to represent in binary.
nbr
)

Converts a non-null BigDecimal to binary format for org.postgresql.core.Oid#NUMERIC.

private static BigInteger
tenPower(int exponent)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BI_MAX_LONGback to summary
private static final BigInteger BI_MAX_LONG
BI_TEN_POWERSback to summary
private static final BigInteger[] BI_TEN_POWERS
BI_TEN_THOUSANDback to summary
private static final BigInteger BI_TEN_THOUSAND
INT_TEN_POWERSback to summary
private static final int[] INT_TEN_POWERS
LONG_BYTESback to summary
private static final int LONG_BYTES
LONG_TEN_POWERSback to summary
private static final long[] LONG_TEN_POWERS
NUMERIC_DSCALE_MASKback to summary
private static final int NUMERIC_DSCALE_MASK
NUMERIC_NANback to summary
private static final short NUMERIC_NAN
NUMERIC_NEGback to summary
private static final short NUMERIC_NEG
NUMERIC_POSback to summary
private static final short NUMERIC_POS
SHORT_BYTESback to summary
private static final int SHORT_BYTES

Constructor Detail

ByteConverterback to summary
private ByteConverter()

Method Detail

boolback to summary
public static boolean bool(byte[] bytes, int idx)

Parses a boolean value from the byte array.

Parameters
bytes:byte[]

The byte array to parse.

idx:int

The starting index to read from bytes.

Returns:boolean

parsed boolean value.

boolback to summary
public static void bool(byte[] target, int idx, boolean value)

Encodes a boolean value to the byte array.

Parameters
target:byte[]

The byte array to encode to.

idx:int

The starting index in the byte array.

value:boolean

The value to encode.

bytesToIntback to summary
public static int bytesToInt(byte[] bytes)

Convert a variable length array of bytes to an integer

Parameters
bytes:byte[]

array of bytes that can be decoded as an integer

Returns:int

integer

float4back to summary
public static float float4(byte[] bytes, int idx)

Parses a float value from the byte array.

Parameters
bytes:byte[]

The byte array to parse.

idx:int

The starting index of the parse in the byte array.

Returns:float

parsed float value.

float4back to summary
public static void float4(byte[] target, int idx, float value)

Encodes a int value to the byte array.

Parameters
target:byte[]

The byte array to encode to.

idx:int

The starting index in the byte array.

value:float

The value to encode.

float8back to summary
public static double float8(byte[] bytes, int idx)

Parses a double value from the byte array.

Parameters
bytes:byte[]

The byte array to parse.

idx:int

The starting index of the parse in the byte array.

Returns:double

parsed double value.

float8back to summary
public static void float8(byte[] target, int idx, double value)

Encodes a int value to the byte array.

Parameters
target:byte[]

The byte array to encode to.

idx:int

The starting index in the byte array.

value:double

The value to encode.

int2back to summary
public static short int2(byte[] bytes, int idx)

Parses a short value from the byte array.

Parameters
bytes:byte[]

The byte array to parse.

idx:int

The starting index of the parse in the byte array.

Returns:short

parsed short value.

int2back to summary
public static void int2(byte[] target, int idx, int value)

Encodes a int value to the byte array.

Parameters
target:byte[]

The byte array to encode to.

idx:int

The starting index in the byte array.

value:int

The value to encode.

int4back to summary
public static int int4(byte[] bytes, int idx)

Parses an int value from the byte array.

Parameters
bytes:byte[]

The byte array to parse.

idx:int

The starting index of the parse in the byte array.

Returns:int

parsed int value.

int4back to summary
public static void int4(byte[] target, int idx, int value)

Encodes a int value to the byte array.

Parameters
target:byte[]

The byte array to encode to.

idx:int

The starting index in the byte array.

value:int

The value to encode.

int8back to summary
public static long int8(byte[] bytes, int idx)

Parses a long value from the byte array.

Parameters
bytes:byte[]

The byte array to parse.

idx:int

The starting index of the parse in the byte array.

Returns:long

parsed long value.

int8back to summary
public static void int8(byte[] target, int idx, long value)

Encodes a long value to the byte array.

Parameters
target:byte[]

The byte array to encode to.

idx:int

The starting index in the byte array.

value:long

The value to encode.

numericback to summary
public static Number numeric(byte[] bytes)

Convert a variable length array of bytes to an integer

Parameters
bytes:byte[]

array of bytes that can be decoded as an integer

Returns:Number

integer

numericback to summary
public static Number numeric(byte[] bytes, int pos, int numBytes)

Convert a variable length array of bytes to a Number. The result will always be a BigDecimal or Double#NaN.

Parameters
bytes:byte[]

array of bytes to be decoded from binary numeric representation.

pos:int

index of the start position of the bytes array for number

numBytes:int

number of bytes to use, length is already encoded in the binary format but this is used for double checking

Returns:Number

BigDecimal representation of numeric or Double#NaN.

numericback to summary
public static byte[] numeric(BigDecimal nbr)

Converts a non-null BigDecimal to binary format for org.postgresql.core.Oid#NUMERIC.

Parameters
nbr:BigDecimal

The instance to represent in binary.

Returns:byte[]

The binary representation of nbr.

tenPowerback to summary
private static BigInteger tenPower(int exponent)
org.postgresql.util back to summary

private final Class ByteConverter.PositiveShorts

extends Object
Class Inheritance

Simple stack structure for non-negative short values.

Field Summary

Modifier and TypeField and Description
private int
private short[]

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private void
grow()

public boolean
public short
pop()

public void
push(short s)

public int
size()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

idxback to summary
private int idx
shortsback to summary
private short[] shorts

Constructor Detail

PositiveShortsback to summary
pack-priv PositiveShorts()

Method Detail

growback to summary
private void grow()
isEmptyback to summary
public boolean isEmpty()
popback to summary
public short pop()
pushback to summary
public void push(short s)
sizeback to summary
public int size()