List of usage examples for java.beans XMLDecoder close
public void close()
From source file:com.jk.util.JKObjectUtil.java
/** * To object./*from ww w . j a v a 2s . c o m*/ * * @param xml * the xml * @return the object */ public static Object toObject(final String xml) { // XStream x = createXStream(); // return x.fromXML(xml); // try { final ByteArrayInputStream out = new ByteArrayInputStream(xml.getBytes()); final XMLDecoder encoder = new XMLDecoder(out); final Object object = encoder.readObject(); // encoder.close(); return object; // } catch (Exception e) { // System.err.println("Failed to decode object : \n" + xml); // return null; // } // return null; }
From source file:org.scantegrity.scanner.Scanner.java
/** * Get and set up the configuration file data. * // w w w. j av a2 s . c o m * This file configures the election. * * @param p_configPath - The path. * @return */ private static ScannerConfig getConfiguration(String p_configPath) { ScannerConfig l_config = new ScannerConfig(); File c_loc = null; try { if (p_configPath == null) { c_loc = new FindFile(ScannerConstants.DEFAULT_CONFIG_NAME).find(); } else { c_loc = new File(p_configPath); } if (!c_loc.isFile()) { c_loc = new FindFile(ScannerConstants.DEFAULT_CONFIG_NAME).find(); System.err.println("Could not open file."); } } catch (NullPointerException e_npe) { System.err.println("Could not open file. File does not exist."); e_npe.printStackTrace(); criticalExit(5); } //TODO: make sure the file is found and is readable if (c_loc == null) { System.err.println("Critical Error: Could not open configuration " + "file. System Exiting."); criticalExit(10); } XMLDecoder e; try { e = new XMLDecoder(new BufferedInputStream(new FileInputStream(c_loc))); l_config = (ScannerConfig) e.readObject(); e.close(); } catch (Exception e_e) { System.err.println("Could not parse Configuration File!"); e_e.printStackTrace(); criticalExit(20); } return l_config; }
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.j a v a 2s . 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(); return settings; } catch (Exception ex) { log.error("Failed to load settings", ex); FileUtils.deleteQuietly(file); } finally { IOUtils.closeQuietly(is); }//from w ww .j av a 2 s. c om } return new Settings(); } }
From source file:org.scantegrity.scanner.Scanner.java
private static void checkForPreviousCounters() { ListIterator<String> it = c_outDirs.listIterator(); while (it.hasNext()) { try {//from w w w . j a v a 2s .co m String l_path = it.next() + File.separator + "count.xml"; File l_file = new File(l_path); if (l_file.exists()) { c_log.log(Level.WARNING, "count.xml exists. Updating counters."); //copy the file try { FileUtils.copyFile(l_file, new File(l_path + "_bak"), true); } catch (IOException e) { c_log.log(Level.WARNING, "Could not backup previous counter file."); } XMLDecoder l_countFile = new XMLDecoder(new BufferedInputStream(new FileInputStream(l_path))); l_countFile.readObject(); c_scanCount = (Integer) l_countFile.readObject(); l_countFile.readObject(); c_ballotCount = (Integer) l_countFile.readObject(); l_countFile.readObject(); c_errorCount = (Integer) l_countFile.readObject(); l_countFile.close(); c_log.log(Level.WARNING, "Previous counts: ScanCount=" + c_scanCount + " BallotCount=" + c_ballotCount + " ErrorCount=" + c_errorCount); } } catch (FileNotFoundException e) { c_log.log(Level.SEVERE, "Unable to open count.xml"); } } }
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 */// w w w . jav a2 s.c o m 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. */// w w w. ja v a 2 s . 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:org.cesecore.util.HashMapTest.java
@SuppressWarnings("rawtypes") @Test//from w w w. j av a2s . 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); }
From source file:org.cesecore.util.HashMapTest.java
@SuppressWarnings("rawtypes") @Test// w w w. j av a 2 s . co m public void testHashMapStrangeCharsSafe() throws Exception { HashMap<String, Comparable> h = new HashMap<String, Comparable>(); h.put("foo0", Boolean.FALSE); h.put("foo1", "\0001\0002fooString"); h.put("foo2", Integer.valueOf(2)); h.put("foo3", Boolean.TRUE); h.put("foo4", ""); HashMap<Object, Object> a = new Base64PutHashMap(); a.putAll(h); // 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); try { XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data.getBytes("UTF8"))); HashMap<?, ?> b = (HashMap<?, ?>) decoder.readObject(); decoder.close(); @SuppressWarnings("unchecked") HashMap<Object, Object> c = new Base64GetHashMap(b); assertEquals(((Boolean) c.get("foo0")).booleanValue(), false); assertEquals(((Boolean) c.get("foo3")).booleanValue(), true); assertEquals(((String) c.get("foo1")), "\0001\0002fooString"); assertEquals(((String) c.get("foo4")), ""); assertEquals(((Integer) c.get("foo2")).intValue(), 2); } catch (ClassCastException e) { assertTrue(false); } }
From source file:org.cesecore.util.HashMapTest.java
@SuppressWarnings("rawtypes") @Test//from w w w.ja v a 2 s .c o m public void testHashMapNormalCharsSafe() throws Exception { HashMap<String, Comparable> h = new HashMap<String, Comparable>(); h.put("foo0", Boolean.FALSE); h.put("foo1", "fooString"); h.put("foo2", Integer.valueOf(2)); h.put("foo3", Boolean.TRUE); h.put("foo4", ""); HashMap<Object, Object> a = new Base64PutHashMap(); a.putAll(h); // 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); try { XMLDecoder decoder = new XMLDecoder(new ByteArrayInputStream(data.getBytes("UTF8"))); HashMap<?, ?> b = (HashMap<?, ?>) decoder.readObject(); decoder.close(); @SuppressWarnings("unchecked") HashMap<Object, Object> c = new Base64GetHashMap(b); assertEquals(((Boolean) c.get("foo0")).booleanValue(), false); assertEquals(((Boolean) c.get("foo3")).booleanValue(), true); assertEquals(((String) c.get("foo4")), ""); assertEquals(((String) c.get("foo1")), "fooString"); assertEquals(((Integer) c.get("foo2")).intValue(), 2); } catch (ClassCastException e) { assertTrue(false); } }