Created
March 2, 2016 13:04
-
-
Save codenameone/ebfffaffd405ed3b7723 to your computer and use it in GitHub Desktop.
Full Externalizable class sample for Codenmae One
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyClass implements Externalizable { | |
private static final int VERSION = 2; | |
private String name; | |
private String value; | |
private String domain; | |
private Date date; | |
private long expires; | |
public MyClass() {} | |
public int getVersion() { | |
return VERSION; | |
} | |
public String getObjectId() { | |
return "MyClass"; | |
} | |
public void externalize(DataOutputStream out) throws IOException { | |
Util.writeUTF(name, out); | |
Util.writeUTF(value, out); | |
Util.writeUTF(domain, out); | |
if(date != null) { | |
out.writeBoolean(true); | |
out.writeLong(date.getTime()); | |
} else { | |
out.writeBoolean(false); | |
} | |
out.writeLong(expires); | |
} | |
public void internalize(int version, DataInputStream in) throws IOException { | |
name = Util.readUTF(in); | |
value = Util.readUTF(in); | |
domain = Util.readUTF(in); | |
if(version > 1) { | |
boolean hasDate = in.readBoolean(); | |
if(hasDate) { | |
date = new Date(in.readLong()); | |
} | |
} | |
expires = in.readLong(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample code for Externalizable.
From the Codename One project