From: <ro...@us...> - 2011-08-27 13:52:39
|
Revision: 3884 http://ninan.svn.sourceforge.net/ninan/?rev=3884&view=rev Author: rotvel Date: 2011-08-27 13:52:30 +0000 (Sat, 27 Aug 2011) Log Message: ----------- Final logging work, log exceptions using LogUtil TODO: Figure out how to configure LogBack levels at runtime - or just remove that part Modified Paths: -------------- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/IServiceManager.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerConnection.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerManager.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NzbDownloadProcessor.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/ServiceManager.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/VersionChecker.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/AbstractProcessStarter.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/SetNinanStatusCommand.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/ArticleIterator.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupInfo.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupIterator.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NinanNNTPClient.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/ReplyIterator.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/configuration/Config.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/configuration/DocumentWrapper.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/AbstractDAO.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/ArticleDAO.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/DatabaseManager.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/H2Helper.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/MetaDAO.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/NewsFileDAO.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/db/NzbDAO.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/mail/MailTask.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/newsfile/Article.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/newsfile/NewsFileBuilder.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/newsserver/ArticleDownloader.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/nzb/NzbFileBrowser.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/nzb/NzbFileParser.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/parcheck/ParChecker.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/rmi/NinanRMIClients.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/rmi/NinanRMIServer.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/rmi/NinanRMISession.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/rmi/NinanSslRMIServerSocketFactory.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/rmi/server/threading/RMIThreads.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/siteintegration/NzbAdder.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/siteintegration/newzbin/NewzbinNzbFileDownloader.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/util/DiskUtil.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/util/FileUtilities.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/util/LogUtil.java trunk/ninan-backend/src/main/java/dk/team/ninan/backend/zip/ZipExtracter.java trunk/ninan-frontend/src/main/java/dk/team/ninan/frontend/services/OverviewService.java trunk/ninan-frontend/src/main/java/dk/team/ninan/frontend/wicket/NinanWebApplication.java trunk/ninan-frontend/src/main/java/dk/team/ninan/frontend/wicket/PostIdPanel.java trunk/ninan-frontend/src/main/java/dk/team/ninan/frontend/wicket/feed/NinanXmlStatusPage.java trunk/ninan-frontend/src/main/java/dk/team/ninan/frontend/wicket/overview/OverviewFunctionPanel.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/CompletedNinanDownload.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/Ininan.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/IninanClient.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/IninanRmiFactory.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/IninanSession.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/NZBStatus.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/NinanDownload.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/NinanRMIClient.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/NinanRmiUserContext.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/NinanStatus.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/exceptions/NinanRMIExceptionNotImplemented.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/internal/IninanClientInternal.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/internal/IninanSessionInternal.java trunk/ninan-rmi/src/main/java/dk/team/ninan/rmi/internal/NinanSessionInternal.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/DownloadPanel.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/Formatter.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/INinanServerDetails.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/INinanStats.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/NameValueMenu.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/NinanServerDetailsFrame.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/NinanTrayMonitor.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/NinanTrayRMIClient.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/OpacityHelper.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/SelfRemovingMessagePanel.java trunk/ninan-systemTray/src/main/java/dk/team/ninan/systemtray/SelfRemovingPanelManager.java trunk/ninan-systemTray/src/main/java/org/jdesktop/swinghelper/tray/JXTrayIcon.java trunk/ninan-ws/src/main/java/dk/team/ninan/ws/service/NinanService.java trunk/ninan-ws/src/main/java/dk/team/ninan/ws/service/impl/AbstractService.java trunk/ninan-ws/src/main/java/dk/team/ninan/ws/service/impl/NinanServiceImpl.java Removed Paths: ------------- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/util/ExceptionUtil.java Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/IServiceManager.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/IServiceManager.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/IServiceManager.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -50,8 +50,7 @@ /** * This should only be set with the running or pause status * - * @param ninanStatus - * The ninan status + * @param ninanStatus The ninan status */ public void setNinanStatus(NinanAppStatus ninanStatus); @@ -82,6 +81,6 @@ public void setSchedulerManager(SchedulerManager schedulerManager); public void setDownloadLoader(DownloadLoader downloadLoader); - + public boolean isShuttingDown(); } \ No newline at end of file Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerConnection.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerConnection.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerConnection.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -28,7 +28,6 @@ import dk.team.ninan.backend.commons.NinanNNTPClient; import dk.team.ninan.backend.configuration.Config; import dk.team.ninan.backend.newsfile.ArticleCache; -import dk.team.ninan.backend.util.ExceptionUtil; import dk.team.ninan.backend.util.LogUtil; /** @@ -119,7 +118,7 @@ localIpAddress = InetAddress.getByName(localIp); localPortForConnect = getNextLocalPortForConnect(); } catch (UnknownHostException e) { - logger.error(getConnectID(), e); + LogUtil.logException(getConnectID(), e); } } @@ -141,7 +140,7 @@ try { result = sendCommand("MODE READER"); } catch (IOException e) { - logger.error(getConnectID() + " Unable to set reader mode (" + getReplyString() + ") " + result, e); + LogUtil.logException(getConnectID() + " Unable to set reader mode (" + getReplyString() + ") " + result, e); } } @@ -152,7 +151,7 @@ disconnect(); } catch (IOException e) { logger.info(getConnectID() + " Error for " + newsServer.toString() + " " + e.getClass().getSimpleName() + " " - + ExceptionUtil.filterExceptionMessage(e)); + + LogUtil.filterExceptionMessage(e)); } catch (Exception e) { logger.info(getConnectID() + " Error for " + newsServer.toString() + " " + e.getClass().getSimpleName() + " " + e.getMessage()); } Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerManager.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerManager.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NewsServerManager.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -24,7 +24,6 @@ import dk.team.ninan.backend.configuration.Config; import dk.team.ninan.backend.newsserver.ArticleDownloader; import dk.team.ninan.backend.newsserver.DownloaderStatus; -import dk.team.ninan.backend.util.ExceptionUtil; import dk.team.ninan.backend.util.LogUtil; import dk.team.ninan.backend.util.NewsserverItem; @@ -197,12 +196,12 @@ userMessages.addErrorMessage(e.getMessage()); } catch (IOException e) { // Filter MalformedServerReplyException - String msg = ExceptionUtil.filterExceptionMessage(e); + String msg = LogUtil.filterExceptionMessage(e); downloader.setDownloaderStatus(DownloaderStatus.CANNOTCONNECT, "reason: " + msg); logger.info(server.toString() + " [" + downloader.getName() + " - " + connection.getConnectID() + "] failed to connect (" + e.getClass().getSimpleName() + " " + msg + ")"); } catch (Exception e) { - logger.error(downloader.getName() + " - " + connection.getConnectID(), e); + LogUtil.logException(downloader.getName() + " - " + connection.getConnectID(), e); } return false; } Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NzbDownloadProcessor.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NzbDownloadProcessor.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/NzbDownloadProcessor.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -43,7 +43,6 @@ import dk.team.ninan.backend.rmi.NinanRMIClients; import dk.team.ninan.backend.unrar.RarExtracter; import dk.team.ninan.backend.util.DiskUtil; -import dk.team.ninan.backend.util.ExceptionUtil; import dk.team.ninan.backend.util.FileUtilities; import dk.team.ninan.backend.util.LogUtil; import dk.team.ninan.backend.util.ThreadUtil; @@ -176,9 +175,9 @@ } } catch (Exception e) { if (!isRunning()) { - logger.info("Exception while shutting down: " + ExceptionUtil.toShortString(e)); + logger.info("Exception while shutting down: " + e.toString()); } else { - logger.error("Error processing collection: ", e); + LogUtil.logException("Error processing collection: ", e); } } } @@ -315,9 +314,9 @@ } catch (Exception ex) { if (!isRunning()) { - logger.info("Exception while shutting down: " + ExceptionUtil.toShortString(ex)); + logger.info("Exception while shutting down: " + ex.toString()); } else { - logger.error("Error running smartpar for " + collection.getColStr(true), ex); + LogUtil.logException("Error running smartpar for " + collection.getColStr(true), ex); } } } @@ -345,9 +344,9 @@ } catch (Exception ex) { if (!isRunning()) { - logger.info("Exception while shutting down: " + ExceptionUtil.toShortString(ex)); + logger.info("Exception while shutting down: " + ex.toString()); } else { - logger.error("Error running par for " + collection.getColStr(true), ex); + LogUtil.logException("Error running par for " + collection.getColStr(true), ex); } } } @@ -552,7 +551,7 @@ } } catch (Exception ex) { ninanApplicationContext.displayErrorMessage("End script failed. " + ex.getMessage()); - logger.error("End script failed", ex); + LogUtil.logException("End script failed", ex); } try { if (!isRunning()) { @@ -564,7 +563,7 @@ } } catch (Exception ex) { ninanApplicationContext.displayErrorMessage("All downloaded script failed. " + ex.getMessage()); - logger.error("All downloaded script failed.", ex); + LogUtil.logException("All downloaded script failed.", ex); } ninanRMIClients.notifyOfDLComplete(collection.getId()); } @@ -578,7 +577,7 @@ updateCollection(collection); } catch (Exception ex) { - logger.error("Error post processing collection for " + collection.getColStr(true), ex); + LogUtil.logException("Error post processing collection for " + collection.getColStr(true), ex); } logger.debug("Post-processing finished: " + collection.getColStr(true)); } Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/ServiceManager.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/ServiceManager.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/ServiceManager.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -160,7 +160,7 @@ } LogUtil.logException(e); //TODO: Give our threads more meaningful names - logger.error("Uncaught Exception in " + t.getName(), e); + LogUtil.logException("Uncaught Exception in " + t.getName(), e); } }); databaseManager.initialize(); Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/VersionChecker.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/VersionChecker.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/VersionChecker.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -101,7 +101,7 @@ runningVersion = properties.getProperty("version"); runningVersion = runningVersion.trim(); } catch (IOException e) { - logger.error("Could not find and load the version properties file", e); + LogUtil.logException("Could not find and load the version properties file", e); } } return runningVersion; Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/AbstractProcessStarter.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/AbstractProcessStarter.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/AbstractProcessStarter.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -146,7 +146,7 @@ sb.append("in '"); sb.append(workDir.getPath()); sb.append("'"); - logger.error(sb.toString(), e); + LogUtil.logException(sb.toString(), e); IUserMessages userMessages = (IUserMessages) NinanApplicationContext.getAppCtx().getBean("userMessages", IUserMessages.class); userMessages.addErrorMessage(sb.toString() + ". " + e.getCause()); Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/SetNinanStatusCommand.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/SetNinanStatusCommand.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/command/SetNinanStatusCommand.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -18,8 +18,6 @@ import java.io.File; import java.io.IOException; -import org.slf4j.Logger; - import dk.team.ninan.backend.IServiceManager; import dk.team.ninan.backend.db.NinanAppStatus; import dk.team.ninan.backend.newsserver.DownloadLoader; @@ -28,7 +26,7 @@ import dk.team.ninan.backend.util.LogUtil; public class SetNinanStatusCommand implements ICommand { - private final static Logger logger = LogUtil.getLogger(); + //private final static Logger logger = LogUtil.getLogger(); public static final long serialVersionUID = 1L; @@ -73,7 +71,7 @@ ninanRMIClients.notifyOfNinanRestart(); new File("restart").createNewFile(); } catch (IOException e) { - logger.error("Could not create the file used for restarting Ninan.", e); + LogUtil.logException("Could not create the file used for restarting Ninan.", e); } serviceManager.shutdownAllServices(); break; Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/ArticleIterator.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/ArticleIterator.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/ArticleIterator.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -2,7 +2,6 @@ // dk.team.ninan.backend.commons class contains package private methods. // The only change is NNTPClient -> NinanNNTPClient - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -26,37 +25,39 @@ import java.util.Iterator; import org.apache.commons.net.nntp.Article; + /** - * Class which wraps an {@code Iterable<String>} of raw article information - * to generate an {@code Iterable<Article>} of the parsed information. + * Class which wraps an {@code Iterable<String>} of raw article information to generate an {@code Iterable<Article>} of the parsed information. + * * @since 3.0 */ class ArticleIterator implements Iterator<Article>, Iterable<Article> { - private final Iterator<String> stringIterator; + private final Iterator<String> stringIterator; - public ArticleIterator(Iterable<String> iterableString) { - stringIterator = iterableString.iterator(); - } + public ArticleIterator(Iterable<String> iterableString) { + stringIterator = iterableString.iterator(); + } - public boolean hasNext() { - return stringIterator.hasNext(); - } + public boolean hasNext() { + return stringIterator.hasNext(); + } - /** - * Get the next Article - * @return the next {@link Article}, never {@code null}, if unparseable then isDummy() - * will be true, and the subject will contain the raw info. - */ - public Article next() { - String line = stringIterator.next(); - return NinanNNTPClient.__parseArticleEntry(line); - } + /** + * Get the next Article + * + * @return the next {@link Article}, never {@code null}, if unparseable then isDummy() will be true, and the subject will contain the raw info. + */ + public Article next() { + String line = stringIterator.next(); + return NinanNNTPClient.__parseArticleEntry(line); + } - public void remove() { - stringIterator.remove(); - } - public Iterator<Article> iterator() { - return this; - } + public void remove() { + stringIterator.remove(); + } + + public Iterator<Article> iterator() { + return this; + } } Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupInfo.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupInfo.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupInfo.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -1,8 +1,6 @@ // This is a verbatim copy of the commons-net 3.0.1 class. Needed because the // dk.team.ninan.backend.commons class contains package private methods. - - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -23,155 +21,129 @@ package dk.team.ninan.backend.commons; /*** - * NewsgroupInfo stores information pertaining to a newsgroup returned by - * the NNTP GROUP, LIST, and NEWGROUPS commands, implemented by - * {@link org.apache.commons.net.nntp.NNTPClient#selectNewsgroup selectNewsgroup } - * , - * {@link org.apache.commons.net.nntp.NNTPClient#listNewsgroups listNewsgroups } - * , and - * {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsgroups } - * respectively. + * NewsgroupInfo stores information pertaining to a newsgroup returned by the NNTP GROUP, LIST, and NEWGROUPS commands, implemented by + * {@link org.apache.commons.net.nntp.NNTPClient#selectNewsgroup selectNewsgroup } , {@link org.apache.commons.net.nntp.NNTPClient#listNewsgroups + * listNewsgroups } , and {@link org.apache.commons.net.nntp.NNTPClient#listNewNewsgroups listNewNewsgroups } respectively. * <p> * <p> + * * @see NNTPClient ***/ -public final class NewsgroupInfo -{ - /*** - * A constant indicating that the posting permission of a newsgroup is - * unknown. For example, the NNTP GROUP command does not return posting - * information, so NewsgroupInfo instances obtained from that command - * willhave an UNKNOWN_POSTING_PERMISSION. - ***/ - public static final int UNKNOWN_POSTING_PERMISSION = 0; +public final class NewsgroupInfo { + /*** + * A constant indicating that the posting permission of a newsgroup is unknown. For example, the NNTP GROUP command does not return posting + * information, so NewsgroupInfo instances obtained from that command willhave an UNKNOWN_POSTING_PERMISSION. + ***/ + public static final int UNKNOWN_POSTING_PERMISSION = 0; - /*** A constant indicating that a newsgroup is moderated. ***/ - public static final int MODERATED_POSTING_PERMISSION = 1; + /*** A constant indicating that a newsgroup is moderated. ***/ + public static final int MODERATED_POSTING_PERMISSION = 1; - /*** A constant indicating that a newsgroup is public and unmoderated. ***/ - public static final int PERMITTED_POSTING_PERMISSION = 2; + /*** A constant indicating that a newsgroup is public and unmoderated. ***/ + public static final int PERMITTED_POSTING_PERMISSION = 2; - /*** - * A constant indicating that a newsgroup is closed for general posting. - ***/ - public static final int PROHIBITED_POSTING_PERMISSION = 3; + /*** + * A constant indicating that a newsgroup is closed for general posting. + ***/ + public static final int PROHIBITED_POSTING_PERMISSION = 3; - private String __newsgroup; - private long __estimatedArticleCount; - private long __firstArticle; - private long __lastArticle; - private int __postingPermission; + private String __newsgroup; + private long __estimatedArticleCount; + private long __firstArticle; + private long __lastArticle; + private int __postingPermission; - void _setNewsgroup(String newsgroup) - { - __newsgroup = newsgroup; - } + void _setNewsgroup(String newsgroup) { + __newsgroup = newsgroup; + } - void _setArticleCount(long count) - { - __estimatedArticleCount = count; - } + void _setArticleCount(long count) { + __estimatedArticleCount = count; + } - void _setFirstArticle(long first) - { - __firstArticle = first; - } + void _setFirstArticle(long first) { + __firstArticle = first; + } - void _setLastArticle(long last) - { - __lastArticle = last; - } + void _setLastArticle(long last) { + __lastArticle = last; + } - void _setPostingPermission(int permission) - { - __postingPermission = permission; - } + void _setPostingPermission(int permission) { + __postingPermission = permission; + } - /*** - * Get the newsgroup name. - * <p> - * @return The name of the newsgroup. - ***/ - public String getNewsgroup() - { - return __newsgroup; - } + /*** + * Get the newsgroup name. + * <p> + * + * @return The name of the newsgroup. + ***/ + public String getNewsgroup() { + return __newsgroup; + } - /*** - * Get the estimated number of articles in the newsgroup. The - * accuracy of this value will depend on the server implementation. - * <p> - * @return The estimated number of articles in the newsgroup. - ***/ - public long getArticleCountLong() - { - return __estimatedArticleCount; - } + /*** + * Get the estimated number of articles in the newsgroup. The accuracy of this value will depend on the server implementation. + * <p> + * + * @return The estimated number of articles in the newsgroup. + ***/ + public long getArticleCountLong() { + return __estimatedArticleCount; + } - /*** - * Get the number of the first article in the newsgroup. - * <p> - * @return The number of the first article in the newsgroup. - ***/ - public long getFirstArticleLong() - { - return __firstArticle; - } + /*** + * Get the number of the first article in the newsgroup. + * <p> + * + * @return The number of the first article in the newsgroup. + ***/ + public long getFirstArticleLong() { + return __firstArticle; + } - /*** - * Get the number of the last article in the newsgroup. - * <p> - * @return The number of the last article in the newsgroup. - ***/ - public long getLastArticleLong() - { - return __lastArticle; - } + /*** + * Get the number of the last article in the newsgroup. + * <p> + * + * @return The number of the last article in the newsgroup. + ***/ + public long getLastArticleLong() { + return __lastArticle; + } - /*** - * Get the posting permission of the newsgroup. This will be one of - * the <code> POSTING_PERMISSION </code> constants. - * <p> - * @return The posting permission status of the newsgroup. - ***/ - public int getPostingPermission() - { - return __postingPermission; - } + /*** + * Get the posting permission of the newsgroup. This will be one of the <code> POSTING_PERMISSION </code> constants. + * <p> + * + * @return The posting permission status of the newsgroup. + ***/ + public int getPostingPermission() { + return __postingPermission; + } - /* - public String toString() { - StringBuilder buffer = new StringBuilder(); - buffer.append(__newsgroup); - buffer.append(' '); - buffer.append(__lastArticle); - buffer.append(' '); - buffer.append(__firstArticle); - buffer.append(' '); - switch(__postingPermission) { - case 1: buffer.append('m'); break; - case 2: buffer.append('y'); break; - case 3: buffer.append('n'); break; - } - return buffer.toString(); -} - */ + /* + * public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(__newsgroup); buffer.append(' '); + * buffer.append(__lastArticle); buffer.append(' '); buffer.append(__firstArticle); buffer.append(' '); switch(__postingPermission) { case 1: + * buffer.append('m'); break; case 2: buffer.append('y'); break; case 3: buffer.append('n'); break; } return buffer.toString(); } + */ - // DEPRECATED METHODS - for API compatibility only - DO NOT USE + // DEPRECATED METHODS - for API compatibility only - DO NOT USE - @Deprecated - public int getArticleCount() { - return (int) __estimatedArticleCount; - } + @Deprecated + public int getArticleCount() { + return (int) __estimatedArticleCount; + } - @Deprecated - public int getFirstArticle() { - return (int) __firstArticle; - } + @Deprecated + public int getFirstArticle() { + return (int) __firstArticle; + } - @Deprecated - public int getLastArticle() { - return (int) __lastArticle; - } + @Deprecated + public int getLastArticle() { + return (int) __lastArticle; + } } Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupIterator.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupIterator.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NewsgroupIterator.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -2,7 +2,6 @@ // dk.team.ninan.backend.commons class contains package private methods. // The only change is NNTPClient -> NinanNNTPClient - /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -24,33 +23,34 @@ package dk.team.ninan.backend.commons; import java.util.Iterator; + /** - * Class which wraps an {@code Iterable<String>} of raw newgroup information - * to generate an {@code Iterable<NewsgroupInfo>} of the parsed information. + * Class which wraps an {@code Iterable<String>} of raw newgroup information to generate an {@code Iterable<NewsgroupInfo>} of the parsed information. + * * @since 3.0 */ class NewsgroupIterator implements Iterator<NewsgroupInfo>, Iterable<NewsgroupInfo> { - private final Iterator<String> stringIterator; + private final Iterator<String> stringIterator; - public NewsgroupIterator(Iterable<String> iterableString) { - stringIterator = iterableString.iterator(); - } + public NewsgroupIterator(Iterable<String> iterableString) { + stringIterator = iterableString.iterator(); + } - public boolean hasNext() { - return stringIterator.hasNext(); - } + public boolean hasNext() { + return stringIterator.hasNext(); + } - public NewsgroupInfo next() { - String line = stringIterator.next(); - return NinanNNTPClient.__parseNewsgroupListEntry(line); - } + public NewsgroupInfo next() { + String line = stringIterator.next(); + return NinanNNTPClient.__parseNewsgroupListEntry(line); + } - public void remove() { - stringIterator.remove(); - } + public void remove() { + stringIterator.remove(); + } - public Iterator<NewsgroupInfo> iterator() { - return this; - } + public Iterator<NewsgroupInfo> iterator() { + return this; + } } Modified: trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NinanNNTPClient.java =================================================================== --- trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NinanNNTPClient.java 2011-08-27 03:27:03 UTC (rev 3883) +++ trunk/ninan-backend/src/main/java/dk/team/ninan/backend/commons/NinanNNTPClient.java 2011-08-27 13:52:30 UTC (rev 3884) @@ -43,54 +43,31 @@ import org.apache.commons.net.nntp.NewGroupsOrNewsQuery; /*** - * NNTPClient encapsulates all the functionality necessary to post and - * retrieve articles from an NNTP server. As with all classes derived - * from {@link org.apache.commons.net.SocketClient}, - * you must first connect to the server with - * {@link org.apache.commons.net.SocketClient#connect connect } - * before doing anything, and finally - * {@link org.apache.commons.net.nntp.NNTP#disconnect disconnect() } - * after you're completely finished interacting with the server. - * Remember that the - * {@link org.apache.commons.net.nntp.NNTP#isAllowedToPost isAllowedToPost()} - * method is defined in + * NNTPClient encapsulates all the functionality necessary to post and retrieve articles from an NNTP server. As with all classes derived from + * {@link org.apache.commons.net.SocketClient}, you must first connect to the server with {@link org.apache.commons.net.SocketClient#connect connect } + * before doing anything, and finally {@link org.apache.commons.net.nntp.NNTP#disconnect disconnect() } after you're completely finished interacting + * with the server. Remember that the {@link org.apache.commons.net.nntp.NNTP#isAllowedToPost isAllowedToPost()} method is defined in * {@link org.apache.commons.net.nntp.NNTP}. * <p> - * You should keep in mind that the NNTP server may choose to prematurely - * close a connection if the client has been idle for longer than a - * given time period or if the server is being shutdown by the operator or - * some other reason. The NNTP class will detect a - * premature NNTP server connection closing when it receives a - * {@link org.apache.commons.net.nntp.NNTPReply#SERVICE_DISCONTINUED NNTPReply.SERVICE_DISCONTINUED } - * response to a command. - * When that occurs, the NNTP class method encountering that reply will throw - * an {@link org.apache.commons.net.nntp.NNTPConnectionClosedException} - * . - * <code>NNTPConectionClosedException</code> - * is a subclass of <code> IOException </code> and therefore need not be - * caught separately, but if you are going to catch it separately, its - * catch block must appear before the more general <code> IOException </code> - * catch block. When you encounter an - * {@link org.apache.commons.net.nntp.NNTPConnectionClosedException} - * , you must disconnect the connection with - * {@link org.apache.commons.net.nntp.NNTP#disconnect disconnect() } - * to properly clean up the - * system resources used by NNTP. Before disconnecting, you may check the - * last reply code and text with - * {@link org.apache.commons.net.nntp.NNTP#getReplyCode getReplyCode } and - * {@link org.apache.commons.net.nntp.NNTP#getReplyString getReplyString }. + * You should keep in mind that the NNTP server may choose to prematurely close a connection if the client has been idle for longer than a given time + * period or if the server is being shutdown by the operator or some other reason. The NNTP class will detect a premature NNTP server connection + * closing when it receives a {@link org.apache.commons.net.nntp.NNTPReply#SERVICE_DISCONTINUED NNTPReply.SERVICE_DISCONTINUED } response to a + * command. When that occurs, the NNTP class method encountering that reply will throw an + * {@link org.apache.commons.net.nntp.NNTPConnectionClosedException} . <code>NNTPConectionClosedException</code> is a subclass of + * <code> IOException </code> and therefore need not be caught separately, but if you are going to catch it separately, its catch block must appear + * before the more general <code> IOException </code> catch block. When you encounter an + * {@link org.apache.commons.net.nntp.NNTPConnectionClosedException} , you must disconnect the connection with + * {@link org.apache.commons.net.nntp.NNTP#disconnect disconnect() } to properly clean up the system resources used by NNTP. Before disconnecting, you + * may check the last reply code and text with {@link org.apache.commons.net.nntp.NNTP#getReplyCode getReplyCode } and + * {@link org.apache.commons.net.nntp.NNTP#getReplyString getReplyString }. * <p> - * Rather than list it separately for each method, we mention here that - * every method communicating with the server and throwing an IOException - * can also throw a - * {@link org.apache.commons.net.MalformedServerReplyException} - * , which is a subclass - * of IOException. A MalformedServerReplyException will be thrown when - * the reply received from the server deviates enough from the protocol - * specification that it cannot be interpreted in a useful manner despite - * attempts to be as lenient as possible. + * Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can + * also throw a {@link org.apache.commons.net.MalformedServerReplyException} , which is a subclass of IOException. A MalformedServerReplyException + * will be thrown when the reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful + * manner despite attempts to be as lenient as possible. * <p> * <p> + * * @author Rory Winston * @author Ted Wise * @see NNTP @@ -98,1652 +75,1273 @@ * @see org.apache.commons.net.MalformedServerReplyException ***/ -public class NinanNNTPClient extends NinanNNTP -{ +public class NinanNNTPClient extends NinanNNTP { - /** - * Parse the reply and store the id and number in the pointer. - * - * @param reply the reply to parse "22n nnn <aaa>" - * @param pointer the pointer to update - * - * @throws MalformedServerReplyException - */ - private void __parseArticlePointer(String reply, ArticleInfo pointer) - throws MalformedServerReplyException - { - String tokens[] = reply.split(" "); - if (tokens.length >= 3) { // OK, we can parset the line - int i = 1; // skip reply code - try - { - // Get article number - pointer.articleNumber = Long.parseLong(tokens[i++]); - // Get article id - pointer.articleId = tokens[i++]; - return; // done - } - catch (NumberFormatException e) - { - // drop through and raise exception - } - } - throw new MalformedServerReplyException( - "Could not parse article pointer.\nServer reply: " + reply); - } + /** + * Parse the reply and store the id and number in the pointer. + * + * @param reply the reply to parse "22n nnn <aaa>" + * @param pointer the pointer to update + * @throws MalformedServerReplyException + */ + private void __parseArticlePointer(String reply, ArticleInfo pointer) throws MalformedServerReplyException { + String tokens[] = reply.split(" "); + if (tokens.length >= 3) { // OK, we can parset the line + int i = 1; // skip reply code + try { + // Get article number + pointer.articleNumber = Long.parseLong(tokens[i++]); + // Get article id + pointer.articleId = tokens[i++]; + return; // done + } catch (NumberFormatException e) { + // drop through and raise exception + } + } + throw new MalformedServerReplyException("Could not parse article pointer.\nServer reply: " + reply); + } - /* - * 211 n f l s group selected - * (n = estimated number of articles in group, - * f = first article number in the group, - * l = last article number in the group, - * s = name of the group.) - */ + /* + * 211 n f l s group selected (n = estimated number of articles in group, f = first article number in the group, l = last article number in the + * group, s = name of the group.) + */ - private static void __parseGroupReply(String reply, NewsgroupInfo info) - throws MalformedServerReplyException - { - String tokens[] = reply.split(" "); - if (tokens.length >= 5) { - int i = 1; // Skip numeric response value - try - { - // Get estimated article count - info._setArticleCount(Long.parseLong(tokens[i++])); - // Get first article number - info._setFirstArticle(Long.parseLong(tokens[i++])); - // Get last article number - info._setLastArticle(Long.parseLong(tokens[i++])); - // Get newsgroup name - info._setNewsgroup(tokens[i++]); + private static void __parseGroupReply(String reply, NewsgroupInfo info) throws MalformedServerReplyException { + String tokens[] = reply.split(" "); + if (tokens.length >= 5) { + int i = 1; // Skip numeric response value + try { + // Get estimated article count + info._setArticleCount(Long.parseLong(tokens[i++])); + // Get first article number + info._setFirstArticle(Long.parseLong(tokens[i++])); + // Get last article number + info._setLastArticle(Long.parseLong(tokens[i++])); + // Get newsgroup name + info._setNewsgroup(tokens[i++]); - info._setPostingPermission(NewsgroupInfo.UNKNOWN_POSTING_PERMISSION); - return ; - } catch (NumberFormatException e) - { - // drop through to report error - } - } + info._setPostingPermission(NewsgroupInfo.UNKNOWN_POSTING_PERMISSION); + return; + } catch (NumberFormatException e) { + // drop through to report error + } + } - throw new MalformedServerReplyException( - "Could not parse newsgroup info.\nServer reply: " + reply); - } + throw new MalformedServerReplyException("Could not parse newsgroup info.\nServer reply: " + reply); + } + // Format: group last first p + static NewsgroupInfo __parseNewsgroupListEntry(String entry) { + String tokens[] = entry.split(" "); + if (tokens.length < 4) { + return null; + } + NewsgroupInfo result = new NewsgroupInfo(); - // Format: group last first p - static NewsgroupInfo __parseNewsgroupListEntry(String entry) - { - String tokens[] = entry.split(" "); - if (tokens.length < 4) { - return null; - } - NewsgroupInfo result = new NewsgroupInfo(); + int i = 0; - int i = 0; + result._setNewsgroup(tokens[i++]); - result._setNewsgroup(tokens[i++]); + try { + long lastNum = Long.parseLong(tokens[i++]); + long firstNum = Long.parseLong(tokens[i++]); + result._setFirstArticle(firstNum); + result._setLastArticle(lastNum); + if ((firstNum == 0) && (lastNum == 0)) + result._setArticleCount(0); + else + result._setArticleCount(lastNum - firstNum + 1); + } catch (NumberFormatException e) { + return null; + } - try - { - long lastNum = Long.parseLong(tokens[i++]); - long firstNum = Long.parseLong(tokens[i++]); - result._setFirstArticle(firstNum); - result._setLastArticle(lastNum); - if((firstNum == 0) && (lastNum == 0)) - result._setArticleCount(0); - else - result._setArticleCount(lastNum - firstNum + 1); - } - catch (NumberFormatException e) - { - return null; - } + switch (tokens[i++].charAt(0)) { + case 'y': + case 'Y': + result._setPostingPermission(NewsgroupInfo.PERMITTED_POSTING_PERMISSION); + break; + case 'n': + case 'N': + result._setPostingPermission(NewsgroupInfo.PROHIBITED_POSTING_PERMISSION); + break; + case 'm': + case 'M': + result._setPostingPermission(NewsgroupInfo.MODERATED_POSTING_PERMISSION); + break; + default: + result._setPostingPermission(NewsgroupInfo.UNKNOWN_POSTING_PERMISSION); + break; + } - switch (tokens[i++].charAt(0)) - { - case 'y': - case 'Y': - result._setPostingPermission( - NewsgroupInfo.PERMITTED_POSTING_PERMISSION); - break; - case 'n': - case 'N': - result._setPostingPermission( - NewsgroupInfo.PROHIBITED_POSTING_PERMISSION); - break; - case 'm': - case 'M': - result._setPostingPermission( - NewsgroupInfo.MODERATED_POSTING_PERMISSION); - break; - default: - result._setPostingPermission( - NewsgroupInfo.UNKNOWN_POSTING_PERMISSION); - break; - } + return result; + } - return result; - } + /** + * Parse a response line from {@link #retrieveArticleInfo(long, long)}. + * + * @param line a response line + * @return the parsed {@link Article}, if unparseable then isDummy() will be true, and the subject will contain the raw info. + * @since 3.0 + */ + static Article __parseArticleEntry(String line) { + // Extract the article information + // Mandatory format (from NNTP RFC 2980) is : + // articleNumber\tSubject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count - /** - * Parse a response line from {@link #retrieveArticleInfo(long, long)}. - * - * @param line a response line - * @return the parsed {@link Article}, if unparseable then isDummy() - * will be true, and the subject will contain the raw info. - * @since 3.0 - */ - static Article __parseArticleEntry(String line) { - // Extract the article information - // Mandatory format (from NNTP RFC 2980) is : - // articleNumber\tSubject\tAuthor\tDate\tID\tReference(s)\tByte Count\tLine Count + Article article = new Article(); + article.setSubject(line); // in case parsing fails + String parts[] = line.split("\t"); + if (parts.length > 6) { + int i = 0; + try { + article.setArticleNumber(Long.parseLong(parts[i++])); + article.setSubject(parts[i++]); + article.setFrom(parts[i++]); + article.setDate(parts[i++]); + article.setArticleId(parts[i++]); + article.addReference(parts[i++]); + } catch (NumberFormatException e) { + // ignored, already handled + } + } + return article; + } - Article article = new Article(); - article.setSubject(line); // in case parsing fails - String parts[] = line.split("\t"); - if (parts.length > 6) { - int i = 0; - try { - article.setArticleNumber(Long.parseLong(parts[i++])); - article.setSubject(parts[i++]); - article.setFrom(parts[i++]); - article.setDate(parts[i++]); - article.setArticleId(parts[i++]); - article.addReference(parts[i++]); - } catch (NumberFormatException e) { - // ignored, already handled - } - } - return article; - } + private NewsgroupInfo[] __readNewsgroupListing() throws IOException { - private NewsgroupInfo[] __readNewsgroupListing() throws IOException - { + BufferedReader reader = new DotTerminatedMessageReader(_reader_); + // Start of with a big vector because we may be reading a very large + // amount of groups. + Vector<NewsgroupInfo> list = new Vector<NewsgroupInfo>(2048); - BufferedReader reader = new DotTerminatedMessageReader(_reader_); - // Start of with a big vector because we may be reading a very large - // amount of groups. - Vector<NewsgroupInfo> list = new Vector<NewsgroupInfo>(2048); + String line; + while ((line = reader.readLine()) != null) { + NewsgroupInfo tmp = __parseNewsgroupListEntry(line); + if (tmp != null) + list.addElement(tmp); + else + throw new MalformedServerReplyException(line); + } - String line; - while ((line = reader.readLine()) != null) - { - NewsgroupInfo tmp = __parseNewsgroupListEntry(line); - if (tmp != null) - list.addElement(tmp); - else - throw new MalformedServerReplyException(line); - } + int size; + if ((size = list.size()) < 1) + return new NewsgroupInfo[0]; - int size; - if ((size = list.size()) < 1) - return new NewsgroupInfo[0]; + NewsgroupInfo[] info = new NewsgroupInfo[size]; + list.copyInto(info); - NewsgroupInfo[] info = new NewsgroupInfo[size]; - list.copyInto(info); + return info; + } - return info; - } + private BufferedReader __retrieve(int command, String articleId, ArticleInfo pointer) throws IOException { + if (articleId != null) { + if (!NNTPReply.isPositiveCompletion(sendCommand(command, articleId))) { + return null; + } + } else { + if (!NNTPReply.isPositiveCompletion(sendCommand(command))) { + return null; + } + } + if (pointer != null) { + __parseArticlePointer(getReplyString(), pointer); + } - private BufferedReader __retrieve(int command, - String articleId, ArticleInfo pointer) - throws IOException - { - if (articleId != null) - { - if (!NNTPReply.isPositiveCompletion(sendCommand(command, articleId))) { - return null; - } - } - else - { - if (!NNTPReply.isPositiveCompletion(sendCommand(command))) { - return null; - } - } + return new DotTerminatedMessageReader(_reader_); + } + private BufferedReader __retrieve(int command, long articleNumber, ArticleInfo pointer) throws IOException { + if (!NNTPReply.isPositiveCompletion(sendCommand(command, Long.toString(articleNumber)))) { + return null; + } - if (pointer != null) { - __parseArticlePointer(getReplyString(), pointer); - } + if (pointer != null) { + __parseArticlePointer(getReplyString(), pointer); + } - return new DotTerminatedMessageReader(_reader_); - } + return new DotTerminatedMessageReader(_reader_); + } + /*** + * Retrieves an article from the NNTP server. The article is referenced by its unique article identifier (including the enclosing < and >). + * The article number and identifier contained in the server reply are returned through an ArticleInfo. The <code> articleId </code> field of the + * ArticleInfo cannot always be trusted because some NNTP servers do not correctly follow the RFC 977 reply format. + * <p> + * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + * <p> + * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned + * BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned + * BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and + * their replies read. If you do not follow these requirements, your program will not work properly. + * <p> + * + * @param articleId The unique article identifier of the article to retrieve. If this parameter is null, the currently selected article is + * retrieved. + * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of + * server deviations from RFC 977 reply formats. You may set this parameter to null if you do not desire to retrieve the returned article + * information. + * @return A DotTerminatedMessageReader instance from which the article be read. null if the article does not exist. + * @exception NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some + * other reason causing the server to send NNTP reply code 400. This exception may be caught either as an IOException or independently + * as itself. + * @exception IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server. + ***/ + public BufferedReader retrieveArticle(String articleId, ArticleInfo pointer) throws IOException { + return __retrieve(NNTPCommand.ARTICLE, articleId, pointer); - private BufferedReader __retrieve(int command, - long articleNumber, ArticleInfo pointer) - throws IOException - { - if (!NNTPReply.isPositiveCompletion(sendCommand(command, - Long.toString(articleNumber)))) { - return null; - } + } - if (pointer != null) { - __parseArticlePointer(getReplyString(), pointer); - } + /** + * Same as <code> retrieveArticle(articleId, (ArticleInfo) null) </code> Note: the return can be cast to a {@link BufferedReader} + */ + public Reader retrieveArticle(String articleId) throws IOException { + return retrieveArticle(articleId, (ArticleInfo) null); + } - return new DotTerminatedMessageReader(_reader_); - } + /** + * Same as <code> retrieveArticle((String) null) </code> Note: the return can be cast to a {@link BufferedReader} + */ + public Reader retrieveArticle() throws IOException { + return retrieveArticle((String) null); + } + /*** + * Retrieves an article from the currently selected newsgroup. The article is referenced by its article number. The article number and identifier + * contained in the server reply are returned through an ArticleInfo. The <code> articleId </code> field of the ArticleInfo cannot always be + * trusted because some NNTP servers do not correctly follow the RFC 977 reply format. + * <p> + * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + * <p> + * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned + * BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned + * BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and + * their replies read. If you do not follow these requirements, your program will not work properly. + * <p> + * + * @param articleNumber The number of the the article to retrieve. + * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of + * server deviations from RFC 977 reply formats. You may set this parameter to null if you do not desire to retrieve the returned article + * information. + * @return A DotTerminatedMessageReader instance from which the article be read. null if the article does not exist. + * @exception NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some + * other reason causing the server to send NNTP reply code 400. This exception may be caught either as an IOException or independently + * as itself. + * @exception IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server. + ***/ + public BufferedReader retrieveArticle(long articleNumber, ArticleInfo pointer) throws IOException { + return __retrieve(NNTPCommand.ARTICLE, articleNumber, pointer); + } + /*** Same as <code> retrieveArticle(articleNumber, null) </code> ***/ + public BufferedReader retrieveArticle(long articleNumber) throws IOException { + return retrieveArticle(articleNumber, null); + } - /*** - * Retrieves an article from the NNTP server. The article is referenced - * by its unique article identifier (including the enclosing < and >). - * The article number and identifier contained in the server reply - * are returned through an ArticleInfo. The <code> articleId </code> - * field of the ArticleInfo cannot always be trusted because some - * NNTP servers do not correctly follow the RFC 977 reply format. - * <p> - * A DotTerminatedMessageReader is returned from which the article can - * be read. If the article does not exist, null is returned. - * <p> - * You must not issue any commands to the NNTP server (i.e., call any - * other methods) until you finish reading the message from the returned - * BufferedReader instance. - * The NNTP protocol uses the same stream for issuing commands as it does - * for returning results. Therefore the returned BufferedReader actually reads - * directly from the NNTP connection. After the end of message has been - * reached, new commands can be executed and their replies read. If - * you do not follow these requirements, your program will not work - * properly. - * <p> - * @param articleId The unique article identifier of the article to - * retrieve. If this parameter is null, the currently selected - * article is retrieved. - * @param pointer A parameter through which to return the article's - * number and unique id. The articleId field cannot always be trusted - * because of server deviations from RFC 977 reply formats. You may - * set this parameter to null if you do not desire to retrieve the - * returned article information. - * @return A DotTerminatedMessageReader instance from which the article - * be read. null if the article does not exist. - * @exception NNTPConnectionClosedException - * If the NNTP server prematurely closes the connection as a result - * of the client being idle or some other reason causing the server - * to send NNTP reply code 400. This exception may be caught either - * as an IOException or independently as itself. - * @exception IOException If an I/O error occurs while either sending a - * command to the server or receiving a reply from the server. - ***/ - public BufferedReader retrieveArticle(String articleId, ArticleInfo pointer) - throws IOException - { - return __retrieve(NNTPCommand.ARTICLE, articleId, pointer); + /*** + * Retrieves an article header from the NNTP server. The article is referenced by its unique article identifier (including the enclosing < and + * >). The article number and identifier contained in the server reply are returned through an ArticleInfo. The <code> articleId </code> field + * of the ArticleInfo cannot always be trusted because some NNTP servers do not correctly follow the RFC 977 reply format. + * <p> + * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + * <p> + * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned + * BufferedReader instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore the returned + * BufferedReader actually reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and + * their replies read. If you do not follow these requirements, your program will not work properly. + * <p> + * + * @param articleId The unique article identifier of the article whose header is being retrieved. If this parameter is null, the header of the + * currently selected article is retrieved. + * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of + * server deviations from RFC 977 reply formats. You may set this parameter to null if you do not desire to retrieve the returned article + * information. + * @return A DotTerminatedMessageReader instance from which the article header can be read. null if the article does not exist. + * @exception NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some + * other reason causing the server to send NNTP reply code 400. This exception may be caught either as an IOException or independently + * as itself. + * @exception IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server. + ***/ + public BufferedReader retrieveArticleHeader(String articleId, ArticleInfo pointer) throws IOException { + return __retrieve(NNTPCommand.HEAD, articleId, pointer); - } + } - /** - * Same as <code> retrieveArticle(articleId, (ArticleInfo) null) </code> - * Note: the return can be cast to a {@link BufferedReader} - */ - public Reader retrieveArticle(String articleId) throws IOException - { - return retrieveArticle(articleId, (ArticleInfo) null); - } + /** + * Same as <code> retrieveArticleHeader(articleId, (ArticleInfo) null) </code> Note: the return can be cast to a {@link BufferedReader} + */ + public Reader retrieveArticleHeader(String articleId) throws IOException { + return retrieveArticleHeader(articleId, (Ar... [truncated message content] |