Package totalcross.io
Interface Storable
-
public interface StorableAn interface for all objects that support loading and saving themselves through the ObjectCatalog class. This works in a similar manner to the Externalizable interface in Java. When saveState() is called, the value of any fields should be written to the given DataStream. When loadState() is called these values should be read back using the equivalent methods, making sure the order remains the same. After loadState() the new object should behave exactly as it did before the corresponding saveState(). Here is an example of the methods in use.public class MyClass implements Storable { int i; String s; public MyClass() { } public MyClass(int i, String s) { this.i = i; this.s = s; } public byte getID() { return (byte) 123; } public Storable getInstance() { return new MyClass(); } public void saveState(DataStream ds) { ds.writeInt(i); ds.writeString(s); } public void loadState(DataStream ds) { i = ds.readInt(); s = ds.readString(); } }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description bytegetID()Gets a unique ID for this class.StorablegetInstance()Returns an object of the same class as this object.voidloadState(DataStream ds)Load state information from the given DataStream into this object If any Storable objects need to be loaded as part of the state, their loadState() method can be called too.voidsaveState(DataStream ds)Send the state information of this object to the given object catalog using the given DataStream.
-
-
-
Method Detail
-
getID
byte getID()
Gets a unique ID for this class. It is up to the user to ensure that the ID of each class of Storable contained in a single ObjectCatalog is unique and the ID of each instance in a class is the same. If the ID returned is zero, no type information will be saved to the catalog and ObjectCatalog.loadObjectAt(int) cannot be used. It is useful, however when accessing Catalogs from other programs using the ObjectCatalog model.
-
getInstance
Storable getInstance()
Returns an object of the same class as this object.- Returns:
- a class. Any data is irrelevent.
-
saveState
void saveState(DataStream ds) throws IOException
Send the state information of this object to the given object catalog using the given DataStream. If any Storable objects need to be saved as part of the state, their saveState() method can be called too.- Throws:
IOException
-
loadState
void loadState(DataStream ds) throws IOException
Load state information from the given DataStream into this object If any Storable objects need to be loaded as part of the state, their loadState() method can be called too.- Throws:
IOException
-
-