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

📄 parsework.java

📁 tRSS是MIDP的的RSS客户端。用户可以从一些新闻网站和个人数据库和feed阅读标题。
💻 JAVA
字号:
/*
 * ParseWork.java
 *
 * Created on January 14, 2006, 3:27 PM
 */

package com.dtw.midp.util;

import java.io.*;
import java.util.Vector;
import javax.microedition.io.*;
import com.dtw.midp.tRSS;
/**
 *
 * @author psaingtong
 * 
 */
public class ParseWork implements WorkerTask {
    private Parser tParser; 
    private String URL;
    private String file;
    private HttpConnection tHttpConnection;
    private InputStream tIn;
    private boolean tCancel;

    /** Creates a new instance of ParseWork */
    public ParseWork(Parser parser,String _URL,String _file) {
        tParser=parser;
        URL=_URL;
        file=_file;
        tCancel=false;
    }
    public void run() throws IOException{
        tCancel = false;
    
    // Set up the network connection.
        tHttpConnection = null;
        tIn = null;
        
        try {
            if(file.equals("file")){
                tIn=this.getClass().getResourceAsStream(URL);
                tParser.parseFile(tIn, URL);
            }else{
            tHttpConnection = (HttpConnection)Connector.open(URL);
                if (tCancel) return;
            tIn = tHttpConnection.openInputStream();
                if (tCancel) return;
            
      // Call the parser.
            tParser.parse(tIn);
            }
        }
        finally {
            if (tIn != null) tIn.close();
            if (tHttpConnection != null) tHttpConnection.close();
            tIn = null;
            tHttpConnection = null;
            tCancel = false;
            }
    }
      
  /**
   * Cancel parsing
   */

    public void cancel(){
        if (tHttpConnection == null) return;
            tCancel = true;
        if (tParser != null) tParser.cancel();
        try {
            if (tIn != null) tIn.close();
            if (tHttpConnection != null) tHttpConnection.close();
            }
        catch (IOException ioe) {}
        tIn = null;
        tHttpConnection = null;
    }
    
    
}

⌨️ 快捷键说明

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