Search in sources :

Example 21 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 22 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 23 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)

Example 24 with DataInput

use of java.io.DataInput in project geode by apache.

the class DataSerializableJUnitTest method testInteger.

/**
   * Tests data serializing a {@link Integer}
   */
@Test
public void testInteger() throws Exception {
    Integer value = new Integer(getRandom().nextInt());
    DataOutputStream out = getDataOutput();
    DataSerializer.writeInteger(value, out);
    out.flush();
    DataInput in = getDataInput();
    Integer value2 = DataSerializer.readInteger(in);
    assertEquals(value, value2);
}
Also used : BigInteger(java.math.BigInteger) DataInput(java.io.DataInput) DataOutputStream(java.io.DataOutputStream) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 25 with DataInput

use of java.io.DataInput in project geode by apache.

the class DataSerializableJUnitTest method testBooleanObject.

/**
   * Tests data serializing a {@link Boolean} using {@link DataSerializer#writeObject}.
   */
@Test
public void testBooleanObject() throws Exception {
    Boolean value = new Boolean(getRandom().nextInt() % 2 == 0);
    DataOutputStream out = getDataOutput();
    DataSerializer.writeObject(value, out);
    out.flush();
    DataInput in = getDataInput();
    Boolean value2 = (Boolean) DataSerializer.readObject(in);
    assertEquals(value, value2);
}
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)295 Test (org.junit.Test)141 DataInputStream (java.io.DataInputStream)139 ByteArrayInputStream (java.io.ByteArrayInputStream)125 DataOutputStream (java.io.DataOutputStream)122 UnitTest (org.apache.geode.test.junit.categories.UnitTest)96 IOException (java.io.IOException)39 ByteArrayOutputStream (java.io.ByteArrayOutputStream)34 DataOutput (java.io.DataOutput)26 ArrayList (java.util.ArrayList)17 ARecord (org.apache.asterix.om.base.ARecord)14 BufferedInputStream (java.io.BufferedInputStream)11 EOFException (java.io.EOFException)11 ByteBuffer (java.nio.ByteBuffer)10 BigInteger (java.math.BigInteger)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 ChannelDataInput (org.apache.sis.internal.storage.io.ChannelDataInput)7