Passing binary data in xfNetLink Java

You can pass binary data, such as JPEG files, by using an ArrayList.

Note

Binary fields in structures are converted to byte arrays. However, if you want to pass binary data such as JPEG files, you should use the procedure described below, rather than a binary field in a structure, because the latter requires that you specify a size.

If you attribute your code, see example G for instructions on defining a binary handle. (Or, in the MDU, define the parameter as a “Binary (handle)” data type.) Your Synergy server routine must declare the argument that receives the data as a memory handle (i4). xfServerPlus will place the data in a memory area and pass the memory handle allocated to that area to your Synergy server routine. After the data has been returned to xfNetLink, xfServerPlus will free the memory area.

If the parameter is defined as “in” only in the SMC, in your Java code you will need to create a byte array and fill it with data, instantiate an ArrayList of byte arrays, and add the byte array as the first element of the list. Then, you can make the method call.

For example:

MyJCW JCWinstance = new MyJCW();
JCWinstance.setxfHost("HostMachine");
JCWinstance.setxfPort(2356);
JCWinstance.connect();
  byte[] inba = new byte[67000];   //Create the byte[]
  .              //Fill byte[] with data
  .
  .
  //Create ArrayList of byte arrays
  ArrayList<byte[]> al = new ArrayList<byte[]>(); 
  al.add(inba);     //Add byte[] as first element of ArrayList
JCWinstance.BinaryArrayMethod(al); //Call XFPL method
JCWinstance.disconnect();

For “out” only parameters, in your Java code you will need to instantiate an ArrayList of byte arrays, call the method, and then extract the byte array from the first element of the ArrayList using the ArrayList.get() method. For example:

MyJCW JCWinstance = new MyJCW();
JCWinstance.setxfHost("HostMachine");
JCWinstance.setxfPort(2356);
JCWinstance.connect();
  // Create ArrayList of byte arrays
  ArrayList<byte[]> al = new ArrayList<byte[]>();
  JCWinstance.BinaryArrayMethod(al); //Call XFPL method
  byte[] rtnba = (byte[])al.get(0);  //Extract byte[] from first element
JCWinstance.disconnect();

For “in/out” parameters, in your Java code you will need to create a byte array and fill it with data, instantiate an ArrayList of byte arrays, add the byte array as the first element of the list, and then call the method. When the data is returned, you will extract the byte array from the first element of the ArrayList using the ArrayList.get() method. For example:

MyJCW JCWinstance = new MyJCW();
JCWinstance.setxfHost("HostMachine");
JCWinstance.setxfPort(2356);
JCWinstance.connect();
  byte[] inba = new byte[67000];    //Create the byte[]
  .                                 //Fill byte[] with data
  .
  .
  //Create ArrayList of byte arrays
  ArrayList<byte[]> al = new ArrayList<byte[]>();
  al.add(inba);  //Add byte[] as first element of ArrayList
JCWinstance.BinaryArrayMethod(al);  //Call XFPL method
  inba = (byte[])al.get(0);  //Extract byte[] from first element
JCWinstance.disconnect();