下面列出了java.io.DataOutput#writeFloat ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Writes an array of <code>float</code>s to a
* <code>DataOutput</code>.
* This method will serialize a
* <code>null</code> array and not throw a
* <code>NullPointerException</code>.
*
* @throws IOException
* A problem occurs while writing to <code>out</code>
*
* @see #readFloatArray
*/
public static void writeFloatArray(float[] array, DataOutput out)
throws IOException {
InternalDataSerializer.checkOut(out);
int length;
if (array == null) {
length = -1;
} else {
length = array.length;
}
InternalDataSerializer.writeArrayLength(length, out);
if (DEBUG) {
InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing float array of length " + length);
}
if (length > 0) {
for (int i = 0; i < length; i++) {
out.writeFloat(array[i]);
}
}
}
/**
* Writes an array of <code>float</code>s to a
* <code>DataOutput</code>.
* This method will serialize a
* <code>null</code> array and not throw a
* <code>NullPointerException</code>.
*
* @throws IOException
* A problem occurs while writing to <code>out</code>
*
* @see #readFloatArray
*/
public static void writeFloatArray(float[] array, DataOutput out)
throws IOException {
InternalDataSerializer.checkOut(out);
int length;
if (array == null) {
length = -1;
} else {
length = array.length;
}
InternalDataSerializer.writeArrayLength(length, out);
if (DEBUG) {
InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing float array of length " + length);
}
if (length > 0) {
for (int i = 0; i < length; i++) {
out.writeFloat(array[i]);
}
}
}
@Override
public void write(DataOutput out) throws IOException {
// spatial
out.writeInt(this.spatial);
// temporal
out.writeInt(this.temporal);
// attribute
out.writeFloat(this.value);
}
@Override
public void toData(DataOutput out) throws IOException {
if (!isNull()) {
out.writeByte(getTypeId());
out.writeFloat(this.value);
return;
}
this.writeNullDVD(out);
}
@Override
public void operateIntegerFloat(LongPointable longp, FloatPointable floatp, DataOutput dOut)
throws SystemException, IOException {
float value = longp.floatValue();
value -= floatp.floatValue();
dOut.write(ValueTag.XS_FLOAT_TAG);
dOut.writeFloat(value);
}
/**
* Writes a primitive <code>float</code> to a
* <code>DataOutput</code>.
*
* @throws IOException
* A problem occurs while writing to <code>out</code>
*
* @see DataOutput#writeFloat
* @since 5.1
*/
public static void writePrimitiveFloat(float value, DataOutput out)
throws IOException {
InternalDataSerializer.checkOut(out);
if (DEBUG) {
InternalDataSerializer.logger.info( LocalizedStrings.DEBUG, "Writing Float " + value);
}
out.writeFloat(value);
}
@Override
public void operateFloatDecimal(FloatPointable floatp, XSDecimalPointable decp, DataOutput dOut)
throws SystemException, IOException {
float value = floatp.floatValue();
value %= decp.floatValue();
dOut.write(ValueTag.XS_FLOAT_TAG);
dOut.writeFloat(value);
}
public void write(DataOutput out) throws IOException {
taskid.write(out);
out.writeFloat(progress);
out.writeInt(numSlots);
WritableUtils.writeEnum(out, runState);
Text.writeString(out, diagnosticInfo);
Text.writeString(out, stateString);
WritableUtils.writeEnum(out, phase);
out.writeLong(startTime);
out.writeLong(finishTime);
out.writeBoolean(includeAllCounters);
out.writeLong(outputSize);
counters.write(out);
nextRecordRange.write(out);
}
@Override
public void serialize(Object value, DataOutput dataOutput) throws IOException {
if (value instanceof Number) {
value = ((Number)value).floatValue();
}
dataOutput.writeFloat((float)value);
}
public static void writeFloat(Float value, DataOutput output) throws IOException
{
if (value == null) {
output.writeFloat(0);
} else {
output.writeFloat(value);
}
}
public void write(DataOutput out) throws IOException {
int length = 0;
if (data != null) {
length = data.length;
}
out.writeInt(length);
for (int i = 0; i < length; i++) {
out.writeFloat(data[i]);
}
}
protected void _toDelta(DataOutput out) throws IOException {
Log.getLogWriter().info("In DeltaObject.toDelta, for " + this + "\n" + "with DataOutput " + out);
DeltaObserver.addToDeltaKey(extra);
// for validation later, encode with a toDelta id number
long toDeltaIdNumber = DeltaPropagationBB.getBB().getSharedCounters().incrementAndRead(DeltaPropagationBB.toDeltaIdNumber);
out.writeLong(toDeltaIdNumber);
Log.getLogWriter().info("Wrote toDeltaIdNumber " + toDeltaIdNumber);
out.writeBoolean(aPrimitiveLongChanged);
if (aPrimitiveLongChanged) {
out.writeLong(aPrimitiveLong);
Log.getLogWriter().info("Wrote changed field aPrimitiveLong " + aPrimitiveLong);
}
out.writeBoolean(aPrimitiveIntChanged);
if (aPrimitiveIntChanged) {
out.writeInt(aPrimitiveInt);
Log.getLogWriter().info("Wrote changed field aPrimitiveInt " + aPrimitiveInt);
}
out.writeBoolean(aPrimitiveShortChanged);
if (aPrimitiveShortChanged) {
out.writeShort(aPrimitiveShort);
Log.getLogWriter().info("Wrote changed field aPrimitiveShort " + aPrimitiveShort);
}
out.writeBoolean(aPrimitiveFloatChanged);
if (aPrimitiveFloatChanged) {
out.writeFloat(aPrimitiveFloat);
Log.getLogWriter().info("Wrote changed field aPrimitiveFloat " + aPrimitiveFloat);
}
out.writeBoolean(aPrimitiveDoubleChanged);
if (aPrimitiveDoubleChanged) {
out.writeDouble(aPrimitiveDouble);
Log.getLogWriter().info("Wrote changed field aPrimitiveDouble " + aPrimitiveDouble);
}
out.writeBoolean(aPrimitiveByteChanged);
if (aPrimitiveByteChanged) {
out.writeByte(aPrimitiveByte);
Log.getLogWriter().info("Wrote changed field aPrimitiveByte " + aPrimitiveByte);
}
out.writeBoolean(aPrimitiveCharChanged);
if (aPrimitiveCharChanged) {
out.writeChar(aPrimitiveChar);
Log.getLogWriter().info("Wrote changed field aPrimitiveChar " + aPrimitiveChar);
}
out.writeBoolean(aPrimitiveBooleanChanged);
if (aPrimitiveBooleanChanged) {
out.writeBoolean(aPrimitiveBoolean);
Log.getLogWriter().info("Wrote changed field aPrimitiveBoolean " + aPrimitiveBoolean);
}
out.writeBoolean(aByteArrayChanged);
if (aByteArrayChanged) {
out.writeInt(aByteArray.length);
out.write(aByteArray);
Log.getLogWriter().info("Wrote changed field aByteArray of length " + aByteArray.length);
}
out.writeBoolean(aStringChanged);
if (aStringChanged) {
out.writeInt(aString.length());
out.writeBytes(aString);
Log.getLogWriter().info("Wrote changed field aString " + aString);
}
out.writeInt(END_SIGNAL.length());
out.writeBytes(END_SIGNAL);
Log.getLogWriter().info("Wrote end signal: " + END_SIGNAL);
Log.getLogWriter().info("Done writing in DeltaObject.toDelta for " + this);
}
public void writeToStream(DataOutput os) throws IOException {
os.writeInt(skinVertIndex);
os.writeFloat(skinVertPos.x);
os.writeFloat(skinVertPos.y);
os.writeFloat(-skinVertPos.z);
}
@Override
public void convertDecimal(XSDecimalPointable decp, DataOutput dOut) throws SystemException, IOException {
float value = decp.floatValue();
dOut.write(ValueTag.XS_FLOAT_TAG);
dOut.writeFloat(value);
}
public void write(DataOutput out) throws IOException {
out.writeFloat(count);
out.writeFloat(average);
}
@Override
public void write(DataOutput out) throws IOException {
out.writeFloat(sum);
out.writeInt(count);
}
protected void _toDelta(DataOutput out) throws IOException {
Log.getLogWriter().info("In DeltaObject.toDelta, for " + this + "\n" + "with DataOutput " + out);
DeltaObserver.addToDeltaKey(extra);
// for validation later, encode with a toDelta id number
long toDeltaIdNumber = DeltaPropagationBB.getBB().getSharedCounters().incrementAndRead(DeltaPropagationBB.toDeltaIdNumber);
out.writeLong(toDeltaIdNumber);
Log.getLogWriter().info("Wrote toDeltaIdNumber " + toDeltaIdNumber);
out.writeBoolean(aPrimitiveLongChanged);
if (aPrimitiveLongChanged) {
out.writeLong(aPrimitiveLong);
Log.getLogWriter().info("Wrote changed field aPrimitiveLong " + aPrimitiveLong);
}
out.writeBoolean(aPrimitiveIntChanged);
if (aPrimitiveIntChanged) {
out.writeInt(aPrimitiveInt);
Log.getLogWriter().info("Wrote changed field aPrimitiveInt " + aPrimitiveInt);
}
out.writeBoolean(aPrimitiveShortChanged);
if (aPrimitiveShortChanged) {
out.writeShort(aPrimitiveShort);
Log.getLogWriter().info("Wrote changed field aPrimitiveShort " + aPrimitiveShort);
}
out.writeBoolean(aPrimitiveFloatChanged);
if (aPrimitiveFloatChanged) {
out.writeFloat(aPrimitiveFloat);
Log.getLogWriter().info("Wrote changed field aPrimitiveFloat " + aPrimitiveFloat);
}
out.writeBoolean(aPrimitiveDoubleChanged);
if (aPrimitiveDoubleChanged) {
out.writeDouble(aPrimitiveDouble);
Log.getLogWriter().info("Wrote changed field aPrimitiveDouble " + aPrimitiveDouble);
}
out.writeBoolean(aPrimitiveByteChanged);
if (aPrimitiveByteChanged) {
out.writeByte(aPrimitiveByte);
Log.getLogWriter().info("Wrote changed field aPrimitiveByte " + aPrimitiveByte);
}
out.writeBoolean(aPrimitiveCharChanged);
if (aPrimitiveCharChanged) {
out.writeChar(aPrimitiveChar);
Log.getLogWriter().info("Wrote changed field aPrimitiveChar " + aPrimitiveChar);
}
out.writeBoolean(aPrimitiveBooleanChanged);
if (aPrimitiveBooleanChanged) {
out.writeBoolean(aPrimitiveBoolean);
Log.getLogWriter().info("Wrote changed field aPrimitiveBoolean " + aPrimitiveBoolean);
}
out.writeBoolean(aByteArrayChanged);
if (aByteArrayChanged) {
out.writeInt(aByteArray.length);
out.write(aByteArray);
Log.getLogWriter().info("Wrote changed field aByteArray of length " + aByteArray.length);
}
out.writeBoolean(aStringChanged);
if (aStringChanged) {
out.writeInt(aString.length());
out.writeBytes(aString);
Log.getLogWriter().info("Wrote changed field aString " + aString);
}
out.writeInt(END_SIGNAL.length());
out.writeBytes(END_SIGNAL);
Log.getLogWriter().info("Wrote end signal: " + END_SIGNAL);
Log.getLogWriter().info("Done writing in DeltaObject.toDelta for " + this);
}
public void toData(DataOutput out) throws IOException {
DataSerializer.writeString(this.cacheLoaderDesc, out);
DataSerializer.writeString(this.cacheWriterDesc, out);
DataSerializer.writeStringArray(this.cacheListenerDescs, out);
DataSerializer.writeString(this.capacityControllerDesc, out);
DataSerializer.writeObject(this.keyConstraint, out);
DataSerializer.writeObject(this.valueConstraint, out);
DataSerializer.writeObject(this.rTtl, out);
DataSerializer.writeObject(this.rIdleTimeout, out);
DataSerializer.writeObject(this.eTtl, out);
DataSerializer.writeString(this.customEttlDesc, out);
DataSerializer.writeObject(this.eIdleTimeout, out);
DataSerializer.writeString(this.customEIdleDesc, out);
DataSerializer.writeObject(this.dataPolicy, out);
DataSerializer.writeObject(this.scope, out);
out.writeBoolean(this.statsEnabled);
out.writeBoolean(this.ignoreJTA);
out.writeInt(this.concurrencyLevel);
out.writeFloat(this.loadFactor);
out.writeInt(this.initialCapacity);
out.writeBoolean(this.earlyAck);
out.writeBoolean(this.multicastEnabled);
out.writeBoolean(this.enableGateway);
DataSerializer.writeString(this.gatewayHubId, out);
out.writeBoolean(this.enableSubscriptionConflation);
out.writeBoolean(this.publisher);
out.writeBoolean(this.enableAsyncConflation);
DataSerializer.writeObject(this.diskWriteAttributes, out);
DataSerializer.writeObject(this.diskDirs, out);
DataSerializer.writeObject(this.diskSizes, out);
out.writeBoolean(this.indexMaintenanceSynchronous);
DataSerializer.writeObject(this.partitionAttributes, out);
DataSerializer.writeObject(this.membershipAttributes, out);
DataSerializer.writeObject(this.subscriptionAttributes, out);
DataSerializer.writeObject(this.evictionAttributes, out);
out.writeBoolean(this.cloningEnable);
DataSerializer.writeString(this.diskStoreName, out);
out.writeBoolean(this.isDiskSynchronous);
DataSerializer.writeStringArray(this.gatewaySendersDescs, out);
out.writeBoolean(this.isGatewaySenderEnabled);
out.writeBoolean(this.concurrencyChecksEnabled);
DataSerializer.writeString(this.hdfsStoreName, out);
DataSerializer.writeString(this.compressorDesc, out);
out.writeBoolean(this.enableOffHeapMemory);
}
public static void writeVector3f(DataOutput os, Vector3f v) throws IOException{
os.writeFloat(v.x);
os.writeFloat(v.y);
os.writeFloat(-v.z);
}
/**
* Write the state of this to the DataOutput
*
* @param out
* DataOutput on which to write internal state
* @throws IOException
*/
public void toData(DataOutput out) throws IOException {
out.writeLong(this.maxMemoryBytes);
out.writeFloat(this.criticalThreshold);
out.writeFloat(this.evictionThreshold);
}