list.add(123456789L);
Map<Object, Object> map = new HashMap<Object, Object>();
map.put("one", 1);
map.put("vector", vector);
Object[] objects = new Object[] {
new Buffer(new byte[] { 1, 2, 3, 4 }),
(byte) 123, true, 12345, 123456789L, (float) 1.2, 1.234,
"random string", vector, list, map
};
byte[] appSpecificBytes = new byte[] { 1, 2, 3 };
FileOutputStream ostream = new FileOutputStream(tmpfile);
DataOutputStream dostream = new DataOutputStream(ostream);
TypedBytesOutput out = new TypedBytesOutput(dostream);
for (Object obj : objects) {
out.write(obj);
}
out.writeBytes(appSpecificBytes, 100);
dostream.close();
ostream.close();
FileInputStream istream = new FileInputStream(tmpfile);
DataInputStream distream = new DataInputStream(istream);
TypedBytesInput in = new TypedBytesInput(distream);
for (Object obj : objects) {
assertEquals(obj, in.read());
}
assertEquals(new Buffer(appSpecificBytes), in.read());
distream.close();
istream.close();
istream = new FileInputStream(tmpfile);
distream = new DataInputStream(istream);
in = new TypedBytesInput(distream);
for (Object obj : objects) {
byte[] bytes = in.readRaw();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
DataInputStream dis = new DataInputStream(bais);
assertEquals(obj, (new TypedBytesInput(dis)).read());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
TypedBytesOutput tbout = new TypedBytesOutput(new DataOutputStream(baos));
tbout.writeRaw(bytes);
bais = new ByteArrayInputStream(bytes);
dis = new DataInputStream(bais);
assertEquals(obj, (new TypedBytesInput(dis)).read());
}
byte[] rawBytes = in.readRaw();
assertEquals(new Buffer(appSpecificBytes),
new Buffer(rawBytes, 5, rawBytes.length - 5));
distream.close();
istream.close();
}