The table below shows the data types that are Floggy compliant and their size. All primitive types are saved using only the size of that type. Object types receive one extra byte that indicates the state of the object (null or not). Only fields of a class that implements net.sourceforge.floggy.Persistable will be persisted.
Type | Default value | Size |
boolean | false | 1 byte |
byte | 0 | 1 byte |
char | 0 | 2 bytes |
double | 0.0 | 8 bytes |
float | 0.0 | 4 bytes |
int | 0 | 4 bytes |
long | 0 | 8 bytes |
short | 0 | 2 bytes |
java.lang.Boolean | null | 1 byte if value is null; 2 bytes otherwise |
java.lang.Byte | null | 1 byte if the value is null or 2 bytes otherwise |
java.lang.Character | null | 1 byte if the value is null or 3 bytes otherwise |
java.lang.Double | null | 1 byte if the value is null or 9 bytes otherwise |
java.lang.Float | null | 1 byte if the value is null or 5 bytes otherwise |
java.lang.Integer | null | 1 byte if the value is null or 5 bytes otherwise |
java.lang.Long | null | 1 byte if the value is null or 9 bytes otherwise |
java.lang.Short | null | 1 byte if the value is null or 3 bytes otherwise |
java.lang.String | null | 1 byte if the value is null or otherwise the size is calculated based on the Modified UTF-8 specification |
java.lang.StringBuffer | null | 1 byte if the value is null or the amount of one String |
java.util.Calendar | null | 1 byte if the value is null or 9 bytes plus the amount of one String |
java.util.Date | null | 1 byte if the value is null or 9 bytes otherwise. The java.util.Date objects are transformed into a long type and saved as a java.lang.Long object |
java.util.Hashtable | null | 1 byte if the value is null |
java.util.Stack | null | 1 byte if the value is null |
java.util.TimeZone | null | 1 byte if the value is null or the amount of one String |
java.util.Vector | null | 1 byte if the value is null |
net.sourceforge.floggy.Persistable | null | 1 byte if the value is null |
Examples
Suppose that you have a class like this:
public class Frog implements Persistable { private String name; private Date bornDate; private char sex; }
Now suppose this three scenarios: