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

The following examples show how to use com.codename1.io.Util#writeUTF() . 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: 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 4
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 5
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 6
Source File: ExternalizableParseObject.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 {
    if (parseObject != null) {
        try {
            Util.writeUTF(className, out);
            parseObject.externalize(out);
        } catch (ParseException ex) {
            Logger.getInstance().error(
                    "Unable to serialize ParseObject with objectId=" + parseObject.getObjectId());
            throw new IOException(ex.getMessage());
        }
    }
}
 
Example 7
Source File: Message.java    From codenameone-demos with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void externalize(DataOutputStream out) throws IOException {
    out.writeLong(time);
    Util.writeUTF(senderId, out);
    Util.writeUTF(recepientId, out);
    Util.writeUTF(picture, out);
    Util.writeUTF(name, out);
    Util.writeUTF(message, out);
}
 
Example 8
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 9
Source File: CachedData.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(url, out);
    Util.writeUTF(etag, out);
    Util.writeUTF(modified, out);
    out.writeInt(data.length);
    out.write(data);
}