List of usage examples for org.apache.commons.net.nntp NNTPClient listNewsgroups
public NewsgroupInfo[] listNewsgroups() throws IOException
From source file:examples.nntp.newsgroups.java
public final static void main(String[] args) { NNTPClient client; NewsgroupInfo[] list;/*from ww w .j a v a 2s . co m*/ if (args.length < 1) { System.err.println("Usage: newsgroups newsserver"); System.exit(1); } client = new NNTPClient(); try { client.connect(args[0]); list = client.listNewsgroups(); if (list != null) { for (int i = 0; i < list.length; i++) System.out.println(list[i].getNewsgroup()); } else { System.err.println("LIST command failed."); System.err.println("Server reply: " + client.getReplyString()); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (client.isConnected()) client.disconnect(); } catch (IOException e) { System.err.println("Error disconnecting from server."); e.printStackTrace(); System.exit(1); } } }
From source file:me.lehrner.newsgroupsndy.presenter.tasks.UpdateGroupListAsyncTask.java
@Override protected Boolean doInBackground(Server... servers) { mServerId = servers[0].getId();//from w w w . j av a2s.c o m String hostName = servers[0].getServerUrl(); int lastVisitInt = servers[0].getLastVisit(); NewsgroupInfo[] newsgroupInfos; ArrayList<String> groupNames = new ArrayList<>(); try { NNTPClient nntpClient = new NNTPClient(); nntpClient.connect(hostName, 119); Log.d(LOG_TAG, "lastVisitInt: " + lastVisitInt); if (lastVisitInt != 0) { Calendar lastVisit = Calendar.getInstance(); lastVisit.setTimeInMillis(lastVisitInt * 1000L); NewGroupsOrNewsQuery query = new NewGroupsOrNewsQuery(lastVisit, false); newsgroupInfos = nntpClient.listNewNewsgroups(query); Log.d(LOG_TAG, "listNewNewsgroups"); } else { newsgroupInfos = nntpClient.listNewsgroups(); Log.d(LOG_TAG, "listNewsgroups"); } nntpClient.disconnect(); } catch (IOException e) { Log.d(LOG_TAG, "IOException"); GroupPresenter groupPresenter = mGroupPresenterWeakReference.get(); if (groupPresenter != null) { groupPresenter.updateNotSuccessful(); } return false; } if (newsgroupInfos == null) { Log.d(LOG_TAG, "newsgroupInfos is null"); return false; } for (NewsgroupInfo newsgroupInfo : newsgroupInfos) { groupNames.add(newsgroupInfo.getNewsgroup()); } return mGroupRepository.saveGroups(mServerId, groupNames); }