Example usage for java.beans XMLDecoder XMLDecoder

List of usage examples for java.beans XMLDecoder XMLDecoder

Introduction

In this page you can find the example usage for java.beans XMLDecoder XMLDecoder.

Prototype

public XMLDecoder(InputStream in, Object owner, ExceptionListener exceptionListener) 

Source Link

Document

Creates a new input stream for reading archives created by the XMLEncoder class.

Usage

From source file:Main.java

public static Object deserialize(InputStream in1) {
    XMLDecoder d = null;// w  w w .j a v a 2s. c o m
    try {
        d = new XMLDecoder(in1, null, null);
        return d.readObject();
    } finally {
        if (null != d) {
            d.close();
        }
    }
}

From source file:org.ejbca.ui.web.admin.certprof.CertProfilesBean.java

private XMLDecoder getXMLDecoder(ByteArrayInputStream is) {
    // Without the exception listener, when a faulty xml file is read, the XMLDecoder catches the exception,
    // writes an error message to stderr and continues reading. Ejbca wouldn't notice that the profile created 
    // based on this XML file is faulty until it is used.
    ExceptionListener elistener = new ExceptionListener() {
        @Override//from   w  w w.  j  a  va2 s . c om
        public void exceptionThrown(Exception e) {
            // This probably means that an extra byte is found or something. The certprofile that raises this exception 
            // does not seem to be faulty at all as far as I can test.
            if (StringUtils.equals("org.apache.xerces.impl.io.MalformedByteSequenceException",
                    e.getClass().getName())) {
                log.error("org.apache.xerces.impl.io.MalformedByteSequenceException: " + e.getMessage());
                log.error("Continuing ...");
            } else {
                log.error(e.getClass().getName() + ": " + e.getMessage());
                throw new IllegalArgumentException(e);
            }
        }
    };
    return new XMLDecoder(is, null, elistener);
}

From source file:org.ejbca.ui.web.admin.rainterface.RAInterfaceBean.java

private XMLDecoder getXMLDecoder(ByteArrayInputStream is) {
    // Without the exception listener, when a faulty xml file is read, the XMLDecoder catches the exception,
    // writes an error message to stderr and continues reading. Ejbca wouldn't notice that the profile created 
    // based on this XML file is faulty until it is used.
    ExceptionListener elistener = new ExceptionListener() {
        @Override/*  w w w . j  av a 2s . c  o m*/
        public void exceptionThrown(Exception e) {
            // This probably means that an extra byte is found or something. The certprofile that raises this exception 
            // does not seem to be faulty at all as far as I can test.
            if (StringUtils.equals("org.apache.xerces.impl.io.MalformedByteSequenceException",
                    e.getClass().getName())) {
                log.error("org.apache.xerces.impl.io.MalformedByteSequenceException: " + e.getMessage());
                log.error("Continuing ...");
            } else {
                log.error(e.getClass().getName() + ": " + e.getMessage());
                throw new IllegalArgumentException(e);
            }
        }
    };

    return new XMLDecoder(is, null, elistener);
}