use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testByteArray.
/**
* Tests data serializing a <code>byte</code> array
*/
@Test
public void testByteArray() throws Exception {
byte[] array = new byte[] { (byte) 4, (byte) 5, (byte) 6 };
DataOutputStream out = getDataOutput();
DataSerializer.writeByteArray(array, out);
DataSerializer.writeObject(array, out);
out.flush();
DataInput in = getDataInput();
for (int idx = 0; idx < 2; idx++) {
byte[] array2 = (idx == 0) ? DataSerializer.readByteArray(in) : (byte[]) DataSerializer.readObject(in);
assertEquals(array.length, array2.length);
for (int i = 0; i < array.length; i++) {
assertEquals(array[i], array2[i]);
}
}
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testDouble.
/**
* Tests data serializing a {@link Double}
*/
@Test
public void testDouble() throws Exception {
Double value = new Double(getRandom().nextDouble());
DataOutputStream out = getDataOutput();
DataSerializer.writeDouble(value, out);
out.flush();
DataInput in = getDataInput();
Double value2 = DataSerializer.readDouble(in);
assertEquals(value, value2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testLinkedHashSetObject.
/**
* Tests data serializing an {@link LinkedHashSet} using {@link DataSerializer#writeObject}.
*/
@Test
public void testLinkedHashSetObject() throws Exception {
Random random = getRandom();
LinkedHashSet set = new LinkedHashSet();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
set.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(set, out);
out.flush();
DataInput in = getDataInput();
LinkedHashSet set2 = (LinkedHashSet) DataSerializer.readObject(in);
assertEquals(set, set2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTimeUnitObject.
/**
* Tests data serializing {@link TimeUnit}s using {@link DataSerializer#writeObject}.
*/
@Test
public void testTimeUnitObject() throws Exception {
DataOutputStream out = getDataOutput();
for (TimeUnit v : TimeUnit.values()) {
DataSerializer.writeObject(v, out, false);
}
out.flush();
DataInput in = getDataInput();
for (TimeUnit v : TimeUnit.values()) {
assertEquals(v, DataSerializer.readObject(in));
}
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testTreeSetObject.
/**
* Tests data serializing an {@link TreeSet} using {@link DataSerializer#writeObject}.
*/
@Test
public void testTreeSetObject() throws Exception {
Random random = getRandom();
TreeSet set = new TreeSet();
int size = random.nextInt(50);
for (int i = 0; i < size; i++) {
set.add(new Long(random.nextLong()));
}
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(set, out);
out.flush();
DataInput in = getDataInput();
TreeSet set2 = (TreeSet) DataSerializer.readObject(in);
assertEquals(set, set2);
}
Aggregations