001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: /*
022: * SkeletonPersistency.java
023: *
024: * Created on 7 août 2003, 22:22
025: */
026:
027: package net.charabia.jsmoothgen.skeleton;
028:
029: import java.io.*;
030:
031: import java.beans.XMLEncoder;
032: import java.beans.XMLDecoder;
033:
034: import javax.xml.transform.stream.StreamResult;
035: import javax.xml.transform.stream.StreamSource;
036:
037: import com.wutka.jox.*;
038:
039: public class SkeletonPersistency {
040: public static SkeletonBean load(File fin) throws IOException {
041: FileInputStream fis = new FileInputStream(fin);
042: try {
043: XMLDecoder dec = new XMLDecoder(fis);
044: dec.setOwner(SkeletonPersistency.class);
045: SkeletonBean obj = (SkeletonBean) dec.readObject();
046: fis.close();
047: return obj;
048: } catch (Exception exc) {
049: throw new IOException(exc.toString());
050: }
051: }
052:
053: public static SkeletonBean loadWithJox(File fin) throws IOException {
054: Object bean = null;
055: try {
056: //FileInputStream istream = new FileInputStream(fin);
057: // KBMLDeserializer bxi = new KBMLDeserializer(istream);
058: // bean = bxi.readBean();
059: //bxi.close();
060:
061: FileReader fr = new FileReader(fin);
062: JOXBeanReader jbr = new JOXBeanReader(fr);
063: bean = jbr.readObject(SkeletonBean.class);
064: jbr.close();
065: fr.close();
066:
067: } catch (Exception e) {
068: e.printStackTrace();
069: }
070: return (SkeletonBean) bean;
071: }
072:
073: public static void save(File fout, SkeletonBean obj)
074: throws IOException {
075: FileOutputStream fos = new FileOutputStream(fout);
076: try {
077: XMLEncoder enc = new XMLEncoder(fos);
078: enc.writeObject(obj);
079: enc.close();
080: } catch (Exception ex) {
081: throw new IOException(ex.toString());
082: } finally {
083: fos.close();
084: }
085: }
086:
087: public static void saveWithJox(File fout, SkeletonBean obj)
088: throws IOException {
089: try {
090: FileWriter fw = new FileWriter(fout);
091: JOXBeanWriter jbw = new JOXBeanWriter(fw);
092: jbw.writeObject("jsmoothskeleton", obj);
093: jbw.close();
094: fw.close();
095: } catch (Exception e) {
096: e.printStackTrace();
097: }
098:
099: }
100:
101: }
|