Class PofHelper

    • Field Detail

      • BIGINTEGER_MAX_LONG

        public static final BigInteger BIGINTEGER_MAX_LONG
        The BigInteger representation of Long.MAX_VALUE.
      • BIGINTEGER_MIN_LONG

        public static final BigInteger BIGINTEGER_MIN_LONG
        The BigInteger representation of Long.MIN_VALUE.
      • BIGDECIMAL_ZERO

        public static final BigDecimal BIGDECIMAL_ZERO
        The default BigDecimal value.
      • BOOLEAN_ARRAY_EMPTY

        public static final boolean[] BOOLEAN_ARRAY_EMPTY
        An empty array of bytes.
      • BYTE_ARRAY_EMPTY

        public static final byte[] BYTE_ARRAY_EMPTY
        An empty array of bytes.
      • CHAR_ARRAY_EMPTY

        public static final char[] CHAR_ARRAY_EMPTY
        An empty array of chars.
      • SHORT_ARRAY_EMPTY

        public static final short[] SHORT_ARRAY_EMPTY
        An empty array of shorts.
      • INT_ARRAY_EMPTY

        public static final int[] INT_ARRAY_EMPTY
        An empty array of ints.
      • LONG_ARRAY_EMPTY

        public static final long[] LONG_ARRAY_EMPTY
        An empty array of longs.
      • FLOAT_ARRAY_EMPTY

        public static final float[] FLOAT_ARRAY_EMPTY
        An empty array of floats.
      • DOUBLE_ARRAY_EMPTY

        public static final double[] DOUBLE_ARRAY_EMPTY
        An empty array of doubles.
      • OBJECT_ARRAY_EMPTY

        public static final Object[] OBJECT_ARRAY_EMPTY
        An empty array of objects.
      • COLLECTION_EMPTY

        public static final Collection COLLECTION_EMPTY
        An empty (and immutable) collection.
      • BINARY_EMPTY

        public static final Binary BINARY_EMPTY
        An empty Binary value.
    • Constructor Detail

      • PofHelper

        public PofHelper()
    • Method Detail

      • getJavaTypeId

        public static int getJavaTypeId​(Object o,
                                        PofContext ctx)
        Return an identifier that represents the Java type of the specified object.
        Parameters:
        o - an object to determine the type of
        ctx - the PofContext used to determine if the object is an instance of a valid user type; must not be null
        Returns:
        one of the PofConstants class J_* constants
      • getPofTypeId

        public static int getPofTypeId​(Class clz,
                                       PofContext ctx)
        Return an identifier that represents the POF type of the specified class.
        Parameters:
        clz - the class; must not be null
        ctx - the PofContext used to determine the type identifier of a user type; must not be null
        Returns:
        one of the PofConstants class T_* constants
        Throws:
        IllegalArgumentException - if the user type associated with the given object is unknown to the specified PofContext
      • isIntrinsicPofType

        public static boolean isIntrinsicPofType​(Class clz)
        Determine if the given class can be represented as an intrinsic POF type.
        Parameters:
        clz - the class; must not be null
        Returns:
        true if the given class can be represented as an intrinsic POF type; false, otherwise
      • convertNumber

        public static Number convertNumber​(Number number,
                                           int nJavaTypeId)
        Convert the passed number to the specified type.
        Parameters:
        number - the number to convert
        nJavaTypeId - the Java type ID to convert to, one of the J_* enumerated values
        Returns:
        the number converted to the specified type
      • convertToDate

        public static Date convertToDate​(Object o)
        Convert a date, time or date/time value to a Java Date.
        Parameters:
        o - an Object of type Date, RawDate, RawTime or RawDateTime
        Returns:
        a Java Date Object
      • resizeArray

        public static <T> T[] resizeArray​(T[] aoOld,
                                          int cNew)
        Expand the passed array to contain the specified number of elements.
        Type Parameters:
        T - the array type
        Parameters:
        aoOld - the "template" array or null
        cNew - the number of desired elements in the new array
        Returns:
        the old array, if it was big enough, or a new array of the same type
      • decodeTinyInt

        public static int decodeTinyInt​(int n)
        Decode an integer value from one of the reserved single-byte combined type and value indicators.
        Parameters:
        n - the integer value that the integer is encoded as
        Returns:
        an integer between -1 and 22 inclusive
      • readChar

        public static char readChar​(DataInput in)
                             throws IOException
        Read a "char" value from the passed DataInput.
        Parameters:
        in - the DataInput object to read from
        Returns:
        a char value
        Throws:
        IOException - on read error
      • readBigInteger

        public static BigInteger readBigInteger​(DataInput in)
                                         throws IOException
        Read a BigInteger value from the passed DataInput.
        Parameters:
        in - the DataInput object to read from
        Returns:
        the BigInteger value
        Throws:
        IOException - on read error
      • readQuad

        public static RawQuad readQuad​(ReadBuffer.BufferInput in)
                                throws IOException
        Read a quad (a 128-bit base-2 IEEE754 value) from the passed DataInput and convert it to a RawQuad.
        Parameters:
        in - the DataInput object to read from
        Returns:
        the quad value as a RawQuad
        Throws:
        IOException - on read error
      • readBigDecimal

        public static BigDecimal readBigDecimal​(ReadBuffer.BufferInput in,
                                                int cBytes)
                                         throws IOException
        Read an IEEE754 value from the passed DataInput and convert it to a Java BigDecimal.
        Parameters:
        in - the DataInput object to read from
        cBytes - the number of bytes for the IEEE754 value: 4, 8 or 16
        Returns:
        the BigDecimal value
        Throws:
        IOException - on read error
      • readLocalDate

        public static LocalDate readLocalDate​(ReadBuffer.BufferInput in)
                                       throws IOException
        Read a LocalDate value from a POF stream.
        Parameters:
        in - the stream containing the POF date value
        Returns:
        a LocalDate object
        Throws:
        IOException - on read error
      • readLocalDateTime

        public static LocalDateTime readLocalDateTime​(ReadBuffer.BufferInput in)
                                               throws IOException
        Read a LocalDateTime value from a POF stream.
        Parameters:
        in - the stream containing the POF date value
        Returns:
        a LocalDateTime object
        Throws:
        IOException - on read error
      • readLocalTime

        public static LocalTime readLocalTime​(ReadBuffer.BufferInput in)
                                       throws IOException
        Read a LocalTime value from a POF stream.
        Parameters:
        in - the stream containing the POF date value
        Returns:
        a LocalTime object
        Throws:
        IOException - on read error
      • readOffsetDateTime

        public static OffsetDateTime readOffsetDateTime​(ReadBuffer.BufferInput in)
                                                 throws IOException
        Read a OffsetDateTime value from a POF stream.
        Parameters:
        in - the stream containing the POF date value
        Returns:
        a OffsetDateTime object
        Throws:
        IOException - on read error
      • readOffsetTime

        public static OffsetTime readOffsetTime​(ReadBuffer.BufferInput in)
                                         throws IOException
        Read a OffsetTime value from a POF stream.
        Parameters:
        in - the stream containing the POF date value
        Returns:
        a OffsetTime object
        Throws:
        IOException - on read error
      • readRawDate

        public static RawDate readRawDate​(ReadBuffer.BufferInput in)
                                   throws IOException
        Read a RawDate value from a POF stream.
        Parameters:
        in - the stream containing the POF date value
        Returns:
        a RawDate object
        Throws:
        IOException - on read error
      • readRawTime

        public static RawTime readRawTime​(ReadBuffer.BufferInput in)
                                   throws IOException
        Read a RawTime value from a POF stream.
        Parameters:
        in - the stream containing the POF time value
        Returns:
        a RawTime object
        Throws:
        IOException - on read error
      • readAsChar

        public static char readAsChar​(ReadBuffer.BufferInput in,
                                      int nType)
                               throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a char.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as an char
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a char value
      • readAsInt

        public static int readAsInt​(ReadBuffer.BufferInput in,
                                    int nType)
                             throws IOException
        Read a value of the specified encoding from the POF stream and convert it to an integer.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as an integer
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to an integer value
      • readAsLong

        public static long readAsLong​(ReadBuffer.BufferInput in,
                                      int nType)
                               throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a long.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as a long
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a long value
      • readAsFloat

        public static float readAsFloat​(ReadBuffer.BufferInput in,
                                        int nType)
                                 throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a float.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as a float
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a float value
      • readAsDouble

        public static double readAsDouble​(ReadBuffer.BufferInput in,
                                          int nType)
                                   throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a double.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as a double
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a double value
      • readAsQuad

        public static RawQuad readAsQuad​(ReadBuffer.BufferInput in,
                                         int nType)
                                  throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a quad.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as a RawQuad
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a double value
      • readAsBigInteger

        public static BigInteger readAsBigInteger​(ReadBuffer.BufferInput in,
                                                  int nType)
                                           throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a BigInteger.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as a BigInteger
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a BigInteger value
      • readAsBigDecimal

        public static BigDecimal readAsBigDecimal​(ReadBuffer.BufferInput in,
                                                  int nType)
                                           throws IOException
        Read a value of the specified encoding from the POF stream and convert it to a BigDecimal.
        Parameters:
        in - the POF stream containing the value
        nType - the POF type of the value
        Returns:
        the POF value as a BigDecimal
        Throws:
        IOException - if an I/O error occurs reading the POF stream, or the POF value cannot be coerced to a BigDecimal value
      • skipValue

        public static void skipValue​(ReadBuffer.BufferInput in)
                              throws IOException
        Within the POF stream, skip the next POF value.
        Parameters:
        in - the BufferInput containing the POF stream
        Throws:
        IOException - on read error
      • skipUniformValue

        public static void skipUniformValue​(ReadBuffer.BufferInput in,
                                            int nType)
                                     throws IOException
        Within the POF stream, skip the next POF value of the specified type.
        Parameters:
        in - the BufferInput containing the POF stream
        nType - the type of the value to skip
        Throws:
        IOException - on read error
      • skipPackedInts

        public static void skipPackedInts​(ReadBuffer.BufferInput in,
                                          int c)
                                   throws IOException
        Skip the specified number of packed integers in the passed POF stream.
        Parameters:
        in - the BufferInput containing the POF stream
        c - the number of packed integers to skip over
        Throws:
        IOException - on read error
      • writeBigDecimal

        public static void writeBigDecimal​(WriteBuffer.BufferOutput out,
                                           BigDecimal dec,
                                           int cBytes)
                                    throws IOException
        Write a BigDecimal to the passed DataOutput stream as a decimal value.
        Parameters:
        out - the DataOutput to write to
        dec - the BigDecimal value
        cBytes - the number of bytes for the IEEE754 value: 4, 8 or 16
        Throws:
        IOException - on write error
      • encodeTinyInt

        public static int encodeTinyInt​(int n)
        Encode an integer value into one of the reserved single-byte combined type and value indicators.
        Parameters:
        n - an integer between -1 and 22 inclusive
        Returns:
        the integer value that the integer is encoded as
      • writeDate

        public static void writeDate​(WriteBuffer.BufferOutput out,
                                     int nYear,
                                     int nMonth,
                                     int nDay)
                              throws IOException
        Write a date value to a BufferOutput object.
        Parameters:
        out - the BufferOutput to write to
        nYear - the year number as defined by ISO8601; note the difference with the Java Date class, whose year is relative to 1900
        nMonth - the month number between 1 and 12 inclusive as defined by ISO8601; note the difference from the Java Date class, whose month value is 0-based (0-11)
        nDay - the day number between 1 and 31 inclusive as defined by ISO8601
        Throws:
        IOException - thrown if the passed BufferOutput object throws an IOException while the value is being written to it
      • writeTime

        public static void writeTime​(WriteBuffer.BufferOutput out,
                                     int nHour,
                                     int nMinute,
                                     int nSecond,
                                     int nNano,
                                     int nTimeZoneType,
                                     int nHourOffset,
                                     int nMinuteOffset)
                              throws IOException
        Write a time value to a BufferOutput object.
        Parameters:
        out - the BufferOutput to write to
        nHour - the hour between 0 and 23 inclusive
        nMinute - the minute value between 0 and 59 inclusive
        nSecond - the second value between 0 and 59 inclusive (and theoretically 60 for a leap-second)
        nNano - the nanosecond value between 0 and 999999999 inclusive
        nTimeZoneType - 0 if the time value does not have an explicit time zone, 1 if the time value is UTC and 2 if the time zone has an explicit hour and minute offset
        nHourOffset - the timezone offset in hours from UTC, for example 0 for BST, -5 for EST and 1 for CET
        nMinuteOffset - the timezone offset in minutes, for example 0 (in most cases) or 30
        Throws:
        IOException - thrown if the passed BufferOutput object throws an IOException while the value is being written to it
      • checkType

        public static void checkType​(int nType)
        Validate a type identifier.
        Parameters:
        nType - the type identifier
      • checkElementCount

        public static void checkElementCount​(int cElements)
        Verify that the number of elements is valid.
        Parameters:
        cElements - the number of elements in a complex data structure
      • checkReferenceRange

        public static void checkReferenceRange​(int nId)
        Validate a reference identifier to make sure it is in a valid range.
        Parameters:
        nId - the reference identity
      • checkDecimalRange

        public static void checkDecimalRange​(BigDecimal dec,
                                             int cBytes)
        Verify that the specified decimal value will fit in the specified number of bits.
        Parameters:
        dec - the decimal value
        cBytes - the number of bytes (4, 8 or 16)
      • calcDecimalSize

        public static int calcDecimalSize​(BigDecimal dec)
        Determine the minimum size (in bytes) of the IEEE754 decimal type that would be capable of holding the passed value.
        Parameters:
        dec - the decimal value
        Returns:
        the number of bytes (4, 8 or 16)
      • checkDate

        public static void checkDate​(int nYear,
                                     int nMonth,
                                     int nDay)
        Validate date information.
        Parameters:
        nYear - the year number
        nMonth - the month number
        nDay - the day number
      • checkTime

        public static void checkTime​(int nHour,
                                     int nMinute,
                                     int nSecond,
                                     int nNano)
        Validate time information.
        Parameters:
        nHour - the hour number
        nMinute - the minute number
        nSecond - the second number
        nNano - the nanosecond number
      • checkTimeZone

        public static void checkTimeZone​(int nHourOffset,
                                         int nMinuteOffset)
        Check the specified timezone offset.
        Parameters:
        nHourOffset - the hour offset
        nMinuteOffset - the minute offset
      • checkYearMonthInterval

        public static void checkYearMonthInterval​(int cYears,
                                                  int cMonths)
        Validate a year-month interval.
        Parameters:
        cYears - the number of years
        cMonths - the number of months
      • checkTimeInterval

        public static void checkTimeInterval​(int cHours,
                                             int cMinutes,
                                             int cSeconds,
                                             int cNanos)
        Validate a time interval.
        Parameters:
        cHours - the number of hours
        cMinutes - the number of minutes
        cSeconds - the number of seconds
        cNanos - the number of nanoseconds
      • checkDayTimeInterval

        public static void checkDayTimeInterval​(int cDays,
                                                int cHours,
                                                int cMinutes,
                                                int cSeconds,
                                                int cNanos)
        Validate a day-time interval.

        See http://www.builderau.com.au/architect/database/soa/SQL_basics_Datetime_and_interval_data_types/0,39024547,20269031,00.htm

        Parameters:
        cDays - the number of days
        cHours - the number of hours
        cMinutes - the number of minutes
        cSeconds - the number of seconds
        cNanos - the number of nanoseconds
      • formatDate

        public static String formatDate​(int nYear,
                                        int nMonth,
                                        int nDay)
        Format a date in the form YYYY-MM-DD.
        Parameters:
        nYear - the year number
        nMonth - the month number
        nDay - the day number
        Returns:
        the formatted string
      • formatTime

        public static String formatTime​(int nHour,
                                        int nMinute,
                                        int nSecond,
                                        int nNano,
                                        boolean fUTC)
        Format a time using the simplest applicable of the following formats:
        1. HH:MM
        2. HH:MM:SS
        3. HH:MM:SS.MMM
        4. HH:MM:SS.NNNNNNNNN
        Parameters:
        nHour - the hour number
        nMinute - the minute number
        nSecond - the second number
        nNano - the nanosecond number
        fUTC - true for UTC, false for no time zone
        Returns:
        a time String
      • formatTime

        public static String formatTime​(int nHour,
                                        int nMinute,
                                        int nSecond,
                                        int nNano,
                                        int nHourOffset,
                                        int nMinuteOffset)
        Format a time using the simplest applicable of the following formats:
        1. HH:MM(+|-)HH:MM
        2. HH:MM:SS(+|-)HH:MM
        3. HH:MM:SS.MMM(+|-)HH:MM
        4. HH:MM:SS.NNNNNNNNN(+|-)HH:MM
        Parameters:
        nHour - the hour number
        nMinute - the minute number
        nSecond - the second number
        nNano - the nanosecond number
        nHourOffset - the timezone offset in hours
        nMinuteOffset - the timezone offset in minutes
        Returns:
        a time String