1 17 package org.apache.servicemix.jbi.util; 18 19 import java.io.File ; 20 import java.io.FileReader ; 21 import java.io.FileWriter ; 22 import java.io.IOException ; 23 import java.io.Reader ; 24 import java.io.Writer ; 25 26 import com.thoughtworks.xstream.XStream; 27 import com.thoughtworks.xstream.io.xml.DomDriver; 28 29 public class XmlPersistenceSupport { 30 31 private static XStream xstream = new XStream(new DomDriver()); 32 33 public static Object read(File file) throws IOException { 34 Reader r = new FileReader (file); 35 try { 36 return xstream.fromXML(r); 37 } finally { 38 r.close(); 39 } 40 } 41 42 public static void write(File file, Object obj) throws IOException { 43 Writer w = new FileWriter (file); 44 try { 45 xstream.toXML(obj, w); 46 } finally { 47 w.close(); 48 } 49 } 50 51 } 52 | Popular Tags |