List of usage examples for java.io DataOutput writeByte
void writeByte(int v) throws IOException;
v
. From source file:org.apache.pig.data.BinInterSedes.java
private void writeMap(DataOutput out, Map<String, Object> m) throws IOException { final int sz = m.size(); if (sz < UNSIGNED_BYTE_MAX) { out.writeByte(TINYMAP); out.writeByte(sz);/*from w w w . ja va 2 s . c o m*/ } else if (sz < UNSIGNED_SHORT_MAX) { out.writeByte(SMALLMAP); out.writeShort(sz); } else { out.writeByte(MAP); out.writeInt(sz); } 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()); } }
From source file:org.apache.pig.data.BinInterSedes.java
private void writeBag(DataOutput out, DataBag bag) 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. final long sz = bag.size(); if (sz < UNSIGNED_BYTE_MAX) { out.writeByte(TINYBAG); out.writeByte((int) sz); } else if (sz < UNSIGNED_SHORT_MAX) { out.writeByte(SMALLBAG);/*from w w w . java 2 s .c o m*/ out.writeShort((int) sz); } else { out.writeByte(BAG); out.writeLong(sz); } Iterator<Tuple> it = bag.iterator(); while (it.hasNext()) { writeTuple(out, it.next()); } }
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 w w w .j av a 2 s. c o m 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.DefaultTuple.java
@Override public void write(DataOutput out) throws IOException { out.writeByte(DataType.TUPLE); int sz = size(); out.writeInt(sz);/*from w w w. j a va2 s . co m*/ for (int i = 0; i < sz; i++) { DataReaderWriter.writeDatum(out, mFields.get(i)); } }
From source file:org.apache.pig.data.SchemaTuple.java
protected void write(DataOutput out, boolean writeIdentifiers) throws IOException { if (writeIdentifiers) { int id = getSchemaTupleIdentifier(); if (id < BinInterSedes.UNSIGNED_BYTE_MAX) { out.writeByte(BinInterSedes.SCHEMA_TUPLE_BYTE_INDEX); out.writeByte(id);/*from w w w . j av a 2 s . c o m*/ } else if (id < BinInterSedes.UNSIGNED_SHORT_MAX) { out.writeByte(BinInterSedes.SCHEMA_TUPLE_SHORT_INDEX); out.writeShort(id); } else { out.writeByte(BinInterSedes.SCHEMA_TUPLE); out.writeInt(id); } } writeElements(out); }
From source file:org.apache.spark.tez.io.TypeAwareWritable.java
/** * // www . j av a 2s.c om */ @Override public void write(DataOutput out) throws IOException { out.writeByte(this.valueType); if (this.valueType != NULL) { out.write(this.valueEncoder.valueBytes); } }
From source file:org.apache.sysml.runtime.compress.CompressedMatrixBlock.java
@Override public void write(DataOutput out) throws IOException { out.writeBoolean(isCompressed());/* w w w .j av a 2 s. co m*/ //serialize uncompressed block if (!isCompressed()) { super.write(out); return; } //serialize compressed matrix block out.writeInt(rlen); out.writeInt(clen); out.writeLong(nonZeros); out.writeInt(_colGroups.size()); for (ColGroup grp : _colGroups) { out.writeByte(grp.getCompType().ordinal()); grp.write(out); //delegate serialization } }
From source file:org.apache.sysml.runtime.matrix.data.FrameBlock.java
@Override public void write(DataOutput out) throws IOException { boolean isDefaultMeta = isColNamesDefault() && isColumnMetadataDefault(); //write header (rows, cols, default) out.writeInt(getNumRows());// ww w. jav a 2 s.c om out.writeInt(getNumColumns()); out.writeBoolean(isDefaultMeta); //write columns (value type, data) for (int j = 0; j < getNumColumns(); j++) { out.writeByte(_schema[j].ordinal()); if (!isDefaultMeta) { out.writeUTF(getColumnName(j)); out.writeLong(_colmeta[j].getNumDistinct()); out.writeUTF((_colmeta[j].getMvValue() != null) ? _colmeta[j].getMvValue() : ""); } _coldata[j].write(out); } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeEmptyBlock(DataOutput out) throws IOException { //empty blocks do not need to materialize row information out.writeByte(BlockType.EMPTY_BLOCK.ordinal()); }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void writeDenseBlock(DataOutput out) throws IOException { out.writeByte(BlockType.DENSE_BLOCK.ordinal()); int limit = rlen * clen; if (out instanceof MatrixBlockDataOutput) //fast serialize ((MatrixBlockDataOutput) out).writeDoubleArray(limit, denseBlock); else //general case (if fast serialize not supported) for (int i = 0; i < limit; i++) out.writeDouble(denseBlock[i]); }