public ArrayWritable readArray(ArrayWritable aw) throws IOException { if (aw == null) { aw = new ArrayWritable(TypedBytesWritable.class); } else if (!aw.getValueClass().equals(TypedBytesWritable.class)) { throw new RuntimeException("value class has to be TypedBytesWritable"); } int length = in.readVectorHeader(); Writable[] writables = new Writable[length]; for (int i = 0; i < length; i++) { writables[i] = new TypedBytesWritable(in.readRaw()); } aw.set(writables); return aw; }
public Text readText(Text t) throws IOException { if (t == null) { t = new Text(); } t.set(in.readString()); return t; }
public FloatWritable readFloat(FloatWritable fw) throws IOException { if (fw == null) { fw = new FloatWritable(); } fw.set(in.readFloat()); return fw; }
public DoubleWritable readDouble(DoubleWritable dw) throws IOException { if (dw == null) { dw = new DoubleWritable(); } dw.set(in.readDouble()); return dw; }
public VIntWritable readVInt(VIntWritable iw) throws IOException { if (iw == null) { iw = new VIntWritable(); } iw.set(in.readInt()); return iw; }
public VLongWritable readVLong(VLongWritable lw) throws IOException { if (lw == null) { lw = new VLongWritable(); } lw.set(in.readLong()); return lw; }
public BooleanWritable readBoolean(BooleanWritable bw) throws IOException { if (bw == null) { bw = new BooleanWritable(); } bw.set(in.readBool()); return bw; }
public ShortWritable readShort(ShortWritable sw) throws IOException { if (sw == null) { sw = new ShortWritable(); } sw.set(in.readShort()); return sw; }
public ByteWritable readByte(ByteWritable bw) throws IOException { if (bw == null) { bw = new ByteWritable(); } bw.set(in.readByte()); return bw; }
public BytesWritable readBytes(BytesWritable bw) throws IOException { byte[] bytes = in.readBytes(); if (bw == null) { bw = new BytesWritable(bytes); } else { bw.set(bytes, 0, bytes.length); } return bw; }
public SortedMapWritable readSortedMap(SortedMapWritable mw) throws IOException { if (mw == null) { mw = new SortedMapWritable(); } int length = in.readMapHeader(); for (int i = 0; i < length; i++) { WritableComparable key = (WritableComparable) read(); Writable value = read(); mw.put(key, value); } return mw; }
public Writable readWritable(Writable writable) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(in.readBytes()); DataInputStream dis = new DataInputStream(bais); String className = WritableUtils.readString(dis); if (writable == null) { try { Class<? extends Writable> cls = conf.getClassByName(className).asSubclass(Writable.class); writable = (Writable) ReflectionUtils.newInstance(cls, conf); } catch (ClassNotFoundException e) { throw new IOException(e); } } else if (!writable.getClass().getName().equals(className)) { throw new IOException("wrong Writable class given"); } writable.readFields(dis); return writable; }
public Class<? extends Writable> readType() throws IOException { Type type = in.readType(); if (type == null) { return null; } switch (type) { case BYTES: return BytesWritable.class; case BYTE: return ByteWritable.class; case BOOL: return BooleanWritable.class; case INT: return VIntWritable.class; case LONG: return VLongWritable.class; case FLOAT: return FloatWritable.class; case SHORT: return ShortWritable.class; case DOUBLE: return DoubleWritable.class; case STRING: return Text.class; case VECTOR: return ArrayWritable.class; case MAP: return MapWritable.class; case WRITABLE: return Writable.class; case ENDOFRECORD: return null; case NULL: return NullWritable.class; default: throw new RuntimeException("unknown type"); } }
public Writable read() throws IOException { Type type = in.readType(); if (type == null) { return null; } switch (type) { case BYTES: return readBytes(); case BYTE: return readByte(); case BOOL: return readBoolean(); case INT: return readVInt(); case SHORT: return readShort(); case LONG: return readVLong(); case FLOAT: return readFloat(); case DOUBLE: return readDouble(); case STRING: return readText(); case VECTOR: return readArray(); case MAP: return readMap(); case WRITABLE: return readWritable(); case ENDOFRECORD: return null; case NULL: return NullWritable.get(); default: throw new RuntimeException("unknown type"); } }
/** * Get a thread-local typed bytes writable input for the supplied {@link DataInput}. * * @param in data input object * @return typed bytes writable input corresponding to the supplied {@link DataInput}. */ public static TypedBytesWritableInput get(DataInput in) { return get(TypedBytesInput.get(in)); }
public Type readTypeCode() throws IOException { return in.readType(); }