Example usage for java.io ObjectOutputStream putFields

List of usage examples for java.io ObjectOutputStream putFields

Introduction

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

Prototype

public ObjectOutputStream.PutField putFields() throws IOException 

Source Link

Document

Retrieve the object used to buffer persistent fields to be written 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);// www.j a va 2 s.c o  m
    outputStream.writeObject(person);

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

    ObjectOutputStream.PutField putField = outputStream.putFields();

    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  w w  w . j  a  va  2  s  .  com*/

}

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();
    out.writeFields();//from  ww w.j a va2s. c om

    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.
 * // ww w . j av  a  2 s  .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();
    out.writeFields();//  w ww. j a va  2s  .c o m

    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   w  w w  . j  a va2  s .c o  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);
}