List of usage examples for java.io DataOutput write
void write(byte b[]) throws IOException;
b
. 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);// w w w .j a v a 2 s. c o m // write model path if (this.modelPath != null) { WritableUtils.writeString(output, modelPath); } else { 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.nutch.crawl.CrawlDatum.java
public void write(DataOutput out) throws IOException { out.writeByte(CUR_VERSION); // store current version out.writeByte(status);// www . j av a 2 s . c o m 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.nutch.protocol.Content.java
public final void write(DataOutput out) throws IOException { out.writeInt(VERSION);/*from ww w. j a va 2 s. c o m*/ Text.writeString(out, url); // write url Text.writeString(out, base); // write base out.writeInt(content.length); // write content out.write(content); Text.writeString(out, contentType); // write contentType metadata.write(out); // write metadata }
From source file:org.apache.pig.data.DataBag.java
/** * Write a bag's contents to disk./*w w w . j a va 2 s . co m*/ * @param out DataOutput to write data to. * @throws IOException (passes it on from underlying calls). */ @Override public void write(DataOutput out) throws IOException { // We don't care whether this bag was sorted or distinct because // using the iterator to write it will guarantee those things come // correctly. And on the other end there'll be no reason to waste // time re-sorting or re-applying distinct. out.write(BAG); out.writeLong(size()); for (Tuple t : this) { t.write(out); } }
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;//from ww w . j av a 2 s .com 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.Tuple.java
@Override public void write(DataOutput out) throws IOException { out.write(TUPLE); int n = arity(); encodeInt(out, n);/* ww w .jav a 2 s . co m*/ for (int i = 0; i < n; i++) { Datum d = getField(i); if (d != null) { d.write(out); } else { throw new RuntimeException("Null field in tuple"); } } }
From source file:org.apache.pig.data.Tuple.java
static void encodeInt(DataOutput os, int i) throws IOException { if (i >> 28 != 0) os.write((i >> 28) & 0x7f); if (i >> 21 != 0) os.write((i >> 21) & 0x7f); if (i >> 14 != 0) os.write((i >> 14) & 0x7f); if (i >> 7 != 0) os.write((i >> 7) & 0x7f); os.write((i & 0x7f) | (1 << 7)); }
From source file:org.apache.rya.accumulo.mr.RyaStatementWritable.java
/** * Write part of a statement to an output stream. * @param dataOutput Stream for writing serialized statements. * @param row Individual field to write, as a byte array. * @throws IOException if writing to the stream fails. *///from w ww .ja v a 2 s .co m protected void write(DataOutput dataOutput, byte[] row) throws IOException { boolean b = row != null; dataOutput.writeBoolean(b); if (b) { dataOutput.writeInt(row.length); dataOutput.write(row); } }
From source file:org.apache.rya.reasoning.mr.SchemaWritable.java
@Override public void write(DataOutput out) throws IOException { ArrayList<OwlProperty> propList = new ArrayList<>(properties.values()); ArrayList<OwlClass> classList = new ArrayList<>(classes.values()); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(propList);/*from ww w . ja v a 2 s. co m*/ stream.writeObject(classList); byte[] arr = bytes.toByteArray(); stream.close(); out.writeInt(arr.length); out.write(arr); }
From source file:org.apache.spark.tez.io.TypeAwareWritable.java
/** * //www. ja v a 2 s . co m */ @Override public void write(DataOutput out) throws IOException { out.writeByte(this.valueType); if (this.valueType != NULL) { out.write(this.valueEncoder.valueBytes); } }