use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testVectorObject.
/**
* Tests data serializing an {@link Vector} using {@link DataSerializer#writeObject}.
*/
@Test
public void testVectorObject() throws Exception {
Random random = getRandom();
Vector list = new Vector();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
list.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(list, out);
out.flush();
DataInput in = getDataInput();
Vector list2 = (Vector) DataSerializer.readObject(in);
assertEquals(list, list2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testWriteObjectAsByteArray.
@Test
public void testWriteObjectAsByteArray() throws Exception {
// make sure recursive calls to WriteObjectAsByteArray work to test bug 38194
Object v = new WOABA();
DataOutputStream out = getDataOutput();
DataSerializer.writeObjectAsByteArray(v, out);
out.flush();
DataInput in = getDataInput();
byte[] b2 = DataSerializer.readByteArray(in);
// todo should we deserislize the byte[] and make sure it is equal to v?
ByteArrayInputStream bais = new ByteArrayInputStream(b2);
DataInputStream dis = new DataInputStream(bais);
Object v2 = DataSerializer.readObject(dis);
if (!(v2 instanceof WOABA)) {
fail("expected instance of WOABA but found " + v2.getClass());
}
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testBigInteger.
@Test
public void testBigInteger() throws Exception {
BigInteger o = new BigInteger("12345678901234567890");
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(o, out, false);
out.flush();
DataInput in = getDataInput();
BigInteger o2 = (BigInteger) DataSerializer.readObject(in);
assertEquals(o, o2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testProperties.
@Test
public void testProperties() throws Exception {
DataOutputStream out = getDataOutput();
DataSerializer.writeProperties(new Properties(), out);
DataSerializer.writeProperties(null, out);
Properties p1 = new Properties();
p1.setProperty("aKey1", "aValue1");
p1.setProperty("aKey2", "aValue2");
DataSerializer.writeProperties(p1, out);
Properties p2 = new Properties();
p2.put("aKey1", new Integer(1));
p2.put("aKey2", new Integer(2));
DataSerializer.writeProperties(p2, out);
out.flush();
DataInput in = getDataInput();
assertEquals(new Properties(), DataSerializer.readProperties(in));
assertEquals(null, DataSerializer.readProperties(in));
assertEquals(p1, DataSerializer.readProperties(in));
assertEquals(p2, DataSerializer.readProperties(in));
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testDoubleObject.
/**
* Tests data serializing a {@link Double} using {@link DataSerializer#writeObject}.
*/
@Test
public void testDoubleObject() throws Exception {
Double value = new Double(getRandom().nextDouble());
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(value, out);
out.flush();
DataInput in = getDataInput();
Double value2 = (Double) DataSerializer.readObject(in);
assertEquals(value, value2);
}
Aggregations