Search in sources :

Example 46 with DataInput

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"));
}
Also used : DataInput(java.io.DataInput) DataOutput(java.io.DataOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 47 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) File(java.io.File) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 48 with DataInput

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]);
    }
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 49 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) File(java.io.File) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 50 with DataInput

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);
}
Also used : DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

DataInput (java.io.DataInput)247 Test (org.junit.Test)132 DataOutputStream (java.io.DataOutputStream)117 DataInputStream (java.io.DataInputStream)112 ByteArrayInputStream (java.io.ByteArrayInputStream)106 UnitTest (org.apache.geode.test.junit.categories.UnitTest)96 ByteArrayOutputStream (java.io.ByteArrayOutputStream)29 DataOutput (java.io.DataOutput)23 IOException (java.io.IOException)21 ArrayList (java.util.ArrayList)16 ARecord (org.apache.asterix.om.base.ARecord)14 EOFException (java.io.EOFException)9 File (java.io.File)9 BufferedInputStream (java.io.BufferedInputStream)8 HashMap (java.util.HashMap)7 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)7 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)7 GrowableArray (org.apache.hyracks.data.std.util.GrowableArray)7 FileInputStream (java.io.FileInputStream)6 ByteBuffer (java.nio.ByteBuffer)6