Search in sources :

Example 96 with ObjectInputStream

use of java.io.ObjectInputStream in project robovm by robovm.

the class Test method test_readFloat.

/**
     * java.io.ObjectInputStream#readFloat()
     */
public void test_readFloat() throws IOException {
    oos.writeFloat(Float.MAX_VALUE);
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    assertTrue("Read incorrect float value", ois.readFloat() == Float.MAX_VALUE);
    ois.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 97 with ObjectInputStream

use of java.io.ObjectInputStream in project robovm by robovm.

the class Test method test_ConstructorLjava_io_InputStream.

/**
     * java.io.ObjectInputStream#ObjectInputStream(java.io.InputStream)
     */
public void test_ConstructorLjava_io_InputStream() throws IOException {
    oos.writeDouble(Double.MAX_VALUE);
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    ois.close();
    oos.close();
    try {
        ois = new ObjectInputStream(new ByteArrayInputStream(new byte[90]));
        fail("StreamCorruptedException expected");
    } catch (StreamCorruptedException e) {
    // Expected
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 98 with ObjectInputStream

use of java.io.ObjectInputStream in project robovm by robovm.

the class Test method test_readByte.

/**
     * java.io.ObjectInputStream#readByte()
     */
public void test_readByte() throws IOException {
    oos.writeByte(127);
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    assertEquals("Read incorrect byte value", 127, ois.readByte());
    ois.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 99 with ObjectInputStream

use of java.io.ObjectInputStream in project robovm by robovm.

the class Test method test_readObjectCorrupt.

/**
     * java.io.ObjectInputStream#readObject()
     */
public void test_readObjectCorrupt() throws IOException, ClassNotFoundException {
    byte[] bytes = { 00, 00, 00, 0x64, 0x43, 0x48, (byte) 0xFD, 0x71, 00, 00, 0x0B, (byte) 0xB8, 0x4D, 0x65 };
    ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
    try {
        ObjectInputStream in = new ObjectInputStream(bin);
        in.readObject();
        fail("Unexpected read of corrupted stream");
    } catch (StreamCorruptedException e) {
    // Expected
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 100 with ObjectInputStream

use of java.io.ObjectInputStream in project robovm by robovm.

the class Test method test_read.

/**
     * java.io.ObjectInputStream#read()
     */
public void test_read() throws IOException {
    oos.write('T');
    oos.close();
    ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
    assertEquals("Read incorrect byte value", 'T', ois.read());
    ois.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

ObjectInputStream (java.io.ObjectInputStream)923 ByteArrayInputStream (java.io.ByteArrayInputStream)594 ObjectOutputStream (java.io.ObjectOutputStream)386 ByteArrayOutputStream (java.io.ByteArrayOutputStream)312 IOException (java.io.IOException)294 FileInputStream (java.io.FileInputStream)130 Test (org.junit.Test)103 InputStream (java.io.InputStream)78 File (java.io.File)71 BufferedInputStream (java.io.BufferedInputStream)40 Serializable (java.io.Serializable)31 HashMap (java.util.HashMap)30 Test (org.testng.annotations.Test)26 FileOutputStream (java.io.FileOutputStream)24 FileNotFoundException (java.io.FileNotFoundException)23 ArrayList (java.util.ArrayList)23 Map (java.util.Map)21 EOFException (java.io.EOFException)20 ObjectInput (java.io.ObjectInput)18 StreamCorruptedException (java.io.StreamCorruptedException)16