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

The following examples show how to use com.codename1.io.Util#writeObject() . 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: ParseRelation.java    From parse4cn1 with Apache License 2.0 6 votes vote down vote up
/**
 * @see com.codename1.io.Externalizable
 */
public void externalize(DataOutputStream out) throws IOException {
    /* 
    Note that ParseRelations are applied on ParseObjects and since only saved
    ParseObjects are serialized by design, the only piece of information 
    needed to reconstruct the relation is the targetClass. However,
    for completeness, we include other fields except the parent since
    serializing the parent will result in an infinite loop. If there's 
    ever a usecase where a ParseRelation is deemed useful outside a ParseObject,
    a smart way to store the parent would be implemented.
    */
    Util.writeUTF(targetClass, out);
    Util.writeUTF(key, out);
    Util.writeObject(setToArray(addedObjects), out);
    Util.writeObject(setToArray(removedObjects), out);
}
 
Example 2
Source File: ParseObject.java    From parse4cn1 with Apache License 2.0 6 votes vote down vote up
/**
 * Serializes the contents of the ParseObject in a manner that complies with
 * the {@link com.codename1.io.Externalizable} interface.
 *
 * @param out The data stream to serialize to.
 * @throws IOException if any IO error occurs
 * @throws ParseException if the object is {@link #isDirty() dirty}
 */
public void externalize(DataOutputStream out) throws IOException, ParseException {
    if (isDirty()) {
        throw new ParseException(ParseException.OPERATION_FORBIDDEN,
                "A dirty ParseObject cannot be serialized to storage");
    }
    
    Util.writeUTF(getObjectId(), out);
    Util.writeObject(getCreatedAt(), out);
    Util.writeObject(getUpdatedAt(), out);
    
    // Persist actual data
    out.writeInt(keySet().size());
    for (String key : keySet()) {
        out.writeUTF(key);
        Object value = get(key);
        if (value instanceof ParseObject) {
            value = ((ParseObject)value).asExternalizable();
        } else if (ExternalizableJsonEntity.isExternalizableJsonEntity(value)) {
            value = new ExternalizableJsonEntity(value);
        }
        Util.writeObject(value, out);
    }
}
 
Example 3
Source File: Receipt.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void externalize(DataOutputStream out) throws IOException {
    Map m = new HashMap();
    m.put("sku", getSku());
    m.put("expiryDate", getExpiryDate());
    m.put("cancellationDate", getCancellationDate());
    m.put("purchaseDate", getPurchaseDate());
    m.put("orderData", getOrderData());
    m.put("transactionId", getTransactionId());
    m.put("quantity", getQuantity());
    m.put("storeCode", getStoreCode());
    m.put("internalId", getInternalId());

    Util.writeObject(m, out);
    
}
 
Example 4
Source File: ParseUser.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
/**
 * Serializes ParseUser-specific data in addition to regular ParseObject data.
 *
 * @param out The data stream to serialize to.
 * @throws IOException if any IO error occurs
 * @throws ParseException if the object is {@link #isDirty() dirty}
 * @see ParseObject#externalize(java.io.DataOutputStream) 
 */
@Override
public void externalize(DataOutputStream out) throws IOException, ParseException {
    super.externalize(out);
    
    Util.writeUTF(sessionToken, out);
    Util.writeUTF(password, out);
    Util.writeObject(this.equals(current), out);
}
 
Example 5
Source File: ParseFile.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.codename1.io.Externalizable
 */
public void externalize(DataOutputStream out) throws IOException {
    out.writeBoolean(isDirty());
    Util.writeUTF(getEndPoint(), out);
    Util.writeUTF(getName(), out);
    Util.writeUTF(getUrl(), out);
    Util.writeUTF(getContentType(), out);
    Util.writeObject(data, out);
}
 
Example 6
Source File: ExternalizableJsonEntity.java    From parse4cn1 with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.codename1.io.Externalizable
 */
public void externalize(DataOutputStream out) throws IOException {
    Util.writeUTF(type.toString(), out);
    if (type == EJsonEntityType.JSON_ARRAY) {
       Util.writeObject(ParseDecoder.convertJSONArrayToList((JSONArray)object), out); 
    } else if (type == EJsonEntityType.JSON_OBJECT) {
       Util.writeObject(ParseDecoder.convertJSONObjectToMap((JSONObject)object), out);
    }
}
 
Example 7
Source File: ProxyServerHelper.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns an OK response to the client
 * @param resp the response object
 * @param def the method definition
 * @param response the result from the method
 */
public static void writeResponse(HttpServletResponse resp, WSDefinition def, Externalizable response) throws IOException {
    resp.setStatus(HttpServletResponse.SC_OK);
    DataOutputStream dos = new DataOutputStream(resp.getOutputStream());
    Util.writeObject(response, dos);
    dos.close();
}
 
Example 8
Source File: CloudStorage.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
protected void buildRequestBody(OutputStream os) throws IOException {
    DataOutputStream d = new DataOutputStream(os);
    d.writeInt(storageQueue.size());
    d.writeUTF(CloudPersona.getCurrentPersona().getToken());
    d.writeUTF(Display.getInstance().getProperty("package_name", null));
    d.writeUTF(Display.getInstance().getProperty("built_by_user", null));
    for(int iter = 0 ; iter < storageQueue.size() ; iter++) {
        Object e = storageQueue.elementAt(iter);
        if(e instanceof String) {
            // delete operation
            d.writeByte(1);
            d.writeUTF((String)e);
        } else {
            CloudObject cl = (CloudObject)e;
            if(cl.getCloudId() == null) {
                // insert operation
                d.writeByte(2);
                d.writeInt(cl.getAccessPermissions());
                Util.writeObject(cl.getValues(), d);
            } else {
                // update operation
                d.writeByte(3);
                d.writeUTF(cl.getCloudId());
                d.writeLong(cl.getLastModified());
                Util.writeObject(cl.getValues(), d);
            }
        }
    }
    d.writeInt(1);
}
 
Example 9
Source File: CloudObject.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void externalize(DataOutputStream out) throws IOException {
    Util.writeUTF(cloudId, out);
    out.writeBoolean(owner);
    out.writeByte(getAccessPermissions());
    out.writeLong(lastModified);
    out.writeInt(status);
    Util.writeObject(values, out);
}
 
Example 10
Source File: ParseGeoPoint.java    From parse4cn1 with Apache License 2.0 4 votes vote down vote up
/**
 * @see com.codename1.io.Externalizable
 */
public void externalize(DataOutputStream out) throws IOException {
    Util.writeObject(getLatitude(), out);
    Util.writeObject(getLongitude(), out);
}
 
Example 11
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();
        }
    };
}