Example usage for java.beans XMLDecoder readObject

List of usage examples for java.beans XMLDecoder readObject

Introduction

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

Prototype

public Object readObject() 

Source Link

Document

Reads the next object from the underlying input stream.

Usage

From source file:psidev.psi.mi.filemakers.xmlMaker.structure.FlatFileContainer.java

public void load(XMLDecoder ois) {
    flatFiles = (ArrayList<FlatFile>) ois.readObject();
}

From source file:lu.lippmann.cdb.graph.GraphUtil.java

/**
 * /* w ww . j a  v  a 2 s  .co  m*/
 * @param xmlString
 * @return
 */
public static Layout<CNode, CEdge> getLayoutFromXML(final String xmlString) {
    final GraphWithOperations graph = new GraphWithOperations();
    final XMLDecoder in = new XMLDecoder(new BufferedInputStream(new StringInputStream(xmlString)));
    final GraphTO gto = (GraphTO) in.readObject();
    applyOperationsToGraph(graph, new ArrayList<GraphOperation>(gto.getOperations()));
    graph.setUntitledEdgeCount(gto.getUntitledEdgeCount());
    graph.setUntitledVertexCount(gto.getUntitledVertexCount());
    graph.setVariables(gto.getVariables());
    return getLayoutFromGraphWithOperations(graph);
}

From source file:PersistentFrameTest.java

 public void load()
{
   // show file chooser dialog
   int r = chooser.showOpenDialog(null);

   // if file selected, open
   if(r == JFileChooser.APPROVE_OPTION)
   {//from  w  w  w .ja va 2 s . c  o m
      try
      {
         File file = chooser.getSelectedFile();
         XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
         decoder.readObject(); 
         decoder.close();
      }
      catch (IOException e)
      {
         JOptionPane.showMessageDialog(null, e);
      }
   }
}

From source file:org.jumpmind.vaadin.ui.sqlexplorer.DefaultSettingsProvider.java

public Settings load() {
    synchronized (getClass()) {
        File file = getSettingsFile();
        if (file.exists() && file.length() > 0) {
            FileInputStream is = null;
            try {
                is = new FileInputStream(file);
                XMLDecoder decoder = new XMLDecoder(is);
                Settings settings = (Settings) decoder.readObject();
                decoder.close();//w w  w .j  a  v  a2 s  . c om
                return settings;
            } catch (Exception ex) {
                log.error("Failed to load settings", ex);
                FileUtils.deleteQuietly(file);
            } finally {
                IOUtils.closeQuietly(is);
            }
        }
        return new Settings();
    }
}

From source file:org.geomajas.plugin.deskmanager.domain.types.XmlSerialisationType.java

private Object fromXmlString(String xmlString) {
    if (xmlString == null) {
        return null;
    }//  w  w w  .  j  a  v a  2  s  . co  m
    try {
        ByteArrayInputStream is = new ByteArrayInputStream(xmlString.getBytes(ENCODING));
        XMLDecoder decoder = new XMLDecoder(is);
        return decoder.readObject();
    } catch (UnsupportedEncodingException e) {
        LOG.warn(e.getLocalizedMessage());
        IllegalArgumentException ex = new IllegalArgumentException("cannot disassemble the object");
        ex.setStackTrace(e.getStackTrace());
        throw ex;
    }
}

From source file:net.commerce.zocalo.experiment.config.SessionConfigurationTest.java

private Object readObjFromBytes(byte[] bytes) {
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    XMLDecoder dec = new XMLDecoder(bais);
    return dec.readObject();
}

From source file:org.sakaiproject.tool.gradebook.GradebookArchive.java

/**
 * Read a gradebook archive from an xml input stream.
 *
 * @param xml The input stream containing the serialized gradebook archive
 * @return A gradebook archive object modeling the data in the xml stream
 *//*from  w w  w  .  j  a  v  a2 s.  c om*/
public void readArchive(String xml) {
    ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes());
    XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(in));
    GradebookArchive archive = (GradebookArchive) decoder.readObject();
    decoder.close();
    this.gradebook = archive.getGradebook();
    this.courseGrade = archive.getCourseGrade();
    this.assignments = archive.getAssignments();
}

From source file:edu.wisc.my.stats.dao.xml.XmlQueryInformationDao.java

/**
 * @return Reads the Set of QueryInformation from the specified XML file and returns it.
 *//*from w  w  w.j a v  a2s.  c o  m*/
@SuppressWarnings("unchecked")
protected Set<QueryInformation> readQueryInformationSet() {
    final FileInputStream fis;
    try {
        fis = new FileInputStream(this.storeFile);
    } catch (FileNotFoundException fnfe) {
        final String errorMessage = "The specified storeFile='" + this.storeFile + "' could not be found.";
        this.logger.error(errorMessage, fnfe);
        throw new IllegalArgumentException(errorMessage, fnfe);
    }

    final BufferedInputStream bis = new BufferedInputStream(fis);
    final XMLDecoder xmlDecoder = new XMLDecoder(bis);
    try {
        return (Set<QueryInformation>) xmlDecoder.readObject();
    } finally {
        xmlDecoder.close();
    }
}

From source file:edu.wisc.my.portlets.bookmarks.dao.file.FileSystemBookmarkStore.java

/**
 * @see edu.wisc.my.portlets.bookmarks.dao.BookmarkStore#getBookmarkSet(java.lang.String, java.lang.String)
 *//*  w  w  w.  j  a  va 2 s  .  c  o  m*/
public BookmarkSet getBookmarkSet(String owner, String name) {
    final File storeFile = this.getStoreFile(owner, name);

    //Ok if the file doesn't exist, the user hasn't stored one yet.
    if (!storeFile.exists()) {
        return null;
    }

    try {
        final FileInputStream fis = new FileInputStream(storeFile);
        final BufferedInputStream bis = new BufferedInputStream(fis);
        final XMLDecoder d = new XMLDecoder(bis);

        try {
            final BookmarkSet bs = (BookmarkSet) d.readObject();
            return bs;
        } finally {
            d.close();
        }
    } catch (FileNotFoundException fnfe) {
        final String errorMsg = "Error reading BookmarkSet for owner='" + owner + "', name='" + name
                + "' from file='" + storeFile + "'";
        logger.error(errorMsg, fnfe);
        throw new DataAccessResourceFailureException(errorMsg);
    }
}

From source file:org.cesecore.util.HashMapTest.java

@SuppressWarnings("rawtypes")
@Test/*from   www .  j  a v  a 2  s .  c  o m*/
public void testHashMapNormal() throws Exception {
    HashMap<String, Comparable> a = new HashMap<String, Comparable>();
    a.put("foo0", Boolean.FALSE);
    a.put("foo1", "fooString");
    a.put("foo2", Integer.valueOf(2));
    a.put("foo3", Boolean.TRUE);

    // Write to XML
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLEncoder encoder = new XMLEncoder(baos);
    encoder.writeObject(a);
    encoder.close();
    String data = baos.toString("UTF8");
    //log.error(data);

    XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data.getBytes("UTF8")));
    HashMap<?, ?> b = (HashMap<?, ?>) decoder.readObject();
    decoder.close();
    assertEquals(((Boolean) b.get("foo0")).booleanValue(), false);
    assertEquals(((Boolean) b.get("foo3")).booleanValue(), true);
    assertEquals(((String) b.get("foo1")), "fooString");
    assertEquals(((Integer) b.get("foo2")).intValue(), 2);

}