| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| examples.nntp.newsgroups |
|
|
| 1 | /* |
|
| 2 | * Copyright 2001-2005 The Apache Software Foundation |
|
| 3 | * |
|
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
| 5 | * you may not use this file except in compliance with the License. |
|
| 6 | * You may obtain a copy of the License at |
|
| 7 | * |
|
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
| 9 | * |
|
| 10 | * Unless required by applicable law or agreed to in writing, software |
|
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
| 13 | * See the License for the specific language governing permissions and |
|
| 14 | * limitations under the License. |
|
| 15 | */ |
|
| 16 | package examples.nntp; |
|
| 17 | ||
| 18 | import java.io.IOException; |
|
| 19 | import org.apache.commons.net.nntp.NNTPClient; |
|
| 20 | import org.apache.commons.net.nntp.NewsgroupInfo; |
|
| 21 | ||
| 22 | /*** |
|
| 23 | * This is a trivial example using the NNTP package to approximate the |
|
| 24 | * Unix newsgroups command. It merely connects to the specified news |
|
| 25 | * server and issues fetches the list of newsgroups stored by the server. |
|
| 26 | * On servers that store a lot of newsgroups, this command can take a very |
|
| 27 | * long time (listing upwards of 30,000 groups). |
|
| 28 | * <p> |
|
| 29 | ***/ |
|
| 30 | ||
| 31 | 0 | public final class newsgroups |
| 32 | { |
|
| 33 | ||
| 34 | public final static void main(String[] args) |
|
| 35 | { |
|
| 36 | NNTPClient client; |
|
| 37 | NewsgroupInfo[] list; |
|
| 38 | ||
| 39 | 0 | if (args.length < 1) |
| 40 | { |
|
| 41 | 0 | System.err.println("Usage: newsgroups newsserver"); |
| 42 | 0 | System.exit(1); |
| 43 | } |
|
| 44 | ||
| 45 | 0 | client = new NNTPClient(); |
| 46 | ||
| 47 | try |
|
| 48 | { |
|
| 49 | 0 | client.connect(args[0]); |
| 50 | ||
| 51 | 0 | list = client.listNewsgroups(); |
| 52 | ||
| 53 | 0 | if (list != null) |
| 54 | { |
|
| 55 | 0 | for (int i = 0; i < list.length; i++) |
| 56 | 0 | System.out.println(list[i].getNewsgroup()); |
| 57 | } |
|
| 58 | else |
|
| 59 | { |
|
| 60 | 0 | System.err.println("LIST command failed."); |
| 61 | 0 | System.err.println("Server reply: " + client.getReplyString()); |
| 62 | } |
|
| 63 | 0 | } |
| 64 | 0 | catch (IOException e) |
| 65 | { |
|
| 66 | 0 | e.printStackTrace(); |
| 67 | 0 | } |
| 68 | finally |
|
| 69 | { |
|
| 70 | 0 | try |
| 71 | { |
|
| 72 | 0 | if (client.isConnected()) |
| 73 | 0 | client.disconnect(); |
| 74 | } |
|
| 75 | 0 | catch (IOException e) |
| 76 | { |
|
| 77 | 0 | System.err.println("Error disconnecting from server."); |
| 78 | 0 | e.printStackTrace(); |
| 79 | 0 | System.exit(1); |
| 80 | 0 | } |
| 81 | 0 | } |
| 82 | ||
| 83 | 0 | } |
| 84 | ||
| 85 | } |
|
| 86 | ||
| 87 |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |