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

📄 configfactory.java

📁 一个Mp3在线搜索器
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package biz.tbuy.huliqing.jloading.downloader;import java.io.File;import javax.xml.parsers.ParserConfigurationException;import javax.xml.transform.TransformerConfigurationException;import javax.xml.transform.TransformerException;import org.w3c.dom.Document;import org.w3c.dom.Element;/** * * @author huliqing */public class ConfigFactory {            /**     * 载入已经存在的状态保存文件。     * @param configPath     * @return     * @throws java.lang.Exception     */    public static Config loadConfig(String configPath) throws Exception{        return new Config(XmlOper.getDocument(configPath), configPath);    }        public static Config loadConfig(File configFile) throws Exception{        return new Config(XmlOper.getDocument(configFile), configFile.getAbsolutePath());    }        /**     * 创建一个新的状态保存文件     * @param url     * @param savePath     * @param length     * @param threads     * @throws javax.xml.transform.TransformerConfigurationException     * @throws javax.xml.transform.TransformerException     * @throws javax.xml.parsers.ParserConfigurationException     * <pre>     * <file name="短文件名" save="保存路径" length="长度" threads="线程数">     *     <urls>     *             <url src=""/>     *     </urls>     *     <pieces>     *             <piece start="" pos="" end=""/>     *             <piece start="" pos="" end=""/>     *     </pieces>     * </file>     * </pre>     */    public static Config createConfig(String id,             String name,             String url,             String savePath,             long length,             int threads) throws             TransformerConfigurationException,             TransformerException,             ParserConfigurationException {        String configPath = savePath + "_config";   // 状态保存文件的路径        Document doc = XmlOper.newDocument();        Element file = doc.createElement("file");        file.setAttribute("id", id);        file.setAttribute("name", name);        file.setAttribute("save", savePath);        file.setAttribute("length", (String.valueOf(length)));        file.setAttribute("threads", (String.valueOf(threads)));        doc.appendChild(file);        Element us = doc.createElement("urls");        Element u = doc.createElement("url");        u.setAttribute("src", url);        us.appendChild(u);                Element pieces = doc.createElement("pieces");        file.appendChild(us);        file.appendChild(pieces);        XmlOper.saveDocument(doc, configPath);        return new Config(doc, configPath);    }}

⌨️ 快捷键说明

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