new FloatWritable((float) 1.2), new DoubleWritable(1.234),
new Text("random string")
};
TypedBytesWritable tbw = new TypedBytesWritable();
tbw.setValue("typed bytes text");
RecRecord1 r1 = new RecRecord1();
r1.setBoolVal(true);
r1.setByteVal((byte) 0x66);
r1.setFloatVal(3.145F);
r1.setDoubleVal(1.5234);
r1.setIntVal(-4567);
r1.setLongVal(-2367L);
r1.setStringVal("random text");
r1.setBufferVal(new Buffer());
r1.setVectorVal(new ArrayList<String>());
r1.setMapVal(new TreeMap<String, String>());
RecRecord0 r0 = new RecRecord0();
r0.setStringVal("other random text");
r1.setRecordVal(r0);
FileOutputStream ostream = new FileOutputStream(tmpfile);
DataOutputStream dostream = new DataOutputStream(ostream);
TypedBytesWritableOutput out = new TypedBytesWritableOutput(dostream);
for (Writable w : writables) {
out.write(w);
}
out.write(tbw);
out.write(vector);
out.write(map);
out.write(r1);
dostream.close();
ostream.close();
FileInputStream istream = new FileInputStream(tmpfile);
DataInputStream distream = new DataInputStream(istream);
TypedBytesWritableInput in = new TypedBytesWritableInput(distream);
for (Writable w : writables) {
assertEquals(w, in.read());
}
assertEquals(tbw.getValue().toString(), in.read().toString());
assertEquals(ArrayWritable.class, in.readType());
ArrayWritable aw = in.readArray();
Writable[] writables1 = vector.get(), writables2 = aw.get();
assertEquals(writables1.length, writables2.length);
for (int i = 0; i < writables1.length; i++) {
assertEquals(((Text) writables1[i]).toString(),
((TypedBytesWritable) writables2[i]).getValue());
}
assertEquals(MapWritable.class, in.readType());
MapWritable mw = in.readMap();
assertEquals(map.entrySet(), mw.entrySet());
assertEquals(Type.LIST, TypedBytesInput.get(distream).readType());
assertEquals(r1.getBoolVal(), TypedBytesInput.get(distream).read());
assertEquals(r1.getByteVal(), TypedBytesInput.get(distream).read());
assertEquals(r1.getIntVal(), TypedBytesInput.get(distream).read());
assertEquals(r1.getLongVal(), TypedBytesInput.get(distream).read());
assertEquals(r1.getFloatVal(), TypedBytesInput.get(distream).read());
assertEquals(r1.getDoubleVal(), TypedBytesInput.get(distream).read());
assertEquals(r1.getStringVal(), TypedBytesInput.get(distream).read());
Object prevObj = null, obj = TypedBytesInput.get(distream).read();
while (obj != null) {
prevObj = obj;
obj = TypedBytesInput.get(distream).read();
}