Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

3.5 Transferring Data Between C++ and Java

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.

Figure 2 -- Data Exchange through Virtual Streams

3.5.1 Using the Tools.h++ Virtual Streams Format

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.

Figure 3 -- Input and output class relationships

A PortableInputStream uses any InputStream as its source of data. For example, you can create a PortableInputStream that obtains its data from a socket:

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:

See the examples in the com/roguewave/examples/vsj directory of your Rogue Wave root area.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.