public interface Externalizable
Externalizable
is similar to the Java SE Externalizable
interface this interface.
Notice that due to the lack of reflection and use of obfuscation these objects must be registered with the
Util class.
Also notice that all externalizable objects must have a default public constructor.
The externalization process supports serializing these types and considers them to be Externalizable
.
E.g. you can just write Storage.getInstance().writeObject(new Object[] {"Str1", "Str2"});
and it will work
as expected.
Notice that while these objects can be written, the process doesn't guarantee they will be read with the same
object type. E.g. if you write a LinkedList
you could get back a ArrayList
as both
implement Collection
:
String
, Collection
, Map
, ArrayList
,
HashMap
, Vector
, Hashtable
, Integer
,
Double
, Float
, Byte
, Short
,
Long
, Character
, Boolean
, Object[]
,
byte[]
, int[]
, float[]
, long[]
, double[]
.
The sample below demonstrates the usage and registration of the Externalizable
interface:
WARNING: The externalization process caches objects so the app will seem to work and only fail on restart!
Modifier and Type | Method and Description |
---|---|
void |
externalize(DataOutputStream out)
Allows us to store an object state, this method must be implemented
in order to save the state of an object
|
String |
getObjectId()
The object id must be unique, it is used to identify the object when loaded
even when it is obfuscated.
|
int |
getVersion()
Returns the version for the current persistance code, the version will be
pased to internalized thus allowing the internalize method to recognize
classes persisted in older revisions
|
void |
internalize(int version,
DataInputStream in)
Loads the object from the input stream and allows deserialization
|
int getVersion()
void externalize(DataOutputStream out) throws IOException
out
- the stream into which the object must be serializedIOException
- the method may throw an exceptionvoid internalize(int version, DataInputStream in) throws IOException
version
- the version the class returned during the externalization processsin
- the input stream used to load the classIOException
- the method may throw an exceptionString getObjectId()