List of usage examples for java.beans XMLDecoder close
public void close()
From source file:Main.java
public static void main(String[] argv) throws Exception { XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("Bean.xml"))); Bean bean = (Bean) decoder.readObject(); decoder.close(); System.out.println("ID = " + bean.getId()); }/* www. ja v a 2s . c o m*/
From source file:Main.java
public static void main(String[] argv) throws Exception { XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("infilename.xml"))); MyClass o = (MyClass) decoder.readObject(); decoder.close(); int prop = o.getProp(); // 1 int[] props = o.getProps(); // [1, 2, 3] }
From source file:psidev.psi.mi.filemakers.xmlFlattener.XmlFlattenerGui.java
public static void main(String[] args) { /*/* w ww.j ava 2 s. com*/ * Load look'n feel */ try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e2) { log.warn("Cannot use System Look and Feel."); } XmlFlattenerGui f = new XmlFlattenerGui(); Options options = new Options(); Option option = new Option("mapping", true, "Mapping file"); option.setRequired(false); options.addOption(option); option = new Option("xmlDocument", true, "XML document to parse"); option.setRequired(false); options.addOption(option); option = new Option("schema", true, "Xsd schema, for instance data/MIF25.xsd"); option.setRequired(false); options.addOption(option); option = new Option("o", true, "output tab delimited file"); option.setRequired(false); options.addOption(option); option = new Option("validate", false, "validate the XML document (required to retrieved XML ids, e.g. with PSI-MI XML 1.0)"); option.setRequired(false); options.addOption(option); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { // parse the command line arguments cmd = parser.parse(options, args, true); } catch (ParseException exp) { displayUsage(options); System.exit(1); } String mappingFileName = ""; String schema = null; String xmlDocument = null; mappingFileName = cmd.getOptionValue("mapping"); xmlDocument = cmd.getOptionValue("xmlDocument"); schema = cmd.getOptionValue("schema"); if (false == "".equals(mappingFileName)) { try { FileInputStream fin = new FileInputStream(mappingFileName); // Create XML encoder. XMLDecoder xdec = new XMLDecoder(fin); /* get mapping */ TreeMapping treeMapping = (TreeMapping) xdec.readObject(); /* tree */ if (xmlDocument != null) { xmlDocument = xmlDocument.replaceAll("'", ""); treeMapping.setDocumentURL(xmlDocument); log.info("xmlDocument: " + xmlDocument); } if (schema != null) { treeMapping.setSchemaURL(schema.replaceAll("'", "")); } if (cmd.hasOption("validate")) { log.info("XML document will be validated"); ((XsdTreeStructImpl) f.treePanel.xsdTree).setValidateDocument(true); } ((XsdTreeStructImpl) f.treePanel.xsdTree).loadMapping(treeMapping); if (log.isErrorEnabled()) { log.error("Xml Parsing messages:"); for (String error : ((XsdTreeStructImpl) f.treePanel.xsdTree).xmlErrorHandler.getErrors()) { log.error(error); } } ((XsdTreeStructImpl) f.treePanel.xsdTree).loadMapping(treeMapping); f.treePanel.updatePreview(); f.treePanel.setTreeSelectionListener(); f.treePanel.setCellRenderer(); f.treePanel.xsdTree.check(); f.treePanel.reload(); xdec.close(); fin.close(); } catch (Exception e) { } } }
From source file:Main.java
public static Object deserializeObject(File file) { Object data = null;//from ww w.ja va 2 s . c o m try { FileInputStream os = new FileInputStream(file); XMLDecoder decoder = new XMLDecoder(os); data = decoder.readObject(); decoder.close(); } catch (FileNotFoundException f) { data = null; f.printStackTrace(); } return data; }
From source file:Main.java
public static Object Read(String filename) throws FileNotFoundException { XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(filename))); Object obj = decoder.readObject(); decoder.close(); return obj;/*from ww w .ja va 2 s . c o m*/ }
From source file:Main.java
public static Object read(String filename) throws Exception { XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream(filename))); Object o = decoder.readObject(); decoder.close(); return o;/* w w w . j a v a 2s .c o m*/ }
From source file:Main.java
public static Object objectXmlDecoder(String objSource) { Object obj = null;// w w w. ja v a2 s. co m try { File fin = new File(objSource); if (fin.exists()) { FileInputStream fis = new FileInputStream(fin); XMLDecoder decoder = new XMLDecoder(fis); obj = decoder.readObject(); fis.close(); decoder.close(); } } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } catch (Exception e1) { e1.printStackTrace(); } return obj; }
From source file:Main.java
/** * Deserializes an object into from xml file * // w w w .ja v a 2s.c om * @param fileName path to ffile */ public static Object decodeFromFile(String fileName) throws FileNotFoundException, IOException { Object object = null; XMLDecoder decoder = new XMLDecoder(new FileInputStream(fileName)); try { object = decoder.readObject(); } finally { decoder.close(); } return object; }
From source file:Main.java
public static Object handleXml(InputStream in) { XMLDecoder d = new XMLDecoder(in); try {/*from w w w . j a va2s . c om*/ Object result = d.readObject(); //Deserialization happen here return result; } finally { d.close(); } }
From source file:Main.java
public static Object deserialize(InputStream in1) { XMLDecoder d = null; try {// w w w . ja v a2s. c om d = new XMLDecoder(in1, null, null); return d.readObject(); } finally { if (null != d) { d.close(); } } }