Search in sources :

Example 41 with ObjectOutputStream

use of java.io.ObjectOutputStream in project j2objc by google.

the class OldObjectInputOutputStreamTest method setUp.

protected void setUp() throws IOException {
    sos = new Support_OutputStream(256);
    os = new ObjectOutputStream(sos);
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 42 with ObjectOutputStream

use of java.io.ObjectOutputStream in project j2objc by google.

the class OldObjectOutputStreamTest method setUp.

/**
     * Sets up the fixture, for example, open a network connection. This method
     * is called before a test is executed.
     */
protected void setUp() throws Exception {
    super.setUp();
    oos = new ObjectOutputStream(bao = new ByteArrayOutputStream());
    oos_ioe = new ObjectOutputStream(sos = new Support_OutputStream());
    sos.setThrowsException(true);
}
Also used : Support_OutputStream(tests.support.Support_OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 43 with ObjectOutputStream

use of java.io.ObjectOutputStream in project j2objc by google.

the class DecimalFormatSymbolsTest method testSerializationOfMultiCharNegativeAndPercentage.

// https://code.google.com/p/android/issues/detail?id=170718
public void testSerializationOfMultiCharNegativeAndPercentage() throws Exception {
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.forLanguageTag("ar-AR"));
    // TODO(user): Investigate.
    // assertTrue(dfs.getMinusSignString().length() > 1);
    // assertTrue(dfs.getPercentString().length() > 1);
    // Serialize...
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new ObjectOutputStream(out).writeObject(dfs);
    byte[] bytes = out.toByteArray();
    // Deserialize...
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
    DecimalFormatSymbols deserializedDfs = (DecimalFormatSymbols) in.readObject();
    assertEquals(-1, in.read());
    assertEquals(dfs.getMinusSign(), deserializedDfs.getMinusSign());
    assertEquals(dfs.getPercent(), deserializedDfs.getPercent());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 44 with ObjectOutputStream

use of java.io.ObjectOutputStream in project guice by google.

the class Asserts method reserialize.

public static <E> E reserialize(E original) throws IOException {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        new ObjectOutputStream(out).writeObject(original);
        ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
        // the reserialized type is assignable
        @SuppressWarnings("unchecked") E reserialized = (E) new ObjectInputStream(in).readObject();
        return reserialized;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 45 with ObjectOutputStream

use of java.io.ObjectOutputStream in project j2objc by google.

the class SerializationTester method serialize.

private static byte[] serialize(Object object) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new ObjectOutputStream(out).writeObject(object);
    return out.toByteArray();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

ObjectOutputStream (java.io.ObjectOutputStream)1102 ByteArrayOutputStream (java.io.ByteArrayOutputStream)760 ObjectInputStream (java.io.ObjectInputStream)428 ByteArrayInputStream (java.io.ByteArrayInputStream)375 IOException (java.io.IOException)358 FileOutputStream (java.io.FileOutputStream)161 Test (org.junit.Test)161 File (java.io.File)96 BufferedOutputStream (java.io.BufferedOutputStream)52 ObjectOutput (java.io.ObjectOutput)47 OutputStream (java.io.OutputStream)37 HashMap (java.util.HashMap)37 ArrayList (java.util.ArrayList)33 FileInputStream (java.io.FileInputStream)25 InputStream (java.io.InputStream)23 FileNotFoundException (java.io.FileNotFoundException)22 Serializable (java.io.Serializable)17 GZIPOutputStream (java.util.zip.GZIPOutputStream)16 Test (org.testng.annotations.Test)15 NotSerializableException (java.io.NotSerializableException)14