@Override protected Object initialValue() { return new TypedBytesOutput(); } };
/** Set the typed bytes from a given Java object. */ public void setValue(Object obj) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); TypedBytesOutput tbo = TypedBytesOutput.get(new DataOutputStream(baos)); tbo.write(obj); byte[] bytes = baos.toByteArray(); set(bytes, 0, bytes.length); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Get a thread-local typed bytes output for the supplied {@link DataOutput}. * * @param out * data output object * @return typed bytes output corresponding to the supplied {@link DataOutput} * . */ public static TypedBytesOutput get(DataOutput out) { TypedBytesOutput bout = (TypedBytesOutput) tbOut.get(); bout.setDataOutput(out); return bout; }
/** * Writes a list as a typed bytes sequence. * * @param list * the list to be written * @throws IOException */ public void writeList(List list) throws IOException { writeListHeader(); for (Object obj : list) { write(obj); } writeListFooter(); }
/** * Writes a vector as a typed bytes sequence. * * @param vector * the vector to be written * @throws IOException */ public void writeVector(ArrayList vector) throws IOException { writeVectorHeader(vector.size()); for (Object obj : vector) { write(obj); } }
writeByte((Byte) obj); } else if (obj instanceof Boolean) { writeBool((Boolean) obj); } else if (obj instanceof Integer) { writeInt((Integer) obj); } else if (obj instanceof Long) { writeLong((Long) obj); } else if (obj instanceof Float) { writeFloat((Float) obj); } else if (obj instanceof Double) { writeDouble((Double) obj); } else if (obj instanceof String) { writeString((String) obj); } else if (obj instanceof ArrayList) { writeVector((ArrayList) obj); } else if (obj instanceof List) { writeList((List) obj); } else if (obj instanceof Map) { writeMap((Map) obj); } else { throw new RuntimeException("cannot write objects of this type");
/** * Writes a bytes array as a typed bytes sequence. * * @param bytes * the bytes array to be written * @throws IOException */ public void writeBytes(byte[] bytes) throws IOException { writeBytes(bytes, Type.BYTES.code); }
public void writeByte(byte b, String tag) throws IOException { out.writeByte(b); }
public void writeBool(boolean b, String tag) throws IOException { out.writeBool(b); }
public void writeFloat(float f, String tag) throws IOException { out.writeFloat(f); }
public void writeDouble(double d, String tag) throws IOException { out.writeDouble(d); }
/** * Get a thread-local typed bytes writable output for the supplied * {@link DataOutput}. * * @param out * data output object * @return typed bytes writable output corresponding to the supplied * {@link DataOutput}. */ public static TypedBytesWritableOutput get(DataOutput out) { return get(TypedBytesOutput.get(out)); }
/** * Writes a map as a typed bytes sequence. * * @param map * the map to be written * @throws IOException */ @SuppressWarnings("unchecked") public void writeMap(Map map) throws IOException { writeMapHeader(map.size()); Set<Entry> entries = map.entrySet(); for (Entry entry : entries) { write(entry.getKey()); write(entry.getValue()); } }
public void writeEndOfRecord() throws IOException { out.writeEndOfRecord(); } }
writeBytes(((Buffer) obj).get()); } else if (obj instanceof Byte) { writeByte((Byte) obj); } else if (obj instanceof Boolean) { writeBool((Boolean) obj); } else if (obj instanceof Integer) { writeInt((Integer) obj); } else if (obj instanceof Long) { writeLong((Long) obj); } else if (obj instanceof Float) { writeFloat((Float) obj); } else if (obj instanceof Double) { writeDouble((Double) obj); } else if (obj instanceof String) { writeString((String) obj); } else if (obj instanceof ArrayList) { writeVector((ArrayList) obj); } else if (obj instanceof List) { writeList((List) obj); } else if (obj instanceof Map) { writeMap((Map) obj); } else { throw new RuntimeException("cannot write objects of this type");
/** * Writes a vector as a typed bytes sequence. * * @param vector * the vector to be written * @throws IOException */ public void writeVector(ArrayList vector) throws IOException { writeVectorHeader(vector.size()); for (Object obj : vector) { write(obj); } }
/** * Writes a list as a typed bytes sequence. * * @param list * the list to be written * @throws IOException */ public void writeList(List list) throws IOException { writeListHeader(); for (Object obj : list) { write(obj); } writeListFooter(); }
public void writeBytes(BytesWritable bw) throws IOException { byte[] bytes = Arrays.copyOfRange(bw.getBytes(), 0, bw.getLength()); out.writeBytes(bytes); }
public void writeByte(ByteWritable bw) throws IOException { out.writeByte(bw.get()); }
public void writeBoolean(BooleanWritable bw) throws IOException { out.writeBool(bw.get()); }