To transfer data between C++ and Java,Tools.h++ Professional provides an extension of the Tools.h++ virtual streams format. This format is most useful if you have existing Tools.h++ code and are writing an application in Java. Using virtual streams leverages your investment in C++ code, while providing a natural data-exchange interface for new Java development. Figure 2 shows graphically how this is done.
The PortableInputStream and PortableOutputStream classes in Tools.h++ Professional give Java applications the ability to read and write the Tools.h++ portable ASCII virtual streams format. ObjectStreamer instances assist in the process by mapping the contents of C++ classes to the contents of Java classes. The data transfer mechanism can be a file or a socket.
The following figures show how stream classes and data transfer mechanisms in Tools.h++ and Tools.h++ Professional interact. Figure 3 demonstrates the Java chain of objects that link sockets and stream classes in Tools.h++ Professional.
A PortableInputStream uses any InputStream as its source of data. For example, you can create a PortableInputStream that obtains its data from a socket:
import java.net.Socket; import java.io.InputStream; import com.roguewave.vsj.PortableInputStream; // ... Socket s = new Socket(hostname, port); InputStream istrm = s.getInputStream(); PortableInputStream pistrm = new PortableInputStream(istrm);
A C++ application would then use an RWpostream to produce the data read by this PortableInputStream. See the dpymail example program for a demonstration of this technique.
Similarly, you can create a PortableInputStream that reads a data file as follows:
import java.io.FileInputStream; import com.roguewave.vsj.PortableInputStream; // ... FileInputStream fstrm = new FileInputStream(filename); PortableInputStream pstrm = new PortableInputStream(fstrm);
See the examples in the com/roguewave/examples/vsj directory of your Rogue Wave root area.
©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.