下面列出了java.io.ObjectOutputStream#writeFloat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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();
}
}
}
public static void Save(Context ctx) {
if (!Initialized) {
return;
}
try {
ObjectOutputStream out = new ObjectOutputStream(ctx.openFileOutput(SettingsFileName, Context.MODE_PRIVATE));
out.writeInt(Pattern);
out.writeInt(ShiftTimeoutIdx);
out.writeBoolean(UseLightSensor);
out.writeFloat(LightSensorValue);
//Log.d(LOG, "cfg: writing pattern " + Pattern + " ShiftTimeoutIdx " + ShiftTimeoutIdx);
for (int i = Grids.PatternIdCustom; i < Grids.Patterns.length; i++) {
out.write(Grids.Patterns[i]);
}
out.writeBoolean(true); // Not used anymore
out.writeBoolean(true); // Not used anymore
out.writeBoolean(WasEnabled);
out.writeBoolean(SamsungBacklight);
out.writeBoolean(HideNotification);
out.writeBoolean(PersistentNotification);
out.close();
} catch (Exception e) {
Log.e(LOG, "Cannot save config file: " + e); //NON-NLS
}
}
/**
* 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();
}
}
}
/**
* 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();
}
}
}
/**
* @see #readMatrix(ObjectInputStream)
*/
private static void writeMatrix(FastByIDMap<float[]> matrix, ObjectOutputStream out) throws IOException {
if (matrix == null) {
out.writeInt(0);
} else {
out.writeInt(matrix.size());
for (FastByIDMap.MapEntry<float[]> entry : matrix.entrySet()) {
out.writeLong(entry.getKey());
float[] features = entry.getValue();
out.writeInt(features.length);
for (float f : features) {
Preconditions.checkState(LangUtils.isFinite(f));
out.writeFloat(f);
}
}
}
}
private static void writeClusters(Collection<IDCluster> clusters, ObjectOutputStream out) throws IOException {
if (clusters == null) {
out.writeInt(0);
} else {
out.writeInt(clusters.size());
for (IDCluster cluster : clusters) {
FastIDSet members = cluster.getMembers();
out.writeInt(members.size());
LongPrimitiveIterator it = members.iterator();
while (it.hasNext()) {
out.writeLong(it.nextLong());
}
float[] centroid = cluster.getCentroid();
out.writeInt(centroid.length);
for (float f : centroid) {
out.writeFloat(f);
}
}
}
}
/**
* Serializes a {@code Stroke} object. This code handles the
* {@code BasicStroke} class which is the only {@code Stroke}
* implementation provided by the JDK (and isn't directly
* {@code Serializable}).
*
* @param stroke the stroke object ({@code null} permitted).
* @param stream the output stream ({@code null} not permitted).
*
* @throws IOException if there is an I/O error.
*/
public static void writeStroke(Stroke stroke, ObjectOutputStream stream)
throws IOException {
Args.nullNotPermitted(stream, "stream");
if (stroke != null) {
stream.writeBoolean(false);
if (stroke instanceof BasicStroke) {
BasicStroke s = (BasicStroke) stroke;
stream.writeObject(BasicStroke.class);
stream.writeFloat(s.getLineWidth());
stream.writeInt(s.getEndCap());
stream.writeInt(s.getLineJoin());
stream.writeFloat(s.getMiterLimit());
stream.writeObject(s.getDashArray());
stream.writeFloat(s.getDashPhase());
} else {
stream.writeObject(stroke.getClass());
stream.writeObject(stroke);
}
} else {
stream.writeBoolean(true);
}
}
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);
}
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);
}
/**
* Writes a serializable object description to the given object output stream.
*
* @param o the to be serialized object.
* @param stream the outputstream that should receive the object.
* @throws IOException if an I/O error occured.
*/
public void writeObject( final Object o, final ObjectOutputStream stream ) throws IOException {
final GradientPaint gp = (GradientPaint) o;
final Point2D point2D1 = gp.getPoint1();
stream.writeFloat( (float) point2D1.getX() );
stream.writeFloat( (float) point2D1.getY() );
stream.writeObject( gp.getColor1() );
final Point2D point2D = gp.getPoint2();
stream.writeFloat( (float) point2D.getX() );
stream.writeFloat( (float) point2D.getY() );
stream.writeObject( gp.getColor2() );
stream.writeBoolean( gp.isCyclic() );
}
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);
}
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);
}
/**
* Writes a serializable object description to the given object output stream.
*
* @param o the to be serialized object.
* @param stream the outputstream that should receive the object.
* @throws IOException if an I/O error occured.
*/
public void writeObject( final Object o, final ObjectOutputStream stream )
throws IOException {
final BasicStroke s = (BasicStroke) o;
stream.writeFloat( s.getLineWidth() );
stream.writeInt( s.getEndCap() );
stream.writeInt( s.getLineJoin() );
stream.writeFloat( s.getMiterLimit() );
stream.writeObject( s.getDashArray() );
stream.writeFloat( s.getDashPhase() );
}
private void writeObject(ObjectOutputStream stream) throws IOException {
stream.defaultWriteObject();
stream.writeInt(backingMap.table.length);
stream.writeFloat(HashMap.DEFAULT_LOAD_FACTOR);
stream.writeInt(size());
for (E e : this) {
stream.writeObject(e);
}
}
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);
}
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);
}
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);
}
/**
* 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());
}
}
/**
* Writes the map data to the stream. This method must be overridden if a
* subclass must be setup before {@code put()} 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()} 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()} 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 IO operation fails
*/
@SuppressWarnings ( "NonSerializableObjectPassedToObjectStream" )
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 () );
}
}
/**
* 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());
}
}