List of usage examples for java.io DataOutput writeFloat
void writeFloat(float v) throws IOException;
float
value, which is comprised of four bytes, to the output stream. From source file:org.apache.horn.core.AbstractNeuralNetwork.java
@Override public void write(DataOutput output) throws IOException { // write model type WritableUtils.writeString(output, modelType); // write learning rate output.writeFloat(learningRate); // write model path if (this.modelPath != null) { WritableUtils.writeString(output, modelPath); } else {/*from ww w . j av a2 s .com*/ WritableUtils.writeString(output, "null"); } // serialize the class Class<? extends FloatFeatureTransformer> featureTransformerCls = this.featureTransformer.getClass(); byte[] featureTransformerBytes = SerializationUtils.serialize(featureTransformerCls); output.writeInt(featureTransformerBytes.length); output.write(featureTransformerBytes); }
From source file:org.apache.horn.core.LayeredNeuralNetwork.java
@Override public void write(DataOutput output) throws IOException { super.write(output); output.writeInt(finalLayerIdx);//from w ww . ja v a 2 s . co m output.writeFloat(dropRate); // write neuron classes output.writeInt(this.neuronClassList.size()); for (Class<? extends Neuron> clazz : this.neuronClassList) { output.writeUTF(clazz.getName()); } // write squashing functions output.writeInt(this.squashingFunctionList.size()); for (FloatFunction aSquashingFunctionList : this.squashingFunctionList) { WritableUtils.writeString(output, aSquashingFunctionList.getFunctionName()); } // write weight matrices output.writeInt(this.weightMatrixList.size()); for (FloatMatrix aWeightMatrixList : this.weightMatrixList) { FloatMatrixWritable.write(aWeightMatrixList, output); } // DO NOT WRITE WEIGHT UPDATE }
From source file:org.apache.horn.core.RecurrentLayeredNeuralNetwork.java
@Override public void write(DataOutput output) throws IOException { super.write(output); output.writeInt(finalLayerIdx);// ww w. j av a 2 s .c o m output.writeFloat(dropRate); // write neuron classes output.writeInt(this.neuronClassList.size()); for (Class<? extends Neuron> clazz : this.neuronClassList) { output.writeUTF(clazz.getName()); } // write squashing functions output.writeInt(this.squashingFunctionList.size()); for (FloatFunction aSquashingFunctionList : this.squashingFunctionList) { WritableUtils.writeString(output, aSquashingFunctionList.getFunctionName()); } // write recurrent step size output.writeInt(this.recurrentStepSize); // write recurrent step size output.writeInt(this.numOutCells); // write recurrent layer list output.writeInt(this.recurrentLayerList.size()); for (Boolean isReccurentLayer : recurrentLayerList) { output.writeBoolean(isReccurentLayer); } // write weight matrices output.writeInt(this.getSizeOfWeightmatrix()); for (List<FloatMatrix> aWeightMatrixLists : this.weightMatrixLists) { for (FloatMatrix aWeightMatrixList : aWeightMatrixLists) { FloatMatrixWritable.write(aWeightMatrixList, output); } } // DO NOT WRITE WEIGHT UPDATE }
From source file:org.apache.nutch.crawl.CrawlDatum.java
public void write(DataOutput out) throws IOException { out.writeByte(CUR_VERSION); // store current version out.writeByte(status);//from w ww . j a v a 2s . com out.writeLong(fetchTime); out.writeByte(retries); out.writeInt(fetchInterval); out.writeFloat(score); out.writeLong(modifiedTime); if (signature == null) { out.writeByte(0); } else { out.writeByte(signature.length); out.write(signature); } if (metaData != null && metaData.size() > 0) { out.writeBoolean(true); metaData.write(out); } else { out.writeBoolean(false); } }
From source file:org.apache.pig.data.BinInterSedes.java
@Override @SuppressWarnings("unchecked") public void writeDatum(DataOutput out, Object val, byte type) throws IOException { switch (type) { case DataType.TUPLE: writeTuple(out, (Tuple) val); break;// ww w . ja v a2 s . c o m case DataType.BAG: writeBag(out, (DataBag) val); break; case DataType.MAP: { writeMap(out, (Map<String, Object>) val); break; } case DataType.INTERNALMAP: { out.writeByte(INTERNALMAP); Map<Object, Object> m = (Map<Object, Object>) val; out.writeInt(m.size()); Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator(); while (i.hasNext()) { Map.Entry<Object, Object> entry = i.next(); writeDatum(out, entry.getKey()); writeDatum(out, entry.getValue()); } break; } case DataType.INTEGER: int i = (Integer) val; if (i == 0) { out.writeByte(INTEGER_0); } else if (i == 1) { out.writeByte(INTEGER_1); } else if (Byte.MIN_VALUE <= i && i <= Byte.MAX_VALUE) { out.writeByte(INTEGER_INBYTE); out.writeByte(i); } else if (Short.MIN_VALUE <= i && i <= Short.MAX_VALUE) { out.writeByte(INTEGER_INSHORT); out.writeShort(i); } else { out.writeByte(INTEGER); out.writeInt(i); } break; case DataType.LONG: long lng = (Long) val; if (lng == 0) { out.writeByte(LONG_0); } else if (lng == 1) { out.writeByte(LONG_1); } else if (Byte.MIN_VALUE <= lng && lng <= Byte.MAX_VALUE) { out.writeByte(LONG_INBYTE); out.writeByte((int) lng); } else if (Short.MIN_VALUE <= lng && lng <= Short.MAX_VALUE) { out.writeByte(LONG_INSHORT); out.writeShort((int) lng); } else if (Integer.MIN_VALUE <= lng && lng <= Integer.MAX_VALUE) { out.writeByte(LONG_ININT); out.writeInt((int) lng); } else { out.writeByte(LONG); out.writeLong(lng); } break; case DataType.DATETIME: out.writeByte(DATETIME); out.writeLong(((DateTime) val).getMillis()); out.writeShort(((DateTime) val).getZone().getOffset((DateTime) val) / ONE_MINUTE); break; case DataType.FLOAT: out.writeByte(FLOAT); out.writeFloat((Float) val); break; case DataType.BIGINTEGER: out.writeByte(BIGINTEGER); writeBigInteger(out, (BigInteger) val); break; case DataType.BIGDECIMAL: out.writeByte(BIGDECIMAL); writeBigDecimal(out, (BigDecimal) val); break; case DataType.DOUBLE: out.writeByte(DOUBLE); out.writeDouble((Double) val); break; case DataType.BOOLEAN: if ((Boolean) val) out.writeByte(BOOLEAN_TRUE); else out.writeByte(BOOLEAN_FALSE); break; case DataType.BYTE: out.writeByte(BYTE); out.writeByte((Byte) val); break; case DataType.BYTEARRAY: { DataByteArray bytes = (DataByteArray) val; SedesHelper.writeBytes(out, bytes.mData); break; } case DataType.CHARARRAY: { SedesHelper.writeChararray(out, (String) val); break; } case DataType.GENERIC_WRITABLECOMPARABLE: out.writeByte(GENERIC_WRITABLECOMPARABLE); // store the class name, so we know the class to create on read writeDatum(out, val.getClass().getName()); Writable writable = (Writable) val; writable.write(out); break; case DataType.NULL: out.writeByte(NULL); break; default: throw new RuntimeException("Unexpected data type " + val.getClass().getName() + " found in stream. " + "Note only standard Pig type is supported when you output from UDF/LoadFunc"); } }
From source file:org.apache.pig.data.DataReaderWriter.java
@SuppressWarnings("unchecked") public static void writeDatum(DataOutput out, Object val) throws IOException { // Read the data type byte type = DataType.findType(val); switch (type) { case DataType.TUPLE: // Because tuples are written directly by hadoop, the // tuple's write method needs to write the indicator byte. // So don't write the indicator byte here as it is for // everyone else. ((Tuple) val).write(out); break;/* ww w .j a v a 2 s . c om*/ case DataType.BAG: out.writeByte(DataType.BAG); ((DataBag) val).write(out); break; case DataType.MAP: { out.writeByte(DataType.MAP); Map<String, Object> m = (Map<String, Object>) val; out.writeInt(m.size()); Iterator<Map.Entry<String, Object>> i = m.entrySet().iterator(); while (i.hasNext()) { Map.Entry<String, Object> entry = i.next(); writeDatum(out, entry.getKey()); writeDatum(out, entry.getValue()); } break; } case DataType.INTERNALMAP: { out.writeByte(DataType.INTERNALMAP); Map<Object, Object> m = (Map<Object, Object>) val; out.writeInt(m.size()); Iterator<Map.Entry<Object, Object>> i = m.entrySet().iterator(); while (i.hasNext()) { Map.Entry<Object, Object> entry = i.next(); writeDatum(out, entry.getKey()); writeDatum(out, entry.getValue()); } break; } case DataType.INTEGER: out.writeByte(DataType.INTEGER); out.writeInt((Integer) val); break; case DataType.LONG: out.writeByte(DataType.LONG); out.writeLong((Long) val); break; case DataType.FLOAT: out.writeByte(DataType.FLOAT); out.writeFloat((Float) val); break; case DataType.DOUBLE: out.writeByte(DataType.DOUBLE); out.writeDouble((Double) val); break; case DataType.BOOLEAN: out.writeByte(DataType.BOOLEAN); out.writeBoolean((Boolean) val); break; case DataType.BYTE: out.writeByte(DataType.BYTE); out.writeByte((Byte) val); break; case DataType.BYTEARRAY: { out.writeByte(DataType.BYTEARRAY); DataByteArray bytes = (DataByteArray) val; out.writeInt(bytes.size()); out.write(bytes.mData); break; } case DataType.CHARARRAY: { String s = (String) val; byte[] utfBytes = s.getBytes(DataReaderWriter.UTF8); int length = utfBytes.length; if (length < DataReaderWriter.UNSIGNED_SHORT_MAX) { out.writeByte(DataType.CHARARRAY); out.writeShort(length); out.write(utfBytes); } else { out.writeByte(DataType.BIGCHARARRAY); out.writeInt(length); out.write(utfBytes); } break; } case DataType.GENERIC_WRITABLECOMPARABLE: out.writeByte(DataType.GENERIC_WRITABLECOMPARABLE); //store the class name, so we know the class to create on read writeDatum(out, val.getClass().getName()); Writable writable = (Writable) val; writable.write(out); break; case DataType.NULL: out.writeByte(DataType.NULL); break; default: throw new RuntimeException("Unexpected data type " + type + " found in stream."); } }
From source file:org.apache.pig.data.SchemaTuple.java
protected static void write(DataOutput out, float v) throws IOException { out.writeFloat(v); }
From source file:org.apache.tez.mapreduce.hadoop.MRTaskStatus.java
@Override public void write(DataOutput out) throws IOException { taskAttemptId.write(out);//from w w w .ja v a2 s .c om WritableUtils.writeEnum(out, state); out.writeFloat(progress); WritableUtils.writeString(out, diagnostics); WritableUtils.writeString(out, userStatusInfo); WritableUtils.writeEnum(out, phase); counters.write(out); out.writeLong(localOutputSize); out.writeLong(startTime); out.writeLong(finishTime); out.writeLong(sortFinishTime); out.writeLong(mapFinishTime); out.writeLong(shuffleFinishTime); out.writeInt(failedTaskDependencies.size()); for (TezTaskAttemptID taskAttemptId : failedTaskDependencies) { taskAttemptId.write(out); } }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Write a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//* w w w. ja va2 s . c o m*/ public static void writeObject(DataOutput out, Object instance, Class declaredClass, CloudataConf conf, boolean arrayComponent) throws IOException { if (instance == null) { // null instance = new NullInstance(declaredClass, conf); declaredClass = CWritable.class; arrayComponent = false; } if (!arrayComponent) { CUTF8.writeString(out, declaredClass.getName()); // always write declared //System.out.println("Write:declaredClass.getName():" + declaredClass.getName()); } if (declaredClass.isArray()) { // array int length = Array.getLength(instance); out.writeInt(length); //System.out.println("Write:length:" + length); if (declaredClass.getComponentType() == Byte.TYPE) { out.write((byte[]) instance); } else if (declaredClass.getComponentType() == ColumnValue.class) { //ColumnValue? Deserialize? ?? ? ?? ? . writeColumnValue(out, instance, declaredClass, conf, length); } else { for (int i = 0; i < length; i++) { writeObject(out, Array.get(instance, i), declaredClass.getComponentType(), conf, !declaredClass.getComponentType().isArray()); } } } else if (declaredClass == String.class) { // String CUTF8.writeString(out, (String) instance); } else if (declaredClass.isPrimitive()) { // primitive type if (declaredClass == Boolean.TYPE) { // boolean out.writeBoolean(((Boolean) instance).booleanValue()); } else if (declaredClass == Character.TYPE) { // char out.writeChar(((Character) instance).charValue()); } else if (declaredClass == Byte.TYPE) { // byte out.writeByte(((Byte) instance).byteValue()); } else if (declaredClass == Short.TYPE) { // short out.writeShort(((Short) instance).shortValue()); } else if (declaredClass == Integer.TYPE) { // int out.writeInt(((Integer) instance).intValue()); } else if (declaredClass == Long.TYPE) { // long out.writeLong(((Long) instance).longValue()); } else if (declaredClass == Float.TYPE) { // float out.writeFloat(((Float) instance).floatValue()); } else if (declaredClass == Double.TYPE) { // double out.writeDouble(((Double) instance).doubleValue()); } else if (declaredClass == Void.TYPE) { // void } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isEnum()) { // enum CUTF8.writeString(out, ((Enum) instance).name()); } else if (CWritable.class.isAssignableFrom(declaredClass)) { // Writable if (instance.getClass() == declaredClass) { out.writeShort(TYPE_SAME); // ? ?? ? ?? //System.out.println("Write:TYPE_SAME:" + TYPE_SAME); } else { out.writeShort(TYPE_DIFF); //System.out.println("Write:TYPE_DIFF:" + TYPE_DIFF); CUTF8.writeString(out, instance.getClass().getName()); //System.out.println("Write:instance.getClass().getName():" + instance.getClass().getName()); } ((CWritable) instance).write(out); //System.out.println("Write:instance value"); } else { throw new IOException("Can't write: " + instance + " as " + declaredClass); } }
From source file:TVA.Hadoop.MapReduce.Historian.File.StandardPointFile.java
/** * Serializes the point to disk./*w ww . j a va2 s . c o m*/ * * @param out A DataOutput object to write data to. * @see DataOutput * @see org.apache.hadoop.io.Writable#write(java.io.DataOutput) * */ public void write(DataOutput out) throws IOException { out.writeInt(iTimeTag); out.writeShort(this.Flags); out.writeFloat(this.Value); out.writeInt(this.iPointID); }