Datatypes and theirs size

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.

TypeDefault valueSize
booleanfalse1 byte
byte01 byte
char02 bytes
double0.08 bytes
float0.04 bytes
int04 bytes
long08 bytes
short02 bytes
java.lang.Booleannull1 byte if value is null; 2 bytes otherwise
java.lang.Bytenull1 byte if the value is null or 2 bytes otherwise
java.lang.Characternull1 byte if the value is null or 3 bytes otherwise
java.lang.Doublenull1 byte if the value is null or 9 bytes otherwise
java.lang.Floatnull1 byte if the value is null or 5 bytes otherwise
java.lang.Integernull1 byte if the value is null or 5 bytes otherwise
java.lang.Longnull1 byte if the value is null or 9 bytes otherwise
java.lang.Shortnull1 byte if the value is null or 3 bytes otherwise
java.lang.Stringnull1 byte if the value is null or otherwise the size is calculated based on the Modified UTF-8 specification
java.lang.StringBuffernull1 byte if the value is null or the amount of one String
java.util.Calendarnull1 byte if the value is null or 9 bytes plus the amount of one String
java.util.Datenull1 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.Hashtablenull1 byte if the value is null
java.util.Stacknull1 byte if the value is null
java.util.TimeZonenull1 byte if the value is null or the amount of one String
java.util.Vectornull1 byte if the value is null
net.sourceforge.floggy.Persistablenull1 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:

1
A instance of Frog with null name, null bornDate and 0 sex. The total cost of store this instance is: (1 byte) + (1 byte) + (2 bytes)= 4 bytes. This happens because no value must be save for name and bornDate only one byte indicating nullable state.
2
A instance of Frog with Flip Flop name, 05-30-2007 bornDate and M sex. The total cost of store this instance is: (1 byte + 9 bytes) + (1 byte + 8 bytes) + (2 bytes)= 21 bytes. This happens because the values for name and bornDate doesn't are null.
3
A instance of Frog with null name, 05-30-2007 bornDate and F sex. The total cost of store this instance is: (1 byte) + (1 byte + 8 bytes) + (2 bytes)= 12 bytes. This happens because the value of name are null.