Example usage for org.apache.commons.lang SerializationException SerializationException

List of usage examples for org.apache.commons.lang SerializationException SerializationException

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationException SerializationException.

Prototype

public SerializationException(Throwable cause) 

Source Link

Document

Constructs a new SerializationException with specified nested Throwable.

Usage

From source file:brainleg.app.util.AppUtil.java

/**
 * <p>Deserializes an <code>Object</code> from the specified stream.</p>
 * <p/>// w ww  .  j a va 2 s  .co  m
 * <p>The stream will be closed once the object is written. This
 * avoids the need for a finally clause, and maybe also exception
 * handling, in the application code.</p>
 * <p/>
 * <p>The stream passed in is not buffered internally within this method.
 * This is the responsibility of your application if desired.</p>
 *
 * @param inputStream the serialized object input stream, must not be null
 * @return the deserialized object
 * @throws IllegalArgumentException if <code>inputStream</code> is <code>null</code>
 * @throws SerializationException   (runtime) if the serialization fails
 */
public static Object deserialize(InputStream inputStream) {
    if (inputStream == null) {
        throw new IllegalArgumentException("The InputStream must not be null");
    }
    ObjectInputStream in = null;
    try {
        // stream closed in the finally
        in = new ObjectInputStream(inputStream);
        return in.readObject();

    } catch (ClassNotFoundException ex) {
        throw new SerializationException(ex);
    } catch (IOException ex) {
        throw new SerializationException(ex);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            // ignore close exception
        }
    }
}

From source file:com.moisespsena.vraptor.javaobjectserialization.JavaObjectSerialization.java

@Override
public <T> JavaObjectSerializerBuilder from(final T object) {
    try {/*from ww w.  j av a  2  s.  com*/
        response.setContentType("application/x-java-serialized-object");
        return new JavaObjectSerializerBuilder(response.getOutputStream()).from(object);
    } catch (final IOException e) {
        throw new SerializationException(e);
    }
}

From source file:com.moisespsena.vraptor.javaobjectserialization.JavaObjectSerialization.java

@Override
public <T> JavaObjectSerializerBuilder from(final T object, final String alias) {
    try {//w w w  . j a v a 2 s .c  o m
        return new JavaObjectSerializerBuilder(response.getOutputStream()).from(object, alias);
    } catch (final IOException e) {
        throw new SerializationException(e);
    }
}

From source file:mitm.application.djigzo.mail.MailContainer.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }//from   w w w.j a v  a 2s .com

    mail = (Mail) in.readObject();
}

From source file:com.moisespsena.vraptor.javaobjectserialization.JavaObjectSerializerBuilder.java

@Override
public void serialize() {
    ObjectOutputStream out = null;

    try {/*from  w  w w.  j ava2 s  .  c  o  m*/
        if (outputStream instanceof ObjectOutputStream) {
            out = (ObjectOutputStream) outputStream;
        } else {
            out = new ObjectOutputStream(outputStream);
        }

        out.writeObject(source);
        out.flush();
    } catch (final IOException e) {
        throw new SerializationException(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final IOException e) {
                throw new SerializationException(e);
            }
        }
    }
}

From source file:com.osafe.util.SerializationUtils.java

/**
 * <p>Serializes an <code>Object</code> to the specified stream.</p>
 *
 * <p>The stream will be closed once the object is written.
 * This avoids the need for a finally clause, and maybe also exception
 * handling, in the application code.</p>
 *
 * <p>The stream passed in is not buffered internally within this method.
 * This is the responsibility of your application if desired.</p>
 *
 * @param obj  the object to serialize to bytes, may be null
 * @param outputStream  the stream to write to, must not be null
 * @throws IllegalArgumentException if <code>outputStream</code> is <code>null</code>
 * @throws SerializationException (runtime) if the serialization fails
 *//*from   w w  w  .  jav  a2s .  co m*/
public static void serialize(Serializable obj, OutputStream outputStream) {
    if (outputStream == null) {
        throw new IllegalArgumentException("The OutputStream must not be null");
    }
    ObjectOutputStream out = null;
    try {
        // stream closed in the finally
        out = new ObjectOutputStream(outputStream);
        out.writeObject(obj);

    } catch (IOException ex) {
        throw new SerializationException(ex);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException ex) {
            // ignore close exception
        }
    }
}

From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java

private void fromInputStream(InputStream input) throws IOException {
    DataInputStream dis = new DataInputStream(input);

    long version = dis.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }/*from   www .j a  v  a  2  s .co m*/

    algorithm = dis.readUTF();

    int saltSize = dis.readInt();

    this.salt = new byte[saltSize];

    dis.readFully(salt);

    this.iterationCount = dis.readInt();
}

From source file:mitm.application.djigzo.james.EncryptedContainer.java

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, EncryptorException {
    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }//  w w  w  .  j a va 2 s.co  m

    byte[] encrypted = new byte[in.readInt()];

    in.read(encrypted);

    value = (T) SerializationUtils.deserialize(getEncryptor().decrypt(encrypted));
}

From source file:mitm.common.security.password.PBEncryptionParameters.java

private void fromByteArray(byte[] encoded) throws IOException {
    ByteArrayInputStream bis = new ByteArrayInputStream(encoded);

    DataInputStream in = new DataInputStream(bis);

    long version = in.readLong();

    if (version != serialVersionUID) {
        throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
    }// w  w  w  .  j a v  a  2s.c  o  m

    int saltSize = in.readInt();

    this.salt = new byte[saltSize];

    in.readFully(salt);

    this.iterationCount = in.readInt();

    int encryptedSize = in.readInt();

    this.encryptedData = new byte[encryptedSize];

    in.readFully(encryptedData);
}

From source file:mitm.application.djigzo.james.Certificates.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    try {//w ww . j a  v a 2  s  . c o  m
        CertificateFactory certificateFactory = SecurityFactoryFactory.getSecurityFactory()
                .createCertificateFactory("X.509");

        certificates = new HashSet<X509Certificate>();

        long version = in.readLong();

        if (version != serialVersionUID) {
            throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version);
        }

        /*
         * Read how many certificates we have to read.
         */
        int nrOfCertificates = in.readInt();

        for (int i = 0; i < nrOfCertificates; i++) {
            int encodedSize = in.readInt();

            byte[] encoded = new byte[encodedSize];

            in.readFully(encoded);

            X509Certificate certificate = (X509Certificate) certificateFactory
                    .generateCertificate(new ByteArrayInputStream(encoded));

            certificates.add(certificate);
        }
    } catch (NoSuchProviderException e) {
        throw new NoSuchProviderRuntimeException(e);
    } catch (CertificateException e) {
        throw new IOException(e);
    } catch (SecurityFactoryFactoryException e) {
        throw new IOException(e);
    }
}