Example usage for java.io ObjectOutputStream writeInt

List of usage examples for java.io ObjectOutputStream writeInt

Introduction

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

Prototype

public void writeInt(int val) throws IOException 

Source Link

Document

Writes a 32 bit int.

Usage

From source file:org.ejbca.core.ejb.approval.ApprovalSessionBean.java

@Override
public void setApprovals(ApprovalData approvalData, final Collection<Approval> approvals) {
    try {//from  w  w  w  .j  ava2  s. c o  m
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final ObjectOutputStream oos = new ObjectOutputStream(baos);
        final int size = approvals.size();
        oos.writeInt(size);
        final Iterator<Approval> iter = approvals.iterator();
        while (iter.hasNext()) {
            final Approval next = iter.next();
            oos.writeObject(next);
        }
        oos.flush();
        approvalData.setApprovaldata(new String(Base64.encode(baos.toByteArray(), false)));
    } catch (IOException e) {
        log.error("Error building approvals.", e);
        throw new RuntimeException(e);
    }
}

From source file:fr.pasteque.pos.ticket.TicketInfo.java

/** Serialize as shared ticket */
public byte[] serialize() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(m_sId);/* w w w  . j  a v a2s . c  o  m*/
    out.writeInt(tickettype);
    out.writeInt(m_iTicketId);
    out.writeObject(m_Customer);
    out.writeObject(m_dDate);
    out.writeObject(attributes);
    out.writeObject(m_aLines);
    out.writeObject(this.customersCount);
    out.writeObject(this.tariffAreaId);
    out.writeObject(this.discountProfileId);
    out.writeDouble(this.discountRate);
    out.flush();
    byte[] data = bos.toByteArray();
    out.close();
    return data;
}

From source file:org.photovault.replication.Change.java

/**
 Serializes the field changes to a stream
 @param s/* www  .j  av  a  2s .  com*/
 */
private void writeFieldChanges(ObjectOutputStream s) throws IOException {
    if (changedFields == null) {
        initChangedFields();
    }
    s.writeInt(changedFields.size());
    List<String> fieldsSorted = new ArrayList<String>(changedFields.keySet());
    Collections.sort(fieldsSorted);
    for (String f : fieldsSorted) {
        s.writeObject(f);
        s.writeObject(changedFields.get(f));
    }
}

From source file:org.largecollections.MapFactory.java

private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
    stream.writeObject(this.folder);
    stream.writeObject(this.name);
    stream.writeInt(this.cacheSize);
    stream.writeInt(this.bloomFilterSize);
    stream.writeObject(this.bloomFilter);
    stream.writeObject(this.myMaps);
    this.db.close();
}

From source file:org.hibernate.engine.ActionQueue.java

/**
 * Used by the owning session to explicitly control serialization of the
 * action queue// ww w . j  a  v  a 2 s  . c  o m
 *
 * @param oos The stream to which the action queue should get written
 *
 * @throws IOException
 */
public void serialize(ObjectOutputStream oos) throws IOException {
    log.trace("serializing action-queue");

    int queueSize = insertions.size();
    log.trace("starting serialization of [" + queueSize + "] insertions entries");
    oos.writeInt(queueSize);
    for (int i = 0; i < queueSize; i++) {
        oos.writeObject(insertions.get(i));
    }

    queueSize = deletions.size();
    log.trace("starting serialization of [" + queueSize + "] deletions entries");
    oos.writeInt(queueSize);
    for (int i = 0; i < queueSize; i++) {
        oos.writeObject(deletions.get(i));
    }

    queueSize = updates.size();
    log.trace("starting serialization of [" + queueSize + "] updates entries");
    oos.writeInt(queueSize);
    for (int i = 0; i < queueSize; i++) {
        oos.writeObject(updates.get(i));
    }

    queueSize = collectionUpdates.size();
    log.trace("starting serialization of [" + queueSize + "] collectionUpdates entries");
    oos.writeInt(queueSize);
    for (int i = 0; i < queueSize; i++) {
        oos.writeObject(collectionUpdates.get(i));
    }

    queueSize = collectionRemovals.size();
    log.trace("starting serialization of [" + queueSize + "] collectionRemovals entries");
    oos.writeInt(queueSize);
    for (int i = 0; i < queueSize; i++) {
        oos.writeObject(collectionRemovals.get(i));
    }

    queueSize = collectionCreations.size();
    log.trace("starting serialization of [" + queueSize + "] collectionCreations entries");
    oos.writeInt(queueSize);
    for (int i = 0; i < queueSize; i++) {
        oos.writeObject(collectionCreations.get(i));
    }
}

From source file:HashMap.java

/**
 * Adapted from {@link org.apache.commons.collections.map.AbstractHashedMap}.
 *///from ww w  .  ja va  2 s . co m
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeInt(keys.length);
    out.writeInt(size);
    for (int i = 0; i < keys.length; ++i) {
        Object key = keys[i];
        if (key != null) {
            out.writeObject(unmaskNullKey(key));
            out.writeObject(values[i]);
        }
    }
}

From source file:org.objectweb.proactive.core.remoteobject.RemoteObjectSet.java

private void writeObject(ObjectOutputStream out) throws IOException {
    // Almost same as in term of speed UniqueID.getCurrentVMID() but more readable
    this.vmid = ProActiveRuntimeImpl.getProActiveRuntime().getVMInformation().getVMID();
    out.defaultWriteObject();// www .ja  va  2  s. co  m
    out.writeInt(rros.size());

    // write the default protocol
    writeProtocol(out, defaultURI, defaultRO);

    // write all other protocols
    for (URI uri : initialorder) {
        if (!uri.equals(defaultURI)) {
            writeProtocol(out, uri, rros.get(uri));
        }
    }
}

From source file:com.google.gwt.dev.util.collect.HashMap.java

/**
 * Adapted from {@link org.apache.commons.collections.map.AbstractHashedMap}.
 *//*from   www  .  j  a v a 2 s.c  o  m*/
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeInt(keys.length);
    out.writeInt(size);

    if (stableWriteObject) {
        final Integer[] idx = new Integer[keys.length];
        for (int i = 0; i < keys.length; i++) {
            idx[i] = i;
        }
        Arrays.sort(idx, new Comparator<Integer>() {
            @SuppressWarnings({ "rawtypes", "unchecked" })
            @Override
            public int compare(final Integer o1, final Integer o2) {
                Comparable c1 = (Comparable) (keys[o1]);
                Comparable c2 = (Comparable) (keys[o2]);
                if (c1 == null) {
                    // null < anything else
                    return (c2 == null) ? 0 : 1;
                }
                if (c2 == null) {
                    return -1;
                }
                return c1.compareTo(c2);
            }
        });

        for (int i = 0; i < keys.length; ++i) {
            int current = idx[i];
            Object key = keys[current];
            if (key != null) {
                out.writeObject(unmaskNullKey(key));
                out.writeObject(values[current]);
            }
        }
    } else {
        for (int i = 0; i < keys.length; ++i) {
            Object key = keys[i];
            if (key != null) {
                out.writeObject(unmaskNullKey(key));
                out.writeObject(values[i]);
            }
        }
    }
}

From source file:ArraySet.java

/**
 * Save the state of this <tt>HashSet</tt> instance to a stream (that is,
 * serialize this set)./*from w w w . j  a v  a2s  . com*/
 * 
 * @serialData The capacity of the backing <tt>HashMap</tt> instance (int),
 *             and its load factor (float) are emitted, followed by the size
 *             of the set (the number of elements it contains) (int),
 *             followed by all of its elements (each an Object) in no
 *             particular order.
 */
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
    s.defaultWriteObject();
    s.writeInt(map.size());
    for (Iterator<E> i = map.keySet().iterator(); i.hasNext();) {
        s.writeObject(i.next());
    }
}

From source file:ArrayDeque.java

/**
 * Serialize this deque./*from w w w.  j a  v a 2  s. com*/
 *
 * @serialData The current size (<tt>int</tt>) of the deque,
 * followed by all of its elements (each an object reference) in
 * first-to-last order.
 */
private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();

    // Write out size
    int size = size();
    s.writeInt(size);

    // Write out elements in order.
    int i = head;
    int mask = elements.length - 1;
    for (int j = 0; j < size; j++) {
        s.writeObject(elements[i]);
        i = (i + 1) & mask;
    }
}