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:HashSet.java

/**
 * Adapted from {@link org.apache.commons.collections.map.AbstractHashedMap}.
 *///from   ww w .  j a  v a  2s  .  c o m
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeInt(table.length);
    out.writeInt(size);
    for (int i = 0; i < table.length; ++i) {
        Object e = table[i];
        if (e != null) {
            out.writeObject(unmaskNull(e));
        }
    }
}

From source file:edu.umass.cs.msocket.common.policies.GeoLoadProxyPolicy.java

/**
 * @throws Exception if a GNS error occurs
 * @see edu.umass.cs.msocket.common.policies.ProxySelectionPolicy#getNewProxy()
 *///from   w w  w .  j ava 2s .c  om
@Override
public List<InetSocketAddress> getNewProxy() throws Exception {
    // Lookup for active location service GUIDs
    final UniversalGnsClient gnsClient = gnsCredentials.getGnsClient();
    final GuidEntry guidEntry = gnsCredentials.getGuidEntry();
    JSONArray guids;
    try {
        guids = gnsClient.fieldRead(proxyGroupName, GnsConstants.ACTIVE_LOCATION_FIELD, guidEntry);
    } catch (Exception e) {
        throw new GnsException("Could not find active location services (" + e + ")");
    }

    // Try every location proxy in the list until one works
    for (int i = 0; i < guids.length(); i++) {
        // Retrieve the location service IP and connect to it
        String locationGuid = guids.getString(i);
        String locationIP = gnsClient.fieldRead(locationGuid, GnsConstants.LOCATION_SERVICE_IP, guidEntry)
                .getString(0);
        logger.fine("Contacting location service " + locationIP + " to request " + numProxies + " proxies");

        // Location IP is stored as host:port
        StringTokenizer st = new StringTokenizer(locationIP, ":");
        try {
            // Protocol is send the number of desired proxies and receive strings
            // containing proxy IP:port
            Socket s = new Socket(st.nextToken(), Integer.parseInt(st.nextToken()));
            ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
            ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
            oos.writeInt(numProxies);
            oos.flush();
            List<InetSocketAddress> result = new LinkedList<InetSocketAddress>();
            while (!s.isClosed() && result.size() < numProxies) {
                String proxyIP = ois.readUTF();
                StringTokenizer stp = new StringTokenizer(proxyIP, ":");
                result.add(new InetSocketAddress(stp.nextToken(), Integer.parseInt(stp.nextToken())));
            }
            if (!s.isClosed()) // We receive all the proxies we need, just close the
                               // socket
                s.close();
            return result;
        } catch (Exception e) {
            logger.info("Failed to obtain proxy from location service" + locationIP + " (" + e + ")");
        }
    }

    throw new GnsException("Could not find any location service to provide a geolocated proxy");
}

From source file:net.sf.nmedit.jtheme.store2.AbstractMultiParameterElement.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();/* w  w w.java  2  s  .c  o  m*/

    out.writeInt(parameterElementNames.length);

    int size = 0;
    for (int i = 0; i < parameterElementNames.length; i++) {
        String n = parameterElementNames[i];
        if (n != null)
            size++;
    }

    out.writeInt(size);
    for (int i = 0; i < parameterElementNames.length; i++) {
        String n = parameterElementNames[i];
        if (n != null) {
            out.writeInt(i);
            out.writeObject(n);
        }
    }

    size = 0;
    for (int i = 0; i < componentIdList.length; i++) {
        String n = componentIdList[i];
        if (n != null)
            size++;
    }

    out.writeInt(size);
    for (int i = 0; i < componentIdList.length; i++) {
        String n = componentIdList[i];
        if (n != null) {
            out.writeInt(i);
            out.writeObject(n);
        }
    }

    size = 0;
    if (valueList != null) {
        for (int i = 1; i < valueList.length; i += 2) {
            if (valueList[i] != null)
                size++;
        }
    }
    out.writeInt(size);
    if (valueList != null) {
        for (int i = 0; i < valueList.length; i += 2) {
            String n = (String) valueList[i];
            Integer v = (Integer) valueList[i + 1];
            if (v != null) {
                out.writeObject(n);
                out.writeInt(v.intValue());
            }
        }
    }
}

From source file:pt.webdetails.cda.cache.TableCacheKey.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    //to be hazelcast compatible needs to serialize EXACTLY the same
    //binary comparison/hash will be used

    out.writeInt(connectionHash);
    out.writeObject(query);//from  w  w w .ja v a 2 s  .com
    out.writeObject(queryType);

    out.writeInt(parameters.length);
    for (Parameter param : parameters) {
        param.writeObject(out);
    }

    out.writeObject(extraCacheKey);
}

From source file:com.izforge.izpack.compiler.packager.impl.MultiVolumePackager.java

/**
 * Writes packs to one or more <em>.pak</em> volumes.
 * <p/>/* w w w.  j  a  v a  2s.c  o  m*/
 * Pack meta-data is written to the installer jar.
 *
 * @throws IOException for any I/O error
 */
@Override
protected void writePacks() throws IOException {
    String classname = getClass().getSimpleName();

    // propagate the configuration to the variables, for debugging purposes
    getVariables().setProperty(classname + "." + FIRST_VOLUME_FREE_SPACE, Long.toString(maxFirstVolumeSize));
    getVariables().setProperty(classname + "." + VOLUME_SIZE, Long.toString(maxVolumeSize));

    List<PackInfo> packs = getPacksList();
    final int count = packs.size();
    sendMsg("Writing " + count + " Pack" + (count > 1 ? "s" : "") + " into installer");
    logger.fine("Writing " + count + " Pack" + (count > 1 ? "s" : "") + " into installer");
    logger.fine("First volume size: " + maxFirstVolumeSize);
    logger.fine("Subsequent volume size: " + maxVolumeSize);

    File volume = new File(getInfo().getInstallerBase() + ".pak").getAbsoluteFile();
    int volumes = writePacks(packs, volume);

    // write metadata for reading in volumes
    logger.fine("Written " + volumes + " volumes");

    JarOutputStream installerJar = getInstallerJar();
    installerJar.putNextEntry(new ZipEntry(RESOURCES_PATH + "volumes.info"));
    ObjectOutputStream out = new ObjectOutputStream(installerJar);
    out.writeInt(volumes);
    out.writeUTF(volume.getName());
    out.flush();
    installerJar.closeEntry();

    // Now that we know sizes, write pack metadata to primary jar.
    installerJar.putNextEntry(new ZipEntry(RESOURCES_PATH + "packs.info"));
    out = new ObjectOutputStream(installerJar);
    out.writeInt(count);

    for (PackInfo pack : packs) {
        out.writeObject(pack.getPack());
    }
    out.flush();
    installerJar.closeEntry();
}

From source file:clipboardplugin.ClipboardPlugin.java

public void writeData(ObjectOutputStream out) throws IOException {
    out.writeInt(1); // write version

    if (mConfigs != null) {
        ArrayList<AbstractPluginProgramFormating> list = new ArrayList<AbstractPluginProgramFormating>();

        for (AbstractPluginProgramFormating config : mConfigs) {
            if (config != null) {
                list.add(config);//  ww  w.  j a  v  a2 s  . c o m
            }
        }

        out.writeInt(list.size());

        for (AbstractPluginProgramFormating config : list) {
            config.writeData(out);
        }
    } else {
        out.writeInt(0);
    }

    if (mLocalFormatings != null) {
        ArrayList<AbstractPluginProgramFormating> list = new ArrayList<AbstractPluginProgramFormating>();

        for (AbstractPluginProgramFormating config : mLocalFormatings) {
            if (config != null) {
                list.add(config);
            }
        }

        out.writeInt(list.size());

        for (AbstractPluginProgramFormating config : list) {
            config.writeData(out);
        }
    }

}

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

/**
 Write the meta data related to change (i.e. parents, object history that 
 owns this change) into a stream//from   w w  w.j a v  a  2 s . com
 @param os
 @throws java.io.IOException
 */
private void writeChangeMetadata(ObjectOutputStream os) throws IOException {
    os.writeObject(historyClass);
    os.writeObject(targetClassName);
    os.writeObject(targetUuid);
    os.writeInt(parentIds.size());
    for (UUID parentId : parentIds) {
        os.writeObject(parentId);
    }
}

From source file:Main.java

/**
 * Serialises an <code>AttributedString</code> object.
 *
 * @param as  the attributed string object (<code>null</code> permitted).
 * @param stream  the output stream (<code>null</code> not permitted).
 *
 * @throws IOException if there is an I/O error.
 *//*  w ww  .  j  av  a  2  s .c  o m*/
public static void writeAttributedString(AttributedString as, ObjectOutputStream stream) throws IOException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    if (as != null) {
        stream.writeBoolean(false);
        AttributedCharacterIterator aci = as.getIterator();
        // build a plain string from aci
        // then write the string
        StringBuffer plainStr = new StringBuffer();
        char current = aci.first();
        while (current != CharacterIterator.DONE) {
            plainStr = plainStr.append(current);
            current = aci.next();
        }
        stream.writeObject(plainStr.toString());

        // then write the attributes and limits for each run
        current = aci.first();
        int begin = aci.getBeginIndex();
        while (current != CharacterIterator.DONE) {
            // write the current character - when the reader sees that this
            // is not CharacterIterator.DONE, it will know to read the
            // run limits and attributes
            stream.writeChar(current);

            // now write the limit, adjusted as if beginIndex is zero
            int limit = aci.getRunLimit();
            stream.writeInt(limit - begin);

            // now write the attribute set
            Map atts = new HashMap(aci.getAttributes());
            stream.writeObject(atts);
            current = aci.setIndex(limit);
        }
        // write a character that signals to the reader that all runs
        // are done...
        stream.writeChar(CharacterIterator.DONE);
    } else {
        // write a flag that indicates a null
        stream.writeBoolean(true);
    }

}

From source file:ddf.catalog.data.AttributeImpl.java

/**
 * Serializes this {@link AttributeImpl} instance.
 * //from  ww w. j  a  v  a  2 s. c  o m
 * @serialData First, all non-transient fields are written out by the
 *             default Java serialization implementation
 *             (ObjectInputStream.defaultWriteObject()). Then the number of
 *             "value" objects is written out as an ({@code int}). After the
 *             number of objects, each "value" object is written out (each
 *             as {@code Serializable}).
 * @param s
 *            - the {@link ObjectOutputStream} which contains the object to
 *            be serialized
 * @throws IOException
 */
private void writeObject(ObjectOutputStream s) throws IOException {

    /*
     * defaultWriteObject() is invoked for greater flexibility and
     * compatibility. See the *Serialization Note* in MetacardImpl's class
     * Javadoc.
     */
    s.defaultWriteObject();

    s.writeInt(values.size());

    for (Serializable ser : values) {
        s.writeObject(ser);
    }
}

From source file:org.mrgeo.hdfs.vector.shp.ShapefileReader.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeUTF(fileName);
    out.writeInt(source.ordinal());
}