Search in sources :

Example 41 with XMLDecoder

use of java.beans.XMLDecoder in project wcomponents by BorderTech.

the class SimplePicker method loadRecentList.

/**
 * Retrieves the list of recently selected examples from a file on the file system.
 *
 * @return the list of recently used examples.
 */
private List loadRecentList() {
    try {
        InputStream in = new BufferedInputStream(new FileInputStream(RECENT_FILE_NAME));
        XMLDecoder d = new XMLDecoder(in);
        Object result = d.readObject();
        d.close();
        return (List) result;
    } catch (FileNotFoundException ex) {
        // This is ok, it's probably the first time the picker has been used.
        return new ArrayList();
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLDecoder(java.beans.XMLDecoder) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FileInputStream(java.io.FileInputStream)

Example 42 with XMLDecoder

use of java.beans.XMLDecoder in project BiglyBT by BiglySoftware.

the class UserManagerXMLPersist method doLoad.

@Override
public void doLoad(InputStream in, Map usersMap) {
    XMLDecoder decoder = new XMLDecoder(in);
    UserManagerConfig managerConfig = (UserManagerConfig) decoder.readObject();
    for (Iterator iter = managerConfig.getUsers().iterator(); iter.hasNext(); ) {
        UserProfile user = (UserProfile) iter.next();
        usersMap.put(user.getUsername().toLowerCase(), user);
    }
    System.out.println("UserManager: registered " + usersMap.size() + " users");
    decoder.close();
}
Also used : UserProfile(com.biglybt.ui.console.UserProfile) XMLDecoder(java.beans.XMLDecoder) Iterator(java.util.Iterator) UserManagerConfig(com.biglybt.ui.console.multiuser.UserManager.UserManagerConfig)

Example 43 with XMLDecoder

use of java.beans.XMLDecoder in project epp.mpc by eclipse.

the class MarketplaceInfo method load.

/**
 * This method is only public for testing purposes. Do not override or call directly.
 *
 * @noreference This method is not intended to be referenced by clients.
 * @nooverride This method is not intended to be re-implemented or extended by clients.
 */
public MarketplaceInfo load() {
    RegistryFile registryFile = createRegistryFile();
    File loadFile = registryFile.load();
    if (loadFile != null && loadFile.canRead()) {
        synchronized (MarketplaceInfo.class) {
            try {
                final InputStream in = new BufferedInputStream(new FileInputStream(loadFile));
                try {
                    XMLDecoder decoder = new XMLDecoder(in);
                    Object object = decoder.readObject();
                    decoder.close();
                    return (MarketplaceInfo) object;
                } finally {
                    in.close();
                }
            } catch (Throwable t) {
                // ignore, fallback
                IStatus status = new Status(IStatus.WARNING, MarketplaceClientUi.BUNDLE_ID, Messages.MarketplaceInfo_LoadError, t);
                MarketplaceClientUi.getLog().log(status);
                // try to delete broken file
                loadFile.delete();
            }
        }
    }
    return null;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XMLDecoder(java.beans.XMLDecoder) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 44 with XMLDecoder

use of java.beans.XMLDecoder in project compss by bsc-wdc.

the class Serializer method deserializeXML.

/**
 * Reads a XML-serialized object from a byte array
 *
 * @param data
 *            containing the serialized object
 * @return the object read from the data
 */
private static Object deserializeXML(byte[] data) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(data);
    XMLDecoder d = null;
    try {
        d = new XMLDecoder(new BufferedInputStream(bis));
        return d.readObject();
    } finally {
        if (d != null) {
            d.close();
        }
        try {
            bis.close();
        } catch (IOException ex) {
        // ignore close exception
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) XMLDecoder(java.beans.XMLDecoder) IOException(java.io.IOException)

Example 45 with XMLDecoder

use of java.beans.XMLDecoder in project whole by wholeplatform.

the class BeansPersistenceKit method doReadModel.

protected IEntity doReadModel(IPersistenceProvider pp) throws Exception {
    // TODO cannot use getEncoding()
    XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(pp.getInputStream()) {

        @Override
        public void close() throws IOException {
        }
    }, null, new ExceptionListener() {

        public void exceptionThrown(Exception e) {
        // do nothing
        }
    }, ReflectionFactory.getPlatformClassLoader());
    IEntity model = (IEntity) decoder.readObject();
    decoder.close();
    return model;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) IEntity(org.whole.lang.model.IEntity) XMLDecoder(java.beans.XMLDecoder) ExceptionListener(java.beans.ExceptionListener) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

XMLDecoder (java.beans.XMLDecoder)54 ByteArrayInputStream (java.io.ByteArrayInputStream)28 IOException (java.io.IOException)19 BufferedInputStream (java.io.BufferedInputStream)18 XMLEncoder (java.beans.XMLEncoder)15 FileInputStream (java.io.FileInputStream)14 LinkedList (java.util.LinkedList)13 ExceptionListener (java.beans.ExceptionListener)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 File (java.io.File)8 FileOutputStream (java.io.FileOutputStream)5 InputStream (java.io.InputStream)5 AssertionFailedError (junit.framework.AssertionFailedError)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 FileNotFoundException (java.io.FileNotFoundException)4 List (java.util.List)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 BufferedOutputStream (java.io.BufferedOutputStream)3 Serializable (java.io.Serializable)2