use of java.io.DataInput in project gora by apache.
the class TestWritableUtils method testWritesReads.
@Test
public void testWritesReads() throws Exception {
Properties props = new Properties();
props.put("keyBlah", "valueBlah");
props.put("keyBlah2", "valueBlah2");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutput out = new DataOutputStream(bos);
WritableUtils.writeProperties(out, props);
((DataOutputStream) out).flush();
DataInput in = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
Properties propsRead = WritableUtils.readProperties(in);
assertEquals(propsRead.get("keyBlah"), props.get("keyBlah"));
assertEquals(propsRead.get("keyBlah2"), props.get("keyBlah2"));
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testFile.
/**
* Tests data serializing a {@link File}
*/
@Test
public void testFile() throws Exception {
File file = new File(System.getProperty("user.dir"));
DataOutputStream out = getDataOutput();
DataSerializer.writeFile(file, out);
out.flush();
DataInput in = getDataInput();
File file2 = DataSerializer.readFile(in);
assertEquals(file, file2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testObjectArrayObject.
/**
* Tests data serializing a <code>Object</code> array using {@link DataSerializer#writeObject}.
*/
@Test
public void testObjectArrayObject() throws Exception {
Random random = getRandom();
SerializableImpl[] array = new SerializableImpl[] { new SerializableImpl(random), new SerializableImpl(random), new SerializableImpl(random) };
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(array, out);
out.flush();
DataInput in = getDataInput();
SerializableImpl[] array2 = (SerializableImpl[]) 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 testFileObject.
/**
* Tests data serializing a {@link File} using {@link DataSerializer#writeObject}.
*/
@Test
public void testFileObject() throws Exception {
File file = new File(System.getProperty("user.dir"));
DataOutputStream out = getDataOutput();
DataSerializer.writeObject(file, out);
out.flush();
DataInput in = getDataInput();
File file2 = (File) DataSerializer.readObject(in);
assertEquals(file, file2);
}
use of java.io.DataInput in project geode by apache.
the class DataSerializableJUnitTest method testClass.
/**
* Tests data serializing a {@link Class}
*/
@Test
public void testClass() throws Exception {
Class c = this.getClass();
DataOutputStream out = getDataOutput();
DataSerializer.writeClass(c, out);
out.flush();
DataInput in = getDataInput();
Class c2 = DataSerializer.readClass(in);
assertEquals(c, c2);
}
Aggregations