📄 nntpconnection.java
字号:
* @return the article number/message-id pair associated with the new * article */ public ArticleResponse last() throws IOException { return articleImpl(LAST, null); } // RFC977:3.6 The LIST command /** * Send a group listing command to the server. * Returns a GroupIterator. This must be read fully before other commands * are issued. */ public GroupIterator list() throws IOException { return listImpl(LIST); } GroupIterator listImpl(String command) throws IOException { send(command); StatusResponse response = parseResponse(read()); switch (response.status) { case LIST_FOLLOWS: GroupIterator gi = new GroupIterator(this); pendingData = gi; return gi; default: throw new NNTPException(response); } } // RFC977:3.7 The NEWGROUPS command /** * Returns an iterator over the list of new groups on the server since the * specified date. * NB this method suffers from a minor millenium bug. * * @param since the date from which to list new groups * @param distributions if non-null, an array of distributions to match */ public LineIterator newGroups(Date since, String[]distributions) throws IOException { StringBuffer buffer = new StringBuffer(NEWGROUPS); buffer.append(' '); buffer.append(formatDate(since)); if (distributions != null) { buffer.append(' '); for (int i = 0; i < distributions.length; i++) { if (i > 0) { buffer.append(','); } buffer.append(distributions[i]); } } send(buffer.toString()); StatusResponse response = parseResponse(read()); switch (response.status) { case NEWGROUPS_LIST_FOLLOWS: LineIterator li = new LineIterator(this); pendingData = li; return li; default: throw new NNTPException(response); } } // RFC977:3.8 The NEWNEWS command /** * Returns an iterator over the list of message-ids posted or received to * the specified newsgroup(s) since the specified date. * NB this method suffers from a minor millenium bug. * * @param newsgroup the newsgroup wildmat * @param since the date from which to list new articles * @param distributions if non-null, a list of distributions to match */ public LineIterator newNews(String newsgroup, Date since, String[] distributions) throws IOException { StringBuffer buffer = new StringBuffer(NEWNEWS); buffer.append(' '); buffer.append(newsgroup); buffer.append(' '); buffer.append(formatDate(since)); if (distributions != null) { buffer.append(' '); for (int i = 0; i < distributions.length; i++) { if (i > 0) { buffer.append(','); } buffer.append(distributions[i]); } } send(buffer.toString()); StatusResponse response = parseResponse(read()); switch (response.status) { case NEWNEWS_LIST_FOLLOWS: LineIterator li = new LineIterator(this); pendingData = li; return li; default: throw new NNTPException(response); } } // RFC977:3.9 The NEXT command /** * Sends a next article positioning command to the server. * @return the article number/message-id pair associated with the new * article */ public ArticleResponse next() throws IOException { return articleImpl(NEXT, null); } // RFC977:3.10 The POST command /** * Post an article. This is a two-stage process. * If successful, returns an output stream to write the article to. * Clients should call <code>write()</code> on the stream for all the * bytes of the article, and finally call <code>close()</code> * on the stream. * No other method should be called in between. * @see #postComplete */ public OutputStream post() throws IOException { send(POST); StatusResponse response = parseResponse(read()); switch (response.status) { case SEND_ARTICLE: return new PostStream(this, false); default: // POSTING_NOT_ALLOWED throw new NNTPException(response); } } /** * Indicates that the client has finished writing all the bytes of the * article. * Called by the PostStream during <code>close()</code>. * @see #post */ void postComplete() throws IOException { send(DOT); StatusResponse response = parseResponse(read()); switch (response.status) { case ARTICLE_POSTED: case ARTICLE_TRANSFERRED: return; default: // POSTING_FAILED // TRANSFER_FAILED // ARTICLE_REJECTED throw new NNTPException(response); } } // RFC977:3.11 The QUIT command /** * Close the connection. * After calling this method, no further calls on this object are valid. */ public void quit() throws IOException { send(QUIT); StatusResponse response = parseResponse(read()); switch (response.status) { case CLOSING_CONNECTION: socket.close(); return; default: throw new NNTPException(response); } } // RFC977:3.12 The SLAVE command /** * Indicates to the server that this is a slave connection. */ public void slave() throws IOException { send(SLAVE); StatusResponse response = parseResponse(read()); switch (response.status) { case SLAVE_ACKNOWLEDGED: break; default: throw new NNTPException(response); } } // RFC2980:1.1 The CHECK command public boolean check(String messageId) throws IOException { StringBuffer buffer = new StringBuffer(CHECK); buffer.append(' '); buffer.append(messageId); send(buffer.toString()); StatusResponse response = parseResponse(read()); switch (response.status) { case SEND_ARTICLE_VIA_TAKETHIS: return true; case ARTICLE_NOT_WANTED_VIA_TAKETHIS: return false; default: // SERVICE_DISCONTINUED // TRY_AGAIN_LATER // TRANSFER_PERMISSION_DENIED // COMMAND_NOT_RECOGNIZED throw new NNTPException(response); } } // RFC2980:1.2 The MODE STREAM command /** * Attempt to initialise the connection in streaming mode. * This is generally used to bypass the lock step nature of NNTP in order * to perform a series of CHECK and TAKETHIS commands. * * @return true if the server supports streaming mode */ public boolean modeStream() throws IOException { send(MODE_STREAM); StatusResponse response = parseResponse(read()); switch (response.status) { case STREAMING_OK: return true; default: // COMMAND_NOT_RECOGNIZED return false; } } // RFC2980:1.3 The TAKETHIS command /** * Implements the out-of-order takethis command. * The client uses the returned output stream to write all the bytes of the * article. When complete, it calls <code>close()</code> on the * stream. * @see #takethisComplete */ public OutputStream takethis(String messageId) throws IOException { send(TAKETHIS + ' ' + messageId); return new PostStream(this, true); } /** * Completes a takethis transaction. * Called by PostStream.close(). * @see #takethis */ void takethisComplete() throws IOException { send(DOT); StatusResponse response = parseResponse(read()); switch (response.status) { case ARTICLE_TRANSFERRED_OK: return; default: // SERVICE_DISCONTINUED // ARTICLE_TRANSFER_FAILED // TRANSFER_PERMISSION_DENIED // COMMAND_NOT_RECOGNIZED throw new NNTPException(response); } } // RFC2980:1.4 The XREPLIC command // TODO // RFC2980:2.1.2 The LIST ACTIVE command /** * Returns an iterator over the groups specified according to the wildmat * pattern. The iterator must be read fully before other commands are * issued. * @param wildmat the wildmat pattern. If null, returns all groups. If no * groups are matched, returns an empty iterator. */ public GroupIterator listActive(String wildmat) throws IOException { StringBuffer buffer = new StringBuffer(LIST_ACTIVE); if (wildmat != null) { buffer.append(' '); buffer.append(wildmat); } return listImpl(buffer.toString()); } // RFC2980:2.1.3 The LIST ACTIVE.TIMES command /** * Returns an iterator over the active.times file. * Each ActiveTime object returned provides details of who created the * newsgroup and when. */ public ActiveTimesIterator listActiveTimes() throws IOException { send(LIST_ACTIVE_TIMES); StatusResponse response = parseResponse(read()); switch (response.status) { case LIST_FOLLOWS: return new ActiveTimesIterator(this); default: throw new NNTPException(response); } } // RFC2980:2.1.4 The LIST DISTRIBUTIONS command // TODO // RFC2980:2.1.5 The LIST DISTRIB.PATS command // TODO // RFC2980:2.1.6 The LIST NEWSGROUPS command /** * Returns an iterator over the group descriptions for the given groups. * @param wildmat if non-null, limits the groups in the iterator to the * specified pattern * @return an iterator over group name/description pairs * @see #xgtitle */ public PairIterator listNewsgroups(String wildmat) throws IOException { StringBuffer buffer = new StringBuffer(LIST_NEWSGROUPS); if (wildmat != null) { buffer.append(' '); buffer.append(wildmat); } send(buffer.toString()); StatusResponse response = parseResponse(read()); switch (response.status) { case LIST_FOLLOWS: PairIterator pi = new PairIterator(this); pendingData = pi; return pi; default: throw new NNTPException(response); } } // RFC2980:2.1.7 The LIST OVERVIEW.FMT command /** * Returns an iterator over the order in which headers are stored in the * overview database. * Each line returned by the iterator contains one header field. * @see #xover */ public LineIterator listOverviewFmt() throws IOException { send(LIST_OVERVIEW_FMT); StatusResponse response = parseResponse(read()); switch (response.status) { case LIST_FOLLOWS: LineIterator li = new LineIterator(this); pendingData = li; return li; default: throw new NNTPException(response); } } // RFC2980:2.1.8 The LIST SUBSCRIPTIONS command /** * Returns a list of newsgroups suitable for new users of the server. */ public GroupIterator listSubscriptions() throws IOException { return listImpl(LIST_SUBSCRIPTIONS); } // RFC2980:2.2 The LISTGROUP command /** * Returns a listing of all the article numbers in the specified * newsgroup. If the <code>group</code> parameter is null, the currently * selected group is assumed. * @param group the name of the group to list articles for */ public ArticleNumberIterator listGroup(String group) throws IOException { StringBuffer buffer = new StringBuffer(LISTGROUP); if (group != null) { buffer.append(' '); buffer.append(group); } send(buffer.toString()); StatusResponse response = parseResponse(read(), true); switch (response.status) { case GROUP_SELECTED: ArticleNumberIterator ani = new ArticleNumberIterator(this); pendingData = ani; return ani; default: throw new NNTPException(response); } } // RFC2980:2.3 The MODE READER command /** * Indicates to the server that this is a user-agent. * @return true if posting is allowed, false otherwise. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -