List of usage examples for java.beans XMLDecoder readObject
public Object readObject()
From source file:com.snp.site.init.SystemInit.java
/** * XML?? ?//from ww w. ja v a2s .c om * */ static public LanmuConfig getLanmuObjectFromXml(String xmlObjectString) throws Exception { try { XMLDecoder xmlDecoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(xmlObjectString))); LanmuConfig lanmuObject = (LanmuConfig) xmlDecoder.readObject(); xmlDecoder.close(); if (lanmuObject == null) throw new Exception(); return lanmuObject; } catch (Exception e) { throw e; } }
From source file:com.snp.site.init.SystemInit.java
/** demo? ??????? */ static public DataBaseConfig getObjectDemo(String xmlObjectString) throws FileNotFoundException, IOException { // ??// w w w .j a v a 2 s .c o m // 1.? XMLDecoder xmlDecoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(xmlObjectString))); DataBaseConfig objectDemo = (DataBaseConfig) xmlDecoder.readObject(); xmlDecoder.close(); /* * 2.???,????????? * ?DEMO??XML??DEMO?? */ return objectDemo; }
From source file:com.swingtech.commons.util.ClassUtil.java
public static Object getObjectFromXML(final InputStream inStream) { final XMLDecoder d = new XMLDecoder(new BufferedInputStream(inStream)); final Object result = d.readObject(); d.close();/*from w w w .jav a2 s. c o m*/ return result; }
From source file:com.snp.site.init.SystemInit.java
public static void initUrlmap() { XMLDecoder xmlDecoder; try {/*ww w . jav a 2 s . c o m*/ xmlDecoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(getUrlmapConfigpath()))); UrlConfig urlconfig = (UrlConfig) xmlDecoder.readObject(); urlmap = urlconfig.getUrlmap(); } catch (Exception e) { log.debug("email urlmap config file doest not exit!"); } }
From source file:gov.llnl.lc.smt.command.config.SmtConfig.java
public static Map<String, String> readConfigFile(String fileName) throws FileNotFoundException { // return null if can't be read, for any reason logger.info("Reading config from: " + fileName); Map<String, String> config = null; if (fileName != null) { // Create input stream. FileInputStream fis;/*from w w w . j ava 2 s . c o m*/ try { fis = new FileInputStream(fileName); // Create XML decoder. XMLDecoder xdec = new XMLDecoder(fis); // Read object. config = (HashMap<String, String>) xdec.readObject(); // override this config file, with the actual filename (may already be correct) config.put(SmtProperty.SMT_READ_CONFIG.getName(), fileName); } catch (FileNotFoundException e) { logger.severe("Unable to read config from: " + fileName); throw (e); } } return config; }
From source file:org.dawnsci.common.richbeans.beans.BeanUI.java
/** * Bean from string using standard java serialization, useful for tables of beans with serialized strings. Used * externally to the GDA./*from w ww. jav a 2 s . co m*/ * * @param xml * @return the bean */ public static Object getBean(final String xml, final ClassLoader loader) throws Exception { final ClassLoader original = Thread.currentThread().getContextClassLoader(); final ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8")); try { Thread.currentThread().setContextClassLoader(loader); XMLDecoder d = new XMLDecoder(new BufferedInputStream(stream)); final Object bean = d.readObject(); d.close(); return bean; } finally { Thread.currentThread().setContextClassLoader(original); stream.close(); } }
From source file:com.jk.util.JKObjectUtil.java
/** * To object./*from w ww.j a va 2 s . 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
private static void checkForPreviousCounters() { ListIterator<String> it = c_outDirs.listIterator(); while (it.hasNext()) { try {/* w w w . java 2 s. c o 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.scantegrity.scanner.Scanner.java
/** * Get and set up the configuration file data. * /*from w w w.j av a 2 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:de.willuhn.jameica.hbci.io.csv.ProfileUtil.java
/** * Laedt die vorhandenen Profile fuer das Format. * @param format das Format./*from w w w . j av a 2s. co m*/ * @return die Liste der Profile. */ public static List<Profile> read(Format format) { List<Profile> result = new ArrayList<Profile>(); if (format == null) { Logger.warn("no format given"); Application.getMessagingFactory().sendMessage( new StatusBarMessage(i18n.tr("Kein Format ausgewhlt"), StatusBarMessage.TYPE_ERROR)); return result; } final Profile dp = format.getDefaultProfile(); result.add(dp); // System-Profil wird immer vorn einsortiert // 1. Mal schauen, ob wir gespeicherte Profil fuer das Format haben File dir = new File(Application.getPluginLoader().getPlugin(HBCI.class).getResources().getWorkPath(), "csv"); if (!dir.exists()) return result; File file = new File(dir, format.getClass().getName() + ".xml"); if (!file.exists() || !file.canRead()) return result; Logger.info("reading csv profile " + file); XMLDecoder decoder = null; try { decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(file))); decoder.setExceptionListener(new ExceptionListener() { public void exceptionThrown(Exception e) { throw new RuntimeException(e); } }); // Es ist tatsaechlich so, dass "readObject()" nicht etwa NULL liefert, wenn keine Objekte mehr in der // Datei sind sondern eine ArrayIndexOutOfBoundsException wirft. try { for (int i = 0; i < 1000; ++i) { Profile p = (Profile) decoder.readObject(); // Migration aus der Zeit vor dem Support mulitpler Profile: // Da konnte der User nur das eine existierende Profil aendern, es wurde automatisch gespeichert // Das hatte gar keinen Namen. Falls also ein Profil ohne Name existiert (inzwischen koennen keine // mehr ohne Name gespeichert werden), dann ist es das vom User geaenderte Profil. Das machen wir // automatisch zum ersten User-spezifischen Profil if (StringUtils.trimToNull(p.getName()) == null) { p.setName(dp.getName() + " 2"); p.setSystem(false); } result.add(p); } } catch (ArrayIndexOutOfBoundsException e) { // EOF } Logger.info("read " + (result.size() - 1) + " profiles from " + file); Collections.sort(result); // Der User hat beim letzten Mal eventuell nicht alle Spalten zugeordnet. // Die wuerden jetzt hier in dem Objekt fehlen. Daher nehmen wir // noch die Spalten aus dem Default-Profil und haengen die fehlenden noch an. } catch (Exception e) { Logger.error("unable to read profile " + file, e); Application.getMessagingFactory().sendMessage(new StatusBarMessage( i18n.tr("Laden der Profile fehlgeschlagen: {0}", e.getMessage()), StatusBarMessage.TYPE_ERROR)); } finally { if (decoder != null) { try { decoder.close(); } catch (Exception e) { /* useless */} } } return result; }