4.4.2.2 tryOnCARRAY.java Client Code

The code in the following listing illustrates how Jolt works with a service with a buffer type of CARRAY. Because Jolt does not look into the CARRAY data stream, it is the programmer's responsibility to ensure that the data formats between the Jolt client and the CARRAY service match. The example in the following listing assumes that a session object was already instantiated.

Listing CARRAY Buffer Type Example

/* Copyright 1996 Oracle Systems, Inc. All Rights Reserved */
   /* This code fragment illustrates how Jolt works with a service    
    * whose buffer type is CARRAY.  
    */
import java.io.*;
import bea.jolt.*;
class ...
{
      ...
      public void tryOnCARRAY()
      {
           byte data[];
           JoltRemoteService csvc;
           DataInputStream din;
           DataOutputStream dout;
           ByteArrayInputStream bin;
           ByteArrayOutputStream bout;
           /*
            * Use java.io.DataOutputStream to put data into a byte array
            */
           bout = new ByteArrayOutputStream(512);
           dout = new DataOutputStream(bout);
           dout.writeInt(100);
           dout.writeFloat((float) 300.00);
           dout.writeUTF("Hello World");
           dout.writeShort((short) 88);
           /*
            * Copy the byte array into a new byte array "data". Then
            * issue the Jolt remote service call.
            */
            data = bout.toByteArray();
            csvc = new JoltRemoteService("ECHO", session);
            csvc.setBytes("CARRAY", data, data.length);
            csvc.call(null);
            /*
             * Get the result from JoltRemoteService object and use  
             * java.io.DataInputStream to extract each individual value
             * from the byte array.
             */
            data = csvc.getBytesDef("CARRAY", null);  
            if (data != null)
            {
                bin = new ByteArrayInputStream(data);
                din = new DataInputStream(bin);
                System.out.println(din.readInt());
                System.out.println(din.readFloat());
                System.out.println(din.readUTF());
                System.out.println(din.readShort());
            }
       }
}