@Override protected Object initialValue() { return new TypedBytesInput(); } };
/** Get the typed bytes as a Java object. */ public Object getValue() { try { ByteArrayInputStream bais = new ByteArrayInputStream(getBytes()); TypedBytesInput tbi = TypedBytesInput.get(new DataInputStream(bais)); Object obj = tbi.read(); return obj; } catch (IOException e) { throw new RuntimeException(e); } }
return readByte(); } else if (code == Type.BOOL.code) { return readBool(); } else if (code == Type.INT.code) { return readInt(); } else if (code == Type.SHORT.code) { return readShort(); } else if (code == Type.LONG.code) { return readLong(); } else if (code == Type.FLOAT.code) { return readFloat(); } else if (code == Type.DOUBLE.code) { return readDouble(); } else if (code == Type.STRING.code) { return readString(); } else if (code == Type.VECTOR.code) { return readVector(); } else if (code == Type.LIST.code) { return readList(); } else if (code == Type.MAP.code) { return readMap(); } else if (code == Type.MARKER.code) { return null;
public double readDouble(String tag) throws IOException { in.skipType(); return in.readDouble(); }
/** * Reads the vector following a <code>Type.VECTOR</code> code. * * @return the obtained vector * @throws IOException */ @SuppressWarnings("unchecked") public ArrayList readVector() throws IOException { int length = readVectorHeader(); ArrayList result = new ArrayList(length); for (int i = 0; i < length; i++) { result.add(read()); } return result; }
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 IntWritable readInt(IntWritable iw) throws IOException { if (iw == null) { iw = new IntWritable(); } iw.set(in.readInt()); return iw; }
/** * Get a thread-local typed bytes record input for the supplied * {@link DataInput}. * * @param in * data input object * @return typed bytes record input corresponding to the supplied * {@link DataInput}. */ public static TypedBytesRecordInput get(DataInput in) { return get(TypedBytesInput.get(in)); }
/** * Reads the map following a <code>Type.MAP</code> code. * * @return the obtained map * @throws IOException */ @SuppressWarnings("unchecked") public TreeMap readMap() throws IOException { int length = readMapHeader(); TreeMap result = new TreeMap(); for (int i = 0; i < length; i++) { Object key = read(); Object value = read(); result.put(key, value); } return result; }
public DoubleWritable readDouble(DoubleWritable dw) throws IOException { if (dw == null) { dw = new DoubleWritable(); } dw.set(in.readDouble()); return dw; }
public ByteWritable readByte(ByteWritable bw) throws IOException { if (bw == null) { bw = new ByteWritable(); } bw.set(in.readByte()); return bw; }
public BooleanWritable readBoolean(BooleanWritable bw) throws IOException { if (bw == null) { bw = new BooleanWritable(); } bw.set(in.readBool()); return bw; }
public FloatWritable readFloat(FloatWritable fw) throws IOException { if (fw == null) { fw = new FloatWritable(); } fw.set(in.readFloat()); return fw; }
/** * Reads the list following a <code>Type.LIST</code> code. * * @return the obtained list * @throws IOException */ @SuppressWarnings("unchecked") public List readList() throws IOException { List list = new ArrayList(); Object obj = read(); while (obj != null) { list.add(obj); obj = read(); } return list; }