Example usage for java.io ObjectOutputStream writeFields

List of usage examples for java.io ObjectOutputStream writeFields

Introduction

In this page you can find the example usage for java.io ObjectOutputStream writeFields.

Prototype

public void writeFields() throws IOException 

Source Link

Document

Write the buffered fields to the stream.

Usage

From source file:Person.java

public static void main(String[] args) throws Exception {
    ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("yourFile.dat"));

    Person person = new Person();
    person.setFirstName("A");
    person.setLastName("B");
    person.setAge(38);//w w  w  .j  a v  a 2s.  c  om
    outputStream.writeObject(person);

    person = new Person();
    person.setFirstName("C");
    person.setLastName("D");
    person.setAge(22);
    outputStream.writeObject(person);

    outputStream.writeFields();

    outputStream.close();
}

From source file:Main.java

private void writeObject(ObjectOutputStream out) throws IOException {

    ObjectOutputStream.PutField fields = out.putFields();
    fields.put("string", string);
    out.writeFields();

}

From source file:facebook4j.FacebookBaseImpl.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    // http://docs.oracle.com/javase/6/docs/platform/serialization/spec/output.html#861
    out.putFields();/*from  w w w. ja v  a  2s.co m*/
    out.writeFields();

    out.writeObject(conf);
    out.writeObject(auth);
}

From source file:org.kepler.objectmanager.lsid.KeplerLSID.java

/**
 * Custom serialization method. The serial representation of the KeplerLSID
 * object is simply the toString() representation.
 * //from   w  ww . j a v  a2s .  c o m
 * @param oos
 * @throws IOException
 */
private void writeObject(ObjectOutputStream oos) throws IOException {
    ObjectOutputStream.PutField fields = oos.putFields();
    fields.put("lsidString", toString());
    oos.writeFields();
}

From source file:twitter4j.internal.models4j.TwitterBaseImpl.java

private void writeObject(ObjectOutputStream out) throws IOException {
    // http://docs.oracle.com/javase/6/docs/platform/serialization/spec/output.html#861
    out.putFields();// www.ja v  a2s  .  c o m
    out.writeFields();

    out.writeObject(conf);
    out.writeObject(auth);
    List<RateLimitStatusListener> serializableRateLimitStatusListeners = new ArrayList<RateLimitStatusListener>(
            0);
    for (RateLimitStatusListener listener : rateLimitStatusListeners) {
        if (listener instanceof Serializable) {
            serializableRateLimitStatusListeners.add(listener);
        }
    }
    out.writeObject(serializableRateLimitStatusListeners);
}

From source file:gate.annotation.AnnotationSetImpl.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("name", this.name);
    pf.put("doc", this.doc);
    ////from   ww  w  . j a v a2 s .co m
    // out.writeObject(this.name);
    // out.writeObject(this.doc);
    // save only the annotations
    // in an array that will prevent the need for casting
    // when deserializing
    annotations = new Annotation[this.annotsById.size()];
    annotations = this.annotsById.values().toArray(annotations);
    // out.writeObject(annotations);
    pf.put("annotations", this.annotations);
    out.writeFields();
    annotations = null;
    boolean isIndexedByType = (this.annotsByType != null);
    boolean isIndexedByStartNode = (this.annotsByStartNode != null);
    out.writeBoolean(isIndexedByType);
    out.writeBoolean(isIndexedByStartNode);
}