Search in sources :

Example 36 with DataInput

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

Example 37 with DataInput

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

Example 38 with DataInput

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

Example 39 with DataInput

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

Example 40 with DataInput

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);
}
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