The Rogue Wave® JViews library provides the
following two classes for saving graphic objects to, and loading
graphic objects from, a stream:
- IlvOutputStream, used by the class
IlvManager
to save all the graphic objects that it contains
Graphic objects can always be written to an
IlvOutputStream
because they inherit the
write
method of the
IlvGraphic
class:
public void write(IlvOutputStream stream) throws IOException
To save the information contained in your class, you can override
this method and use the methods of the class
IlvOutputStream
. When overriding this method, you must not forget to call the
write
method of the superclass to save the information related to the
superclass. You will obtain something that resembles the following
example.
public void write(IlvOutputStream stream) throws IOException { // write fields of super class super.write(stream); // write fields of my class stream.write("color", getColor()); stream.write("thickness", getThickness()); .... }
To read your graphic object from an
IlvInputStream
, you must create a constructor with an
IlvInputStream
. This constructor is mandatory even if you have not overridden the
write
method. The corresponding constructor in the class IlvGraphic is:
public IlvGraphic(IlvInputStream stream) throws IlvReadFileException
Assuming that
MyClass
is the name of your class, your new constructor will look like
this:
public MyClass(IlvInputStream stream) throws IlvReadFileException
In the body of this constructor, you first call the corresponding
constructor in the superclass, then you read the information you
have saved in the
write
method. In the above example, the corresponding constructor is:
public MyClass(IlvInputStream stream) throws IlvReadFileException { super(stream); setColor(stream.readColor("color")); setThickness(stream.readInt("thickness")); ... }
Important
The recommended way to serialize any
IlvManager
object is through IVL serialization and not Java™ serialization. Serialization cannot
work for managers that contain graphic objects such as
IlvIcon
or some other classes, since these classes internally manage Java
SE objects that are not serializable.