com.informix.lang

## Class IfxToJavaType

- java.lang.Object
- - com.informix.lang.IfxToJavaType

    public final class IfxToJavaType
    extends java.lang.Object

This static class handles all the Informix to Java data conversion. A separate method is provided for converting each IFX data type.

### Field Summary

Fields
`static int` `DAYS1900` Constant: number of days between 1/1/0000 and 1/1/1900
`static int` `DAYS4CENT` Constant: 365*400 +100-3
`static int` `DAYS4YEAR` Constant: 365*4 +1

### Constructor Summary

Constructors
Constructor and Description
`IfxToJavaType()`

### Method Summary

Methods
`static int` `convertDateToDays(java.sql.Date dt)` Converts java.sql.Date to a int that encodes the number of days since 1/1/1900 (as 1).
`static java.sql.Date` `convertDaysToDate(int dt)` Does the actual conversion from days -> (yr, date, month)
`static java.lang.String` `IfxToDateTimeUnloadString(byte[] b, int offset, int length, short prec)` Convert Informix DateTime to string which is in format compatible with SQL LOAD/UNLOAD format solution adopted for now.
`java.lang.String` `IfxToJavaChar(byte[] b, boolean encoption)`
`java.lang.String` `IfxToJavaChar(byte[] b, int offset, int length, boolean encoption)`
`static java.lang.String` `IfxToJavaChar(byte[] b, int offset, int length, java.lang.String dbEnc, boolean encoption)` Convert Informix CHAR (n)/ CHARACTER (n) to Java String Conversion method: Create String from given bytes
`java.lang.String` `IfxToJavaChar(byte[] b, java.lang.String dbEnc, boolean encoption)`
`static java.sql.Date` `IfxToJavaDate(byte[] b)`
`static java.sql.Date` `IfxToJavaDate(byte[] b, int offset)` Convert Informix DATE to Java Date IFX date arrives as a long encoding number of days since Dec31, 1899 treated as 0.
`static java.sql.Timestamp` `IfxToJavaDateTime(byte[] b, int offset, int length, short prec)` Convert Informix DateTime to Java Timestamp Note: IFX DateTime can specify a date in a subset of the full range [YR ..
`static java.sql.Timestamp` `IfxToJavaDateTime(byte[] b, int offset, int length, short prec, java.util.Calendar cal)`
`static java.sql.Timestamp` `IfxToJavaDateTime(byte[] b, short prec)` Convert Informix DateTime to Java Timestamp
`static java.math.BigDecimal` `IfxToJavaDecimal(byte[] b, int offset, int length, short prec)` Convert Informix Decimal to Java Bignum
`static java.math.BigDecimal` `IfxToJavaDecimal(byte[] b, short prec)` Convert Informix Decimal to Java Bignum
`static double` `IfxToJavaDouble(byte[] b)`
`static double` `IfxToJavaDouble(byte[] b, int offset)` Convert Informix Double to Java Double
`static int` `IfxToJavaInt(byte[] b)`
`static int` `IfxToJavaInt(byte[] b, int offset)`
`static Interval` `IfxToJavaInterval(byte[] b, int offset, int length, short prec)`
`static Interval` `IfxToJavaInterval(byte[] b, short prec)`
`static long` `IfxToJavaLongBigInt(byte[] b)`
`static long` `IfxToJavaLongBigInt(byte[] b, int offset)` Convert Informix bigint to Java long
`static long` `IfxToJavaLongInt(byte[] b)`
`static long` `IfxToJavaLongInt(byte[] buf, int offset)` Convert Informix int8 to Java long
`static float` `IfxToJavaReal(byte[] b)`
`static float` `IfxToJavaReal(byte[] b, int offset)` Convert Informix Real to Java Real
`static short` `IfxToJavaSmallInt(byte[] b)`
`static short` `IfxToJavaSmallInt(byte[] b, int offset)` Convert Informix SmallInt to Java short
`static boolean` `rleapyear(int yr)` checks if yr is a leap year
`protected static short` `widenByte(byte b)` Moves byte into short in such a way that the high bit is NOT propagated

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DAYS1900

    public static final int DAYS1900

Constant: number of days between 1/1/0000 and 1/1/1900

See Also:
  Constant Field Values

#### DAYS4CENT

    public static final int DAYS4CENT

Constant: 365*400 +100-3

See Also:
  Constant Field Values

#### DAYS4YEAR

    public static final int DAYS4YEAR

Constant: 365*4 +1

See Also:
  Constant Field Values

### Constructor Detail

#### IfxToJavaType

    public IfxToJavaType()

### Method Detail

#### IfxToJavaChar

    public java.lang.String IfxToJavaChar(byte[] b,
                                 boolean encoption)
                                   throws java.io.IOException

Throws:
  `java.io.IOException`

#### IfxToJavaChar

    public java.lang.String IfxToJavaChar(byte[] b,
                                 int offset,
                                 int length,
                                 boolean encoption)
                                   throws java.io.IOException

Throws:
  `java.io.IOException`

#### IfxToJavaChar

    public java.lang.String IfxToJavaChar(byte[] b,
                                 java.lang.String dbEnc,
                                 boolean encoption)
                                   throws java.io.IOException

Throws:
  `java.io.IOException`

#### IfxToJavaChar

    public static java.lang.String IfxToJavaChar(byte[] b,
                                 int offset,
                                 int length,
                                 java.lang.String dbEnc,
                                 boolean encoption)
                                          throws java.io.IOException

Convert Informix CHAR (n)/ CHARACTER (n) to Java String Conversion method: Create String from given bytes

Parameters:
  `b` - bytes encoding data
  `offset` - offset into byte array
  `length` - size of char data
  `dbEnc` - - JDK encoding
  `encoption` - - true if IFX_USE_STRENC connection property is set.
Returns:
  String the string value of the bytes
Throws:
  `java.io.IOException`

#### IfxToJavaDate

    public static java.sql.Date IfxToJavaDate(byte[] b)

#### IfxToJavaDate

    public static java.sql.Date IfxToJavaDate(byte[] b,
                              int offset)

Convert Informix DATE to Java Date IFX date arrives as a long encoding number of days since Dec31, 1899 treated as 0. Negative numbers are allowed and count backwards from the same date. Unfortunately, java.util.Date does NOT yet provide a method to accept "number of days" so need to grind out the yr,month,days triplet. Conversion path: IFX -> long -> Date

Parameters:
  `b` - bytes encoding data
  `offset` - offset into the byte array
  `length` - data length

#### rleapyear

    public static final boolean rleapyear(int yr)

checks if yr is a leap year

#### convertDaysToDate

    public static java.sql.Date convertDaysToDate(int dt)

Does the actual conversion from days -> (yr, date, month)

Parameters:
  `dt` - number of days since 1/1/1900 (as 1) Does handle negative days, interp as backwards from 12/31/1899 as 0 No dates before 1/1/0000 allowed, however for now, relies on IFX not generating out of allowed range date.

#### convertDateToDays

    public static int convertDateToDays(java.sql.Date dt)

Converts java.sql.Date to a int that encodes the number of days since 1/1/1900 (as 1). Dates earlier than that are encoded as negative numbers.

Parameters:
  `dt` - java.sql date

#### IfxToJavaDateTime

    public static java.sql.Timestamp IfxToJavaDateTime(byte[] b,
                                       short prec)

Convert Informix DateTime to Java Timestamp

#### IfxToJavaDateTime

    public static java.sql.Timestamp IfxToJavaDateTime(byte[] b,
                                       int offset,
                                       int length,
                                       short prec)

Convert Informix DateTime to Java Timestamp Note: IFX DateTime can specify a date in a subset of the full range [YR .. NANOSEC] allowed by Java Timestamp. This creates two problems a. What to do with partial IFX DateTimes when converting to Java Timestamp? Backfill current date? Set unspecified fields to 0? b. How to send Java Timestamp back to IFX when the IFX is only expecting a partial DateTime (based on the precision there). The problem here is how best to preserve the precision info that came from IFX and use it on the way back. See the note " ..." for more details, possible solutions, and solution adopted for now. Conversion path: IFX-> Decimal-> Timestamp

Parameters:
  `b` - bytes encoding data
  `offset` - offset into the byte array
  `length` - data length
  `prec` - precision as received from IFX

#### IfxToJavaDateTime

    public static java.sql.Timestamp IfxToJavaDateTime(byte[] b,
                                       int offset,
                                       int length,
                                       short prec,
                                       java.util.Calendar cal)

#### IfxToDateTimeUnloadString

    public static java.lang.String IfxToDateTimeUnloadString(byte[] b,
                                             int offset,
                                             int length,
                                             short prec)

Convert Informix DateTime to string which is in format compatible with SQL LOAD/UNLOAD format solution adopted for now. Conversion path: IFX-> Decimal-> String

Parameters:
  `b` - bytes encoding data
  `offset` - offset into the byte array
  `length` - data length
  `prec` - precision as received from IFX

#### IfxToJavaInterval

    public static Interval IfxToJavaInterval(byte[] b,
                             short prec)

#### IfxToJavaInterval

    public static Interval IfxToJavaInterval(byte[] b,
                             int offset,
                             int length,
                             short prec)

#### IfxToJavaDecimal

    public static java.math.BigDecimal IfxToJavaDecimal(byte[] b,
                                        short prec)

Convert Informix Decimal to Java Bignum

Parameters:
  `b` - bytes encoding data
  `prec` - precision as received from IFX

#### IfxToJavaDecimal

    public static java.math.BigDecimal IfxToJavaDecimal(byte[] b,
                                        int offset,
                                        int length,
                                        short prec)

Convert Informix Decimal to Java Bignum

Parameters:
  `b` - bytes encoding data
  `offset` - into byte array
  `length` - length of data
  `prec` - precision as received from IFX

#### IfxToJavaDouble

    public static double IfxToJavaDouble(byte[] b)

#### IfxToJavaDouble

    public static double IfxToJavaDouble(byte[] b,
                         int offset)

Convert Informix Double to Java Double

Parameters:
  `b` - bytes encoding data
  `offset` - offset into byte array
  `length` - data length

#### IfxToJavaReal

    public static float IfxToJavaReal(byte[] b)

#### IfxToJavaReal

    public static float IfxToJavaReal(byte[] b,
                      int offset)

Convert Informix Real to Java Real

Parameters:
  `b` - bytes encoding data
  `prec` - precision as received from IFX

#### widenByte

    protected static final short widenByte(byte b)

Moves byte into short in such a way that the high bit is NOT propagated

#### IfxToJavaSmallInt

    public static short IfxToJavaSmallInt(byte[] b)

#### IfxToJavaSmallInt

    public static short IfxToJavaSmallInt(byte[] b,
                          int offset)

Convert Informix SmallInt to Java short

Parameters:
  `b` - bytes encoding data
  `offset` - into byte array
  `length` - data length
  `prec` - precision as received from IFX

#### IfxToJavaInt

    public static int IfxToJavaInt(byte[] b)

#### IfxToJavaInt

    public static int IfxToJavaInt(byte[] b,
                   int offset)

#### IfxToJavaLongInt

    public static long IfxToJavaLongInt(byte[] b)

#### IfxToJavaLongInt

    public static long IfxToJavaLongInt(byte[] buf,
                        int offset)

Convert Informix int8 to Java long

Parameters:
  `b` - bytes encoding data
  `offset` - offset into byte array

#### IfxToJavaLongBigInt

    public static long IfxToJavaLongBigInt(byte[] b)

#### IfxToJavaLongBigInt

    public static long IfxToJavaLongBigInt(byte[] b,
                           int offset)

Convert Informix bigint to Java long

Parameters:
  `b` - bytes encoding data
  `offset` - offset into byte array