An example that overrides the default I/O methods

The following example illustrates a Java UDT class with nondefault definitions. JavaType is the new Java UDT, and JavaBuffer is the buffer type for the SQL data being converted, as I/O function sets and related types shows. For a complete set of required and optional code, see Usage example.
public class JavaType implements SQLData
{
// Java data Object declarations for this Class....
// non-default Data Input function
   public static JavaType JavaTypeInput( JavaBuffer in )
   {
      JavaType x = new JavaType(); // make a new object
      // convert JavaBuffer fields to Java data objects in 
      // this Class
      return( x );// return the new object
   }
   // non-default Data Output function
   public static JavaBuffer JavaTypeOutput( JavaType out )
   {
      JavaBuffer x = new JavaBuffer();
      // Do whatever it takes to translate object to output 
      // buffer format
   return x;     // return the initialized buffer
   }
   // required SQLData implementation
   private String type;
   public String getSQLTypeName()
   {
      return type;
   }
   public void readSQL ( SQLInput instream, String typeName )
      throws SQLException
   {
      type = typeName;
      // cast up to Informix specific stream type
      IfmxUDTSQLInput in = (IfmxUDTSQLInput) instream;
      // read stream fields into Java data objects in this Class
      return;
   }

   public void writeSQL( SQLOutput outstream ) throws SQLException
   {
   // cast up to Informix specific stream type
      IfmxUDTSQLOutput out = (IfmxUDTSQLOutput) outstream;
   // write object to output stream
      return;
   }
}

For an example of the SQL definitions required to use the explicit methods in the preceding code, see SQL definitions for a variable-length UDT example.