Java Code Examples for com.codename1.io.Util#readObject()

The following examples show how to use com.codename1.io.Util#readObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParseUser.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes ParseUser-specific data in addition to regular ParseObject data.
 * 
 * @param version The version of the previously serialized object (defaults to {@link ParseConstants#API_VERSION}).
 * @param in The data input stream to deserialize from.
 * @throws IOException if any IO error occurs
 * @see ParseObject#internalize(int, java.io.DataInputStream) 
 */
@Override
public void internalize(int version, DataInputStream in) throws IOException, ParseException {
    super.internalize(version, in);
    
    sessionToken = Util.readUTF(in);
    password = Util.readUTF(in);
    current = ((Boolean) Util.readObject(in)) ? this : null;
}
 
Example 2
Source File: ParseFile.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.codename1.io.Externalizable
 */
public void internalize(int version, DataInputStream in) throws IOException {
    setDirty(in.readBoolean());
    endPoint = Util.readUTF(in);
    setName(Util.readUTF(in));
    setUrl(Util.readUTF(in));
    setContentType(Util.readUTF(in));
    data = (byte[]) Util.readObject(in);
}
 
Example 3
Source File: ParseObject.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
/**
 * Deserializes the contents of the ParseObject in a manner that complies with 
 * the {@link com.codename1.io.Externalizable} interface.
 * 
 * @param version The version of the previously serialized object (defaults to {@link ParseConstants#API_VERSION}).
 * @param in The data input stream to deserialize from.
 * @throws IOException if any IO error occurs
 * @throws ParseException if the object is {@link #isDirty() dirty}
 */
public void internalize(int version, DataInputStream in) throws IOException, ParseException {
    if (isDirty()) {
        throw new ParseException(ParseException.OPERATION_FORBIDDEN, 
                "A dirty ParseObject cannot be deserialized from storage");
    }
    
    reset();
    setObjectId(Util.readUTF(in));
    setCreatedAt((Date)Util.readObject(in));
    setUpdatedAt((Date)Util.readObject(in));
    
    // Retrieve actual data
    int keyCount = in.readInt();
    String key;
    Object value;
    for (int i = 0; i < keyCount; ++i) {
        key = in.readUTF();
        value = Util.readObject(in);
        
        if (value instanceof ExternalizableParseObject) {
            value = ((ExternalizableParseObject) value).getParseObject();
        } else if (value instanceof ExternalizableJsonEntity) {
            value = ((ExternalizableJsonEntity) value).getJsonEntity();
        }
        
        if (value != null) {
            data.put(key, value);
        }
    }
}
 
Example 4
Source File: Receipt.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void internalize(int version, DataInputStream in) throws IOException {
    Map m = (Map)Util.readObject(in);
    setSku((String)m.get("sku"));
    setExpiryDate((Date)m.get("expiryDate"));
    cancellationDate = (Date)m.get("cancellationDate");
    purchaseDate = (Date)m.get("purchaseDate");
    quantity = (Integer)m.get("quantity");
    transactionId = (String)m.get("transactionId");
    orderData = (String)m.get("orderData");
    storeCode = (String)m.get("storeCode");
    internalId = (String)m.get("internalId");
}
 
Example 5
Source File: CloudObject.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void internalize(int version, DataInputStream in) throws IOException {
    cloudId = Util.readUTF(in);
    owner = in.readBoolean();
    accessPermissions = in.readByte();
    lastModified = in.readLong();
    status = in.readInt();
    values = (Hashtable)Util.readObject(in);
}
 
Example 6
Source File: PropertyIndex.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an externalizable object for serialization of this business object, unlike regular
 * externalizables this implementation is robust to changes, additions and removals of 
 * properties
 * @return an externalizable instance
 */
public Externalizable asExternalizable() {
    return new Externalizable() {
        public int getVersion() {
            return 1;
        }

        public void externalize(DataOutputStream out) throws IOException {
            out.writeInt(getSize());
            for(PropertyBase b : PropertyIndex.this) {
                out.writeUTF(b.getName());
                if(b instanceof CollectionProperty) {
                    out.writeByte(2);
                    Util.writeObject(((CollectionProperty)b).asList(), out);
                    continue;
                }
                if(b instanceof MapProperty) {
                    out.writeByte(3);
                    Util.writeObject(((MapProperty)b).asMap(), out);
                    continue;
                }
                if(b instanceof Property) {
                    out.writeByte(1);
                    Util.writeObject(((Property)b).get(), out);
                    continue;
                }
            }
        }

        public void internalize(int version, DataInputStream in) throws IOException {
            int size = in.readInt();
            for(int iter = 0 ; iter < size ; iter++) {
                String pname = in.readUTF();
                int type = in.readByte();
                Object data = Util.readObject(in);
                PropertyBase pb = get(pname);
                switch(type) {
                    case 1: // Property
                        if(pb instanceof Property) {
                            ((Property)pb).set(data);
                        }
                        break;
                        
                    case 2: // CollectionProperty
                        if(pb instanceof CollectionProperty) {
                            ((CollectionProperty)pb).set((List)data);
                        }
                        break;
                        
                    case 3: // MapProperty
                        if(pb instanceof MapProperty) {
                            ((MapProperty)pb).setMap((Map)data);
                        }
                        break;
                }
            }
        }

        public String getObjectId() {
            return getName();
        }
    };
}