Package gnu.inet.nntp

Examples of gnu.inet.nntp.NNTPConnection


     */
    private void connect(int numberOfConnections) throws NntpNotConnectedException {
        //TODO check available connections
        if(availableConnections.size() < 1) {
            try {
                NNTPConnection con = new NNTPConnection(Application.getInstance().getProperty("nntp.hostname", "localhost"),
                        Integer.parseInt(Application.getInstance().getProperty("nntp.port", "119")));
                String username = Application.getInstance().getProperty("nntp.username");
                if(!"".equals(username)) {
                    if(con.authinfo(username, Application.getInstance().getProperty("nntp.password"))) {
                        System.out.println(new Date() + ": connected");
                        availableConnections.push(con);
                    } else {
                        System.err.println(new Date() + ": not connected. check username/password");
                        throw new NntpNotConnectedException();
                    }
                }
            } catch (NumberFormatException e) {
//                e.printStackTrace();
                throw new NntpNotConnectedException();
            } catch(UnknownHostException e) {
//                e.printStackTrace();
                throw new NntpNotConnectedException();
            } catch (IOException e) {
//                e.printStackTrace();
                throw new NntpNotConnectedException();
            }
        }
       
        //TODO open multiple connections
        for (int i = 0; i < numberOfConnections; i++) {
            if(i >= availableConnections.size()) break;
            NNTPConnection con = availableConnections.pop();
            //TODO connect
//          con.connect();
            fireConnected();
            usedConnections.push(con);
        }
View Full Code Here


     *
     */
    public void disconnect() throws IOException {
        Iterator it = usedConnections.iterator();
        while(it.hasNext()) {
            NNTPConnection con = (NNTPConnection) it.next();
            //TODO disconnect connection
            con.quit();
            availableConnections.push(con);
        }
        fireDisconnected();
    }
View Full Code Here

        }
       
        // TODO start a thread to get list of articles
//        Thread t = new Thread() {
            // get first connection
            NNTPConnection con = usedConnections.get(0);
            Stack<Integer> articlesIds = new Stack<Integer>();
           
//            public void run() {
                try {
                    ArticleNumberIterator ait = con.listGroup(g.getName());
                    while(ait.hasNext()) {
                        Integer id = (Integer) ait.next();
                        System.out.println("Got article ID '" + id + "'");
                        //TODO check if ArticleResponse, int articleID or Article is returned
                        articlesIds.push(id);
//                        Thread.sleep(2);
                    }
                   
                    for (Integer id : articlesIds) {
//                        System.out.println("Reading article '" + id + "'");
                        ArticleResponse a = (ArticleResponse) con.article(id);
                        StringWriter sw = new StringWriter();
                        PrintWriter pw = new PrintWriter(sw);
                        BufferedReader br = new BufferedReader(new InputStreamReader(a.in));
                        String line = null;
                        while((line = br.readLine()) != null) {
View Full Code Here

TOP

Related Classes of gnu.inet.nntp.NNTPConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.