List of usage examples for java.beans XMLEncoder close
public void close()
From source file:MainClass.java
public static void main(String args[]) { JFrame x = new JFrame("Look at me"); x.setSize(200, 300);/*from www. j a v a 2 s . c om*/ x.setVisible(true); x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FileOutputStream f; try { f = new FileOutputStream("Test.xml"); XMLEncoder e = new XMLEncoder(new BufferedOutputStream(f)); e.writeObject(x); e.close(); } catch (Exception e) { } }
From source file:Main.java
public static void main(String[] argv) throws Exception { MyClass o = new MyClass(); o.setProp(1);/*w w w . j ava2 s. c o m*/ o.setProps(new int[] { 1, 2, 3 }); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("outfilename.xml"))); encoder.writeObject(o); encoder.close(); }
From source file:MyBean.java
public static void main(String args[]) throws IOException { // Create/* w w w. j av a2 s .co m*/ MyBean saveme = new MyBean(); saveme.setNames(new String[] { "one", "two", "three" }); saveme.setPoint(new Point(15, 27)); saveme.setLength(6); // Save XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("saveme.xml"))); encoder.writeObject(saveme); encoder.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Item bean = new Item(); bean.setId(new Long(1)); bean.setItemName("a"); bean.setItemColour("Red"); bean.setItemQuantities(new Integer(100)); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Bean.xml"))); encoder.writeObject(bean);/* w w w . jav a 2s .c om*/ encoder.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MyClass o = new MyClass(); o.setProp(1);/*from ww w .j a va 2 s . c o m*/ o.setProps(new int[] { 1, 2, 3 }); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("outfilename.xml"))); encoder.writeObject(o); encoder.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { BeanInfo bi = Introspector.getBeanInfo(BeanToXmlTransient.class); PropertyDescriptor[] pds = bi.getPropertyDescriptors(); for (int i = 0; i < pds.length; i++) { PropertyDescriptor propertyDescriptor = pds[i]; if (propertyDescriptor.getName().equals("itemQuantities")) { propertyDescriptor.setValue("transient", Boolean.TRUE); }/*ww w.j av a2s . co m*/ } BeanToXmlTransient bean = new BeanToXmlTransient(); bean.setId(new Long(1)); bean.setItemName("Item"); bean.setItemColour("Red"); bean.setItemQuantities(new Integer(100)); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("BeanTransient.xml"))); encoder.writeObject(bean); encoder.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { MyClass o = new MyClass(123); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("outfilename.xml"))); String[] propertyNames = new String[] { "prop" }; encoder.setPersistenceDelegate(MyClass.class, new DefaultPersistenceDelegate(propertyNames)); encoder.writeObject(o);// w w w . j a v a 2s.c o m encoder.close(); }
From source file:com.icesoft.applications.faces.address.XWrapperUtil.java
public static void main(String[] args) { if (log.isDebugEnabled()) { log.debug("Converting database..."); }/*from w ww.j a va 2 s . c om*/ //load the CSV file InputStream is = MatchAddressDB.class.getResourceAsStream(CSV_ADDRESS_DB); BufferedReader buff = new BufferedReader(new InputStreamReader(is)); XMLEncoder xEncode = null; XAddressDataWrapper xData; //open the XML encoder and attempt to write the xml file try { xEncode = new XMLEncoder(new BufferedOutputStream(new FileOutputStream(XML_GZ_ADDRESS_DB))); } catch (FileNotFoundException ex) { log.error("Database could not be written.", ex); } //first line char[] line = getNextLine(buff); while (line != null) { //get three strings within quotes String addressValues[] = new String[3]; int stringValueStart = 0, stringValueEnd; for (int i = 0; i < 3; i++) { //opening quote while (line[stringValueStart++] != '\"') { } stringValueEnd = stringValueStart + 1; //closing quote while (line[stringValueEnd] != '\"') { stringValueEnd++; } //value addressValues[i] = new String(line, stringValueStart, stringValueEnd - stringValueStart); stringValueStart = stringValueEnd + 1; } //assign the data to the wrapper xData = new XAddressDataWrapper(); xData.setCity(addressValues[1]); xData.setState(addressValues[2]); xData.setZip(addressValues[0]); //read the next line (entry) in the CSV file line = getNextLine(buff); } //close the XML Encoder try { xEncode.close(); } catch (NullPointerException npe) { log.error("Could not close XML Encoder.", npe); return; } if (log.isDebugEnabled()) { log.debug("Closed XML Encoder."); } }
From source file:Main.java
public static String toXml(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLEncoder e = new XMLEncoder(baos); e.writeObject(o);/*ww w. j a v a2 s .com*/ e.close(); return baos.toString(); }
From source file:Main.java
public static boolean serializeObject(File file, Object o) { if (file.exists()) { System.out.println("Warning! Object Already Exists \n Replacing File."); }// w w w . j av a 2 s.c om try { FileOutputStream os = new FileOutputStream(file); XMLEncoder encoder = new XMLEncoder(os); encoder.writeObject(o); encoder.close(); } catch (Exception f) { System.out.println("Warning! Write was Unsuccessful"); return false; } return true; }