Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
private int __id = -1;
private final static net.sourceforge.floggy.persistence.PersistableMetadata __persistableMetadata = new net.sourceforge.floggy.persistence.PersistableMetadata("FloggyVectorArray520738657");
public net.sourceforge.floggy.persistence.PersistableMetadata __getPersistableMetadata() {
    return __persistableMetadata;
}
public void __load(byte[] buffer) throws java.lang.Exception {
    java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(buffer);
    java.io.DataInputStream dis = new java.io.DataInputStream(bais);
    if(dis.readByte() == 0) {
        int count = dis.readInt();
        this.x = new java.util.Vector[count];
        for(int j = 0; j < count; j++) {
            if(dis.readByte() == 1) {
                this.x[j] = null;
            }
            else {
                int size = dis.readInt();
                this.x[j] = new java.util.Vector(size);
                for(int k = 0; k < size; k++) {
                    if(dis.readByte() == 1) {
                        this.x[j].addElement((Object) null);
                        continue;
                    }
                    else {
                        String className = dis.readUTF();
                        if(className.equals("java.lang.Boolean")) {
                            this.x[j].addElement(new java.lang.Boolean(dis.readBoolean()));
                            continue;
                        }
                        if(className.equals("java.lang.Byte")) {
                            this.x[j].addElement(new java.lang.Byte(dis.readByte()));
                            continue;
                        }
                        if(className.equals("java.lang.Character")) {
                            this.x[j].addElement(new java.lang.Character(dis.readChar()));
                            continue;
                        }
                        if(className.equals("java.lang.Double")) {
                            this.x[j].addElement(new java.lang.Double(dis.readDouble()));
                            continue;
                        }
                        if(className.equals("java.lang.Float")) {
                            this.x[j].addElement(new java.lang.Float(dis.readFloat()));
                            continue;
                        }
                        if(className.equals("java.lang.Integer")) {
                            this.x[j].addElement(new java.lang.Integer(dis.readInt()));
                            continue;
                        }
                        if(className.equals("java.lang.Long")) {
                            this.x[j].addElement(new java.lang.Long(dis.readLong()));
                            continue;
                        }
                        if(className.equals("java.lang.Short")) {
                            this.x[j].addElement(new java.lang.Short(dis.readShort()));
                            continue;
                        }
                        if(className.equals("java.lang.String")) {
                            this.x[j].addElement(new java.lang.String(dis.readUTF()));
                            continue;
                        }
                        if(className.equals("java.util.Date")) {
                            this.x[j].addElement(new java.util.Date(dis.readLong()));
                            continue;
                        }
                        Class persistableClass = java.lang.Class.forName(className);
                        Object object = persistableClass.newInstance();
                        if(object instanceof net.sourceforge.floggy.persistence.internal.__Persistable) {
                            ((net.sourceforge.floggy.persistence.internal.__Persistable) object).__load(dis.readInt());
                            this.x[j].addElement(object);
                        }
                    }
                }
            }
        }
    }
    else {
        x = null;
    }
    dis.close();
}
public void __load(int id) throws java.lang.Exception {
    javax.microedition.rms.RecordStore rs = net.sourceforge.floggy.persistence.PersistableManager.getRecordStore(__persistableMetadata);
    byte[] buffer = rs.getRecord(id);
    rs.closeRecordStore();
    this.__load(buffer);
    this.__id = id;
}
public int __save() throws java.lang.Exception {
    java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
    java.io.DataOutputStream dos = new java.io.DataOutputStream(baos);
    javax.microedition.rms.RecordStore rs = net.sourceforge.floggy.persistence.PersistableManager.getRecordStore(__persistableMetadata);
    if(this.x == null) {
        dos.writeByte(1);
    }
    else {
        dos.writeByte(0);
        int count = this.x.length;
        dos.writeInt(count);
        for(int l = 0; l < count; l++) {
            if(this.x[l] == null) {
                dos.writeByte(1);
            }
            else {
                dos.writeByte(0);
                int size = this.x[l].size();
                dos.writeInt(size);
                for(int m = 0; m < size; m++) {
                    Object object = this.x[l].elementAt(m);
                    if(object == null) {
                        dos.writeByte(1);
                        continue;
                    }
                    dos.writeByte(0);
                    String className= object.getClass().getName();
                    dos.writeUTF(className);
                    if(object instanceof java.lang.Boolean) {
                        dos.writeBoolean(((java.lang.Boolean) object).booleanValue());
                    }
                    else if(object instanceof java.lang.Byte) {
                        dos.writeByte(((java.lang.Byte) object).byteValue());
                    }
                    else if(object instanceof java.lang.Character) {
                        dos.writeChar(((java.lang.Character) object).charValue());
                    }
                    else if(object instanceof java.lang.Double) {
                        dos.writeDouble(((java.lang.Double) object).doubleValue());
                    }
                    else if(object instanceof java.lang.Float) {
                        dos.writeFloat(((java.lang.Float) object).floatValue());
                    }
                    else if(object instanceof java.lang.Integer) {
                        dos.writeInt(((java.lang.Integer) object).intValue());
                    }
                    else if(object instanceof java.lang.Long) {
                        dos.writeLong(((java.lang.Long) object).longValue());
                    }
                    else if(object instanceof java.lang.Short) {
                        dos.writeShort(((java.lang.Short) object).shortValue());
                    }
                    else if(object instanceof java.lang.String) {
                        dos.writeUTF(((java.lang.String) object));
                    }
                    else if(object instanceof java.util.Date) {
                        dos.writeLong(((java.util.Date) object).getTime());
                    }
                    else if(object instanceof net.sourceforge.floggy.persistence.internal.__Persistable) {
                        int id = ((net.sourceforge.floggy.persistence.internal.__Persistable) object).__save();
                        dos.writeInt(id);
                    }
                    else {
                        throw new net.sourceforge.floggy.persistence.FloggyException("The class "+className+" doesn't is a persistable class!");
                    }
                }
            }
        }
    }
    if(this.__id == -1) {
        this.__id = rs.addRecord(baos.toByteArray(), 0, baos.size());
    }
    else {
        rs.setRecord(this.__id, baos.toByteArray(), 0, baos.size());
    }
    rs.closeRecordStore();
    dos.close();
    return this.__id;
}
public void __delete() throws java.lang.Exception {
    if (this.__id != -1) {
        javax.microedition.rms.RecordStore rs = net.sourceforge.floggy.persistence.PersistableManager.getRecordStore(__persistableMetadata);
        rs.deleteRecord(this.__id);
        rs.closeRecordStore();
    }
}
New to GrepCode? Check out our FAQ X