⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlfileio.java

📁 一款即时通讯软件
💻 JAVA
字号:
/*
 *   License
 *
 * The contents of this file are subject to the Jabber Open Source License
 * Version 1.0 (the "License").  You may not copy or use this file, in either
 * source code or executable form, except in compliance with the License.  You
 * may obtain a copy of the License at http://www.jabber.com/license/ or at
 * http://www.opensource.org/.  
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 *   Copyrights
 *
 * Portions created by or assigned to Jabber.com, Inc. are 
 * Copyright (c) 2000 Jabber.com, Inc.  All Rights Reserved.  Contact
 * information for Jabber.com, Inc. is available at http://www.jabber.com/.
 *
 * Portions Copyright (c) 1999-2000 David Waite 
 *
 *   Acknowledgements
 * 
 * Special thanks to the Jabber Open Source Contributors for their
 * suggestions and support of Jabber.
 * 
 *   Changes
 *
 * dwaite - 20001006
 * Merged all ProtocolHandler code in from sax, as this code will most 
 * probably never be swapped out (a DOM-based implementation would warrant 
 * a substantially different base)
 * @author  David Waite <a href="mailto:dwaite@jabber.com">
 *                      <i>&lt;dwaite@jabber.com&gt;</i></a>
 * @author  $Author: chris $
 * @version $Revision: 1.1 $
 *
 * j.komzak
 * Changed to work with files.
 */

package edu.ou.kmi.buddyspace.xml;

/*
 * XMLFileIO.java
 *
 * Project: BuddySpace
 * (C) Copyright Knowledge Media Institute 2002
 *
 *
 * Created on 28 August 2002, 10:50
 */

import java.io.*;
import org.jabber.jabberbeans.*;

/**
 * <code>XMLFileIO</code> provides XML storing/reading in/from files.
 * It relies on <code>FileHandler</code>.
 *
 * @author  Jiri Komzak, Knowledge Media Institute, Open University, United Kingdom
 */
public class XMLFileIO implements XMLFileDocInterface {
    
    private XMLData xmlData = null;
    //private XMLData map = null;
    
    /** Read file and returns XML contains */
    public XMLData readFile(String filename) throws IOException {
        FileInputStream input;
        File file;
        try {
            file = new File(filename);
            input = new FileInputStream(file);
        } catch (NullPointerException e) {
            throw new IOException("Cannot open input file");
        } catch (FileNotFoundException e) {
            throw new IOException("Cannot open input file");
        }
        
        FileHandler handler = new FileHandler();
        handler.setListener(this);
        handler.setInputStream(input);
        handler.run();
        
        try {
            input.close();
        } catch (IOException e) {
            throw new IOException("Cannot close input file");
        }
        
        return xmlData;
    }
    
    /** Saves XML data into given file */
    public static void saveTag(XMLData tag, String filename) throws IOException {
        FileWriter output;
        File file;
        try {
            file = new File(filename);
            output = new FileWriter(file);
        } catch (IOException e) {
            throw new IOException("Cannot open output file");
        }
        
        StringBuffer str = new StringBuffer();
        tag.appendItem(str);
        
        try {
            output.write(str.toString());
            output.close();
        } catch (IOException e) {
            throw new IOException("Cannot write or close output file");
        }
    }
    
    /** Called from handler - sets received data */
    public void received(XMLData xmlData) {
        this.xmlData = xmlData;
    }
    
    /** Called from handler - empty implementation */
    public void unexpectedThreadDeath(Exception e) {
    }
    
    /*protected void testReadFile() {
        String filename = "J:/test.ygf";
        //String filename = "J:/test_out.ygf";
        map = readFile(filename);
    }
    
    protected void testSaveTag() {
        String filename = "J:/test_out.ygf";
        saveTag(map, filename);
    }
    
    public static void main(String args[]) {
        XMLFileIO io = new XMLFileIO();
        io.testReadFile();
        io.testSaveTag();
    }*/
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -