Search in sources :

Example 6 with OptionalDataException

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

the class Calendar method readObject.

/**
     * Reconstitutes this object from a stream (i.e., deserialize it).
     */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    final ObjectInputStream input = stream;
    input.defaultReadObject();
    stamp = new int[FIELD_COUNT];
    // streamed out anymore.  We expect 'time' to be correct.
    if (serialVersionOnStream >= 2) {
        isTimeSet = true;
        if (fields == null) {
            fields = new int[FIELD_COUNT];
        }
        if (isSet == null) {
            isSet = new boolean[FIELD_COUNT];
        }
    } else if (serialVersionOnStream >= 0) {
        for (int i = 0; i < FIELD_COUNT; ++i) {
            stamp[i] = isSet[i] ? COMPUTED : UNSET;
        }
    }
    serialVersionOnStream = currentSerialVersion;
    // If there's a ZoneInfo object, use it for zone.
    ZoneInfo zi = null;
    try {
        zi = AccessController.doPrivileged(new PrivilegedExceptionAction<ZoneInfo>() {

            @Override
            public ZoneInfo run() throws Exception {
                return (ZoneInfo) input.readObject();
            }
        }, CalendarAccessControlContext.INSTANCE);
    } catch (PrivilegedActionException pae) {
        Exception e = pae.getException();
        if (!(e instanceof OptionalDataException)) {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof IOException) {
                throw (IOException) e;
            } else if (e instanceof ClassNotFoundException) {
                throw (ClassNotFoundException) e;
            }
            throw new RuntimeException(e);
        }
    }
    if (zi != null) {
        zone = zi;
    }
    // implementation as much as possible.
    if (zone instanceof SimpleTimeZone) {
        String id = zone.getID();
        TimeZone tz = TimeZone.getTimeZone(id);
        if (tz != null && tz.hasSameRules(zone) && tz.getID().equals(id)) {
            zone = tz;
        }
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) OptionalDataException(java.io.OptionalDataException) ZoneInfo(sun.util.calendar.ZoneInfo) PrivilegedActionException(java.security.PrivilegedActionException) OptionalDataException(java.io.OptionalDataException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 7 with OptionalDataException

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

the class ReflectionFactoryTest method newOptionalDataException.

/**
     * Test the constructor of OptionalDataExceptions.
     */
@Test
static void newOptionalDataException() {
    OptionalDataException ode = factory.newOptionalDataExceptionForSerialization(true);
    Assert.assertTrue(ode.eof, "eof wrong");
    ode = factory.newOptionalDataExceptionForSerialization(false);
    Assert.assertFalse(ode.eof, "eof wrong");
}
Also used : OptionalDataException(java.io.OptionalDataException) Test(org.testng.annotations.Test)

Example 8 with OptionalDataException

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

the class PropertyComplexValueFilterType 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 9 with OptionalDataException

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

the class QueryType 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)

Aggregations

OptionalDataException (java.io.OptionalDataException)9 ObjectInputStream (java.io.ObjectInputStream)8 IOException (java.io.IOException)7 StreamCorruptedException (java.io.StreamCorruptedException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InvalidClassException (java.io.InvalidClassException)4 NotSerializableException (java.io.NotSerializableException)4 ObjectOutputStream (java.io.ObjectOutputStream)4 Serializable (java.io.Serializable)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)2 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Test (org.testng.annotations.Test)1 ZoneInfo (sun.util.calendar.ZoneInfo)1