Search in sources :

Example 1 with StreamCorruptedException

use of java.io.StreamCorruptedException in project midpoint by Evolveum.

the class PropertySimpleValueFilterType method copyOf.

/**
     * Creates and returns a deep copy of a given {@code Serializable}.
     * 
     * @param serializable
     *     The instance to copy or {@code null}.
     * @return
     *     A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
     */
private static Serializable copyOf(final Serializable serializable) {
    // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
    if (serializable != null) {
        try {
            final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
            out.writeObject(serializable);
            out.close();
            final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
            final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
            final Serializable copy = ((Serializable) in.readObject());
            in.close();
            return copy;
        } catch (SecurityException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (ClassNotFoundException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (InvalidClassException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (NotSerializableException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (StreamCorruptedException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (OptionalDataException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (IOException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with StreamCorruptedException

use of java.io.StreamCorruptedException in project midpoint by Evolveum.

the class SearchFilterType method copyOf.

/**
     * Creates and returns a deep copy of a given {@code Serializable}.
     * 
     * @param serializable
     *     The instance to copy or {@code null}.
     * @return
     *     A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
     */
private static Serializable copyOf(final Serializable serializable) {
    // CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
    if (serializable != null) {
        try {
            final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
            final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
            out.writeObject(serializable);
            out.close();
            final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
            final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
            final Serializable copy = ((Serializable) in.readObject());
            in.close();
            return copy;
        } catch (SecurityException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (ClassNotFoundException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (InvalidClassException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (NotSerializableException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (StreamCorruptedException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (OptionalDataException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        } catch (IOException e) {
            throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
        }
    }
    return null;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with StreamCorruptedException

use of java.io.StreamCorruptedException in project jdk8u_jdk by JetBrains.

the class Test4067824 method main.

public static void main(String[] args) throws Exception {
    ClassLoader cl = Test4067824.class.getClassLoader();
    try {
        Beans.instantiate(cl, "Test4067824");
    } catch (ClassNotFoundException exception) {
        // This is expected.  Make sure there is the right detail message:
        if (exception.toString().indexOf("IllegalAccessException") < 0)
            throw new Error("unexpected exception", exception);
    }
    FileOutputStream fout = new FileOutputStream("foo.ser");
    fout.write(new byte[] { 1, 2, 3, 4, 5 });
    fout.close();
    try {
        // trying to instantiate corrupt foo.ser
        Beans.instantiate(cl, "foo");
        throw new Error("Instantiated corrupt .ser file OK!!??");
    } catch (ClassNotFoundException exception) {
    // expected exception
    } catch (StreamCorruptedException exception) {
    // expected exception
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) StreamCorruptedException(java.io.StreamCorruptedException)

Example 4 with StreamCorruptedException

use of java.io.StreamCorruptedException 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 5 with StreamCorruptedException

use of java.io.StreamCorruptedException 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)

Aggregations

StreamCorruptedException (java.io.StreamCorruptedException)51 IOException (java.io.IOException)33 ObjectInputStream (java.io.ObjectInputStream)28 ByteArrayInputStream (java.io.ByteArrayInputStream)20 OptionalDataException (java.io.OptionalDataException)11 File (java.io.File)8 FileInputStream (java.io.FileInputStream)7 FileNotFoundException (java.io.FileNotFoundException)7 InvalidClassException (java.io.InvalidClassException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ObjectOutputStream (java.io.ObjectOutputStream)6 EOFException (java.io.EOFException)4 NotSerializableException (java.io.NotSerializableException)4 Serializable (java.io.Serializable)4 SSLException (javax.net.ssl.SSLException)4 FileOutputStream (java.io.FileOutputStream)3 SocketTimeoutException (java.net.SocketTimeoutException)3 InvalidParameterException (java.security.InvalidParameterException)3 Blob (java.sql.Blob)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3