Java Code Examples for java.io.ObjectOutputStream.writeFloat()

The following are Jave code examples for showing how to use writeFloat() of the java.io.ObjectOutputStream class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jdk8u-jdk   File: Floats.java   View Source Code Vote up 6 votes
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeFloat((float) 0.0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readFloat();
        }
    }
}
 
Example 2
Project: openjdk-jdk10   File: Floats.java   View Source Code Vote up 6 votes
/**
 * Run benchmark for given number of batches, with given number of cycles
 * for each batch.
 */
void doReps(ObjectOutputStream oout, ObjectInputStream oin,
            StreamBuffer sbuf, int nbatches, int ncycles)
    throws Exception
{
    for (int i = 0; i < nbatches; i++) {
        sbuf.reset();
        for (int j = 0; j < ncycles; j++) {
            oout.writeFloat((float) 0.0);
        }
        oout.flush();
        for (int j = 0; j < ncycles; j++) {
            oin.readFloat();
        }
    }
}
 
Example 3
Project: jaer   File: Histogram2DFilter.java   View Source Code Vote up 5 votes
public void saveHistogramToFile(File file) throws IOException, FileNotFoundException {
    log.info("Saving histogram data to " + file.getName());
    FileOutputStream fos = new FileOutputStream(file);
    ObjectOutputStream oos = new ObjectOutputStream(fos);
    oos.writeObject(histogram.length);
    oos.writeObject(histogram);
    oos.writeObject(bitmap);
    oos.writeFloat(threshold);
    oos.close();
    fos.close();
    log.info("histogram saved to file " + file.getPath());
    setFilePath(file.getPath());
}
 
Example 4
Project: oma-riista-android   File: GameHarvest.java   View Source Code Vote up 5 votes
private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();

    out.writeLong(mCoordinates != null ? mCoordinates.first : -1);
    out.writeLong(mCoordinates != null ? mCoordinates.second : -1);

    out.writeUTF(mLocation != null ? mLocation.getProvider() : null);
    out.writeDouble(mLocation != null ? mLocation.getLatitude() : -1);
    out.writeDouble(mLocation != null ? mLocation.getLongitude() : -1);
    out.writeFloat(mLocation != null ? mLocation.getAccuracy() : -1);
    out.writeDouble(mLocation != null ? mLocation.getAltitude() : -1);
}
 
Example 5
Project: jdk8u-jdk   File: CustomObjTrees.java   View Source Code Vote up 5 votes
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 6
Project: openjdk-jdk10   File: CustomObjTrees.java   View Source Code Vote up 5 votes
private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeBoolean(z);
    out.writeByte(b);
    out.writeChar(c);
    out.writeShort(s);
    out.writeInt(i);
    out.writeFloat(f);
    out.writeLong(j);
    out.writeDouble(d);
    out.writeObject(str);
    out.writeObject(parent);
    out.writeObject(left);
    out.writeObject(right);
}
 
Example 7
Project: keepass2android   File: AbstractReferenceMap.java   View Source Code Vote up 3 votes
/**
 * Replaces the superclass method to store the state of this class.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 * 
 * @param out  the output stream
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeInt(keyType);
    out.writeInt(valueType);
    out.writeBoolean(purgeValues);
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    for (MapIterator it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
    out.writeObject(null);  // null terminate map
    // do not call super.doWriteObject() as code there doesn't work for reference map
}
 
Example 8
Project: keepass2android   File: AbstractHashedMap.java   View Source Code Vote up 3 votes
/**
 * Writes the map data to the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 * 
 * @param out  the output stream
 */
protected void doWriteObject(ObjectOutputStream out) throws IOException {
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    out.writeInt(size);
    for (MapIterator it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
}
 
Example 9
Project: HCFCore   File: AbstractReferenceMap.java   View Source Code Vote up 3 votes
/**
 * Replaces the superclass method to store the state of this class.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 *
 * @param out  the output stream
 * @throws IOException if an error occurs while writing to the stream
 */
@Override
protected void doWriteObject(final ObjectOutputStream out) throws IOException {
    out.writeInt(keyType.value);
    out.writeInt(valueType.value);
    out.writeBoolean(purgeValues);
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    for (final MapIterator<K, V> it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
    out.writeObject(null);  // null terminate map
    // do not call super.doWriteObject() as code there doesn't work for reference map
}
 
Example 10
Project: HCFCore   File: AbstractHashedMap.java   View Source Code Vote up 3 votes
/**
 * Writes the map data to the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 *
 * @param out  the output stream
 * @throws IOException if an error occurs while writing tothe stream
 */
protected void doWriteObject(final ObjectOutputStream out) throws IOException {
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    out.writeInt(size);
    for (final MapIterator<K, V> it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
}
 
Example 11
Project: HCFCore   File: AbstractReferenceMap.java   View Source Code Vote up 3 votes
/**
 * Replaces the superclass method to store the state of this class.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 *
 * @param out  the output stream
 * @throws IOException if an error occurs while writing to the stream
 */
@Override
protected void doWriteObject(final ObjectOutputStream out) throws IOException {
    out.writeInt(keyType.value);
    out.writeInt(valueType.value);
    out.writeBoolean(purgeValues);
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    for (final MapIterator<K, V> it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
    out.writeObject(null);  // null terminate map
    // do not call super.doWriteObject() as code there doesn't work for reference map
}
 
Example 12
Project: HCFCore   File: AbstractHashedMap.java   View Source Code Vote up 3 votes
/**
 * Writes the map data to the stream. This method must be overridden if a
 * subclass must be setup before <code>put()</code> is used.
 * <p>
 * Serialization is not one of the JDK's nicest topics. Normal serialization will
 * initialise the superclass before the subclass. Sometimes however, this isn't
 * what you want, as in this case the <code>put()</code> method on read can be
 * affected by subclass state.
 * <p>
 * The solution adopted here is to serialize the state data of this class in
 * this protected method. This method must be called by the
 * <code>writeObject()</code> of the first serializable subclass.
 * <p>
 * Subclasses may override if they have a specific field that must be present
 * on read before this implementation will work. Generally, the read determines
 * what must be serialized here, if anything.
 *
 * @param out  the output stream
 * @throws IOException if an error occurs while writing tothe stream
 */
protected void doWriteObject(final ObjectOutputStream out) throws IOException {
    out.writeFloat(loadFactor);
    out.writeInt(data.length);
    out.writeInt(size);
    for (final MapIterator<K, V> it = mapIterator(); it.hasNext();) {
        out.writeObject(it.next());
        out.writeObject(it.getValue());
    }
}