Coverage report

| %line | %branch
--- | --- | ---
examples.nntp.NNTPUtils |
0% |
0% |

1 |  |
     package examples.nntp;
2 |  |
3 |  |
     import java.io.BufferedReader;
4 |  |
     import java.io.IOException;
5 |  |
     import java.io.Reader;
6 |  |
     import java.util.StringTokenizer;
7 |  |
8 |  |
     import org.apache.commons.net.io.DotTerminatedMessageReader;
9 |  |
     import org.apache.commons.net.nntp.Article;
10 |  |
     import org.apache.commons.net.nntp.NNTPClient;
11 |  |
12 |  |
     /**
13 |  |
      *
14 |  |
      * Some convenience methods for NNTP example classes.
15 |  |
      *
16 |  |
      * @author Rory Winston <rwinston@checkfree.com>
17 |  |
      */
18 | 0 |
     public class NNTPUtils {
19 |  |
20 |  |
     	/**
21 |  |
     	 * Given an {@link NNTPClient} instance, and an integer range of messages, return
22 |  |
     	 * an array of {@link Article} instances.
23 |  |
     	 * @param client
24 |  |
     	 * @param lowArticleNumber
25 |  |
     	 * @param highArticleNumber
26 |  |
     	 * @return Article[] An array of Article
27 |  |
     	 * @throws IOException
28 |  |
     	 */
29 |  |
     	public  static Article[] getArticleInfo(NNTPClient client, int lowArticleNumber, class="keyword">int highArticleNumber)
30 |  |
     			throws IOException {
31 | 0 |
     			Reader reader = null;
32 | 0 |
     			Article[] articles = null;
33 | 0 |
     			reader =
34 |  |
     				(DotTerminatedMessageReader) client.retrieveArticleInfo(
35 |  |
     					lowArticleNumber,
36 |  |
     					highArticleNumber);
37 |  |
38 | 0 |
     			if (reader != null) {
39 | 0 |
     				String theInfo = readerToString(reader);
40 | 0 |
     				StringTokenizer st = new StringTokenizer(theInfo, "\n");
41 |  |
42 |  |
     				// Extract the article information
43 |  |
     				// Mandatory format (from NNTP RFC 2980) is :
44 |  |
     				// Subject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count
45 |  |
46 | 0 |
     				int count = st.countTokens();
47 | 0 |
     				articles = new Article[count];
48 | 0 |
     				int index = 0;
49 |  |
50 | 0 |
     				while (st.hasMoreTokens()) {
51 | 0 |
     					StringTokenizer stt = new StringTokenizer(st.nextToken(), "\t");
52 | 0 |
     					Article article = new Article();
53 | 0 |
     					article.setArticleNumber(Integer.parseInt(stt.nextToken()));
54 | 0 |
     					article.setSubject(stt.nextToken());
55 | 0 |
     					article.setFrom(stt.nextToken());
56 | 0 |
     					article.setDate(stt.nextToken());
57 | 0 |
     					article.setArticleId(stt.nextToken());
58 | 0 |
     					article.addHeaderField("References", stt.nextToken());
59 | 0 |
     					articles[index++] = article;
60 |  |
     				}
61 |  |
     			} else {
62 | 0 |
     				return null;
63 |  |
     			}
64 |  |
65 | 0 |
     			return articles;
66 |  |
     		}
67 |  |
68 |  |
69 |  |
     	/**
70 |  |
     	 * Convert a {@link Reader} instance to a String
71 |  |
     	 * @param reader The Reader instance
72 |  |
     	 * @return String
73 |  |
     	 */
74 |  |
     	public static String readerToString(Reader reader) {
75 | 0 |
     		String temp = null;
76 | 0 |
     		StringBuffer sb = null;
77 | 0 |
     		BufferedReader bufReader = new BufferedReader(reader);
78 |  |
79 | 0 |
     		sb = new StringBuffer();
80 |  |
     		try {
81 | 0 |
     			temp = bufReader.readLine();
82 | 0 |
     			while (temp != null) {
83 | 0 |
     				sb.append(temp);
84 | 0 |
     				sb.append("\n");
85 | 0 |
     				temp = bufReader.readLine();
86 |  |
     			}
87 | 0 |
     		} catch (IOException e) {
88 | 0 |
     			e.printStackTrace();
89 | 0 |
     		}
90 |  |
91 | 0 |
     		return sb.toString();
92 |  |
     	}
93 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.