Package org.postgresql.util
Class ByteConverter
- java.lang.Object
-
- org.postgresql.util.ByteConverter
-
public class ByteConverter extends java.lang.ObjectHelper methods to parse java base types from byte arrays.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEC_DIGITSprivate static intLONG_BYTESprivate static intNBASEprivate static intNUMERIC_DSCALE_MASKprivate static shortNUMERIC_NANprivate static shortNUMERIC_NEGprivate static shortNUMERIC_POSprivate static int[]round_powersprivate static intSHORT_BYTES
-
Constructor Summary
Constructors Modifier Constructor Description privateByteConverter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanbool(byte[] bytes, int idx)Parses a boolean value from the byte array.static voidbool(byte[] target, int idx, boolean value)Encodes a boolean value to the byte array.static intbytesToInt(byte[] bytes)Convert a variable length array of bytes to an integerprivate static voiddigitToString(int idx, short[] digits, java.nio.CharBuffer buffer, boolean alwaysPutIt)Convert a number from binary representation to text representation.static floatfloat4(byte[] bytes, int idx)Parses a float value from the byte array.static voidfloat4(byte[] target, int idx, float value)Encodes a int value to the byte array.static doublefloat8(byte[] bytes, int idx)Parses a double value from the byte array.static voidfloat8(byte[] target, int idx, double value)Encodes a int value to the byte array.static shortint2(byte[] bytes, int idx)Parses a short value from the byte array.static voidint2(byte[] target, int idx, int value)Encodes a int value to the byte array.static intint4(byte[] bytes, int idx)Parses an int value from the byte array.static voidint4(byte[] target, int idx, int value)Encodes a int value to the byte array.static longint8(byte[] bytes, int idx)Parses a long value from the byte array.static voidint8(byte[] target, int idx, long value)Encodes a long value to the byte array.private static java.lang.StringnumberBytesToString(short[] digits, int scale, int weight, int sign)Convert a number from binary representation to text representation.static java.lang.Numbernumeric(byte[] bytes)Convert a variable length array of bytes to an integerstatic java.lang.Numbernumeric(byte[] bytes, int pos, int numBytes)Convert a variable length array of bytes to an integer
-
-
-
Field Detail
-
NBASE
private static final int NBASE
- See Also:
- Constant Field Values
-
NUMERIC_DSCALE_MASK
private static final int NUMERIC_DSCALE_MASK
- See Also:
- Constant Field Values
-
NUMERIC_POS
private static final short NUMERIC_POS
- See Also:
- Constant Field Values
-
NUMERIC_NEG
private static final short NUMERIC_NEG
- See Also:
- Constant Field Values
-
NUMERIC_NAN
private static final short NUMERIC_NAN
- See Also:
- Constant Field Values
-
DEC_DIGITS
private static final int DEC_DIGITS
- See Also:
- Constant Field Values
-
round_powers
private static final int[] round_powers
-
SHORT_BYTES
private static final int SHORT_BYTES
- See Also:
- Constant Field Values
-
LONG_BYTES
private static final int LONG_BYTES
- See Also:
- Constant Field Values
-
-
Method Detail
-
bytesToInt
public static int bytesToInt(byte[] bytes)
Convert a variable length array of bytes to an integer- Parameters:
bytes- array of bytes that can be decoded as an integer- Returns:
- integer
-
digitToString
private static void digitToString(int idx, short[] digits, java.nio.CharBuffer buffer, boolean alwaysPutIt)Convert a number from binary representation to text representation.- Parameters:
idx- index of the digit to be converted in the digits arraydigits- array of shorts that can be decoded as the number Stringbuffer- the character buffer to put the text representation inalwaysPutIt- a flag that indicate whether or not to put the digit char even if it is zero
-
numberBytesToString
private static java.lang.String numberBytesToString(short[] digits, int scale, int weight, int sign)Convert a number from binary representation to text representation.- Parameters:
digits- array of shorts that can be decoded as the number Stringscale- the scale of the number binary representationweight- the weight of the number binary representationsign- the sign of the number- Returns:
- String the number as String
-
numeric
public static java.lang.Number numeric(byte[] bytes)
Convert a variable length array of bytes to an integer- Parameters:
bytes- array of bytes that can be decoded as an integer- Returns:
- integer
-
numeric
public static java.lang.Number numeric(byte[] bytes, int pos, int numBytes)Convert a variable length array of bytes to an integer- Parameters:
bytes- array of bytes that can be decoded as an integerpos- index of the start position of the bytes array for numbernumBytes- number of bytes to use, length is already encoded in the binary format but this is used for double checking- Returns:
- integer
-
int8
public static long int8(byte[] bytes, int idx)Parses a long value from the byte array.- Parameters:
bytes- The byte array to parse.idx- The starting index of the parse in the byte array.- Returns:
- parsed long value.
-
int4
public static int int4(byte[] bytes, int idx)Parses an int value from the byte array.- Parameters:
bytes- The byte array to parse.idx- The starting index of the parse in the byte array.- Returns:
- parsed int value.
-
int2
public static short int2(byte[] bytes, int idx)Parses a short value from the byte array.- Parameters:
bytes- The byte array to parse.idx- The starting index of the parse in the byte array.- Returns:
- parsed short value.
-
bool
public static boolean bool(byte[] bytes, int idx)Parses a boolean value from the byte array.- Parameters:
bytes- The byte array to parse.idx- The starting index to read from bytes.- Returns:
- parsed boolean value.
-
float4
public static float float4(byte[] bytes, int idx)Parses a float value from the byte array.- Parameters:
bytes- The byte array to parse.idx- The starting index of the parse in the byte array.- Returns:
- parsed float value.
-
float8
public static double float8(byte[] bytes, int idx)Parses a double value from the byte array.- Parameters:
bytes- The byte array to parse.idx- The starting index of the parse in the byte array.- Returns:
- parsed double value.
-
int8
public static void int8(byte[] target, int idx, long value)Encodes a long value to the byte array.- Parameters:
target- The byte array to encode to.idx- The starting index in the byte array.value- The value to encode.
-
int4
public static void int4(byte[] target, int idx, int value)Encodes a int value to the byte array.- Parameters:
target- The byte array to encode to.idx- The starting index in the byte array.value- The value to encode.
-
int2
public static void int2(byte[] target, int idx, int value)Encodes a int value to the byte array.- Parameters:
target- The byte array to encode to.idx- The starting index in the byte array.value- The value to encode.
-
bool
public static void bool(byte[] target, int idx, boolean value)Encodes a boolean value to the byte array.- Parameters:
target- The byte array to encode to.idx- The starting index in the byte array.value- The value to encode.
-
float4
public static void float4(byte[] target, int idx, float value)Encodes a int value to the byte array.- Parameters:
target- The byte array to encode to.idx- The starting index in the byte array.value- The value to encode.
-
float8
public static void float8(byte[] target, int idx, double value)Encodes a int value to the byte array.- Parameters:
target- The byte array to encode to.idx- The starting index in the byte array.value- The value to encode.
-
-