public class NNTPConnection extends Object implements NNTPConstants
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
canPost
Whether the host permits posting of articles.
|
static int |
DEFAULT_PORT
The default NNTP port.
|
protected String |
hostname
The hostname of the host we are connected to.
|
protected LineInputStream |
in
The socket input stream.
|
static Logger |
logger
The logger used for NNTP protocol traces.
|
static Level |
NNTP_TRACE
The network trace level.
|
protected CRLFOutputStream |
out
The socket output stream.
|
protected PendingData |
pendingData
Pending data, if any.
|
protected int |
port
The port on the host we are connected to.
|
protected Socket |
socket
The socket used for network communication.
|
protected String |
welcome
The greeting issued by the host when we connected.
|
ARTICLE, ARTICLE_FOLLOWS, ARTICLE_NOT_WANTED, ARTICLE_NOT_WANTED_VIA_TAKETHIS, ARTICLE_POSTED, ARTICLE_REJECTED, ARTICLE_RETRIEVED, ARTICLE_TRANSFER_FAILED, ARTICLE_TRANSFERRED, ARTICLE_TRANSFERRED_OK, AUTHINFO_GENERIC, AUTHINFO_OK, AUTHINFO_PASS, AUTHINFO_REJECTED, AUTHINFO_SIMPLE, AUTHINFO_SIMPLE_DENIED, AUTHINFO_SIMPLE_OK, AUTHINFO_SIMPLE_REQUIRED, AUTHINFO_USER, BODY, BODY_FOLLOWS, CHECK, CLOSING_CONNECTION, COMMAND_NOT_RECOGNIZED, DATE, DATE_OK, GROUP, GROUP_SELECTED, HEAD, HEAD_FOLLOWS, HELP, HELP_TEXT, IHAVE, INTERNAL_ERROR, LAST, LIST, LIST_ACTIVE, LIST_ACTIVE_TIMES, LIST_DISTRIB_PATS, LIST_DISTRIBUTIONS, LIST_FOLLOWS, LIST_NEWSGROUPS, LIST_OVERVIEW_FMT, LIST_SUBSCRIPTIONS, LISTGROUP, MODE_READER, MODE_STREAM, NEWGROUPS, NEWGROUPS_LIST_FOLLOWS, NEWNEWS, NEWNEWS_LIST_FOLLOWS, NEXT, NO_ARTICLE_SELECTED, NO_GROUP_SELECTED, NO_NEXT_ARTICLE, NO_POSTING_ALLOWED, NO_PREVIOUS_ARTICLE, NO_SUCH_ARTICLE, NO_SUCH_ARTICLE_NUMBER, NO_SUCH_GROUP, OVERVIEW_FOLLOWS, PERMISSION_DENIED, POST, POSTING_ALLOWED, POSTING_FAILED, POSTING_NOT_ALLOWED, QUIT, SEND_ARTICLE, SEND_ARTICLE_VIA_TAKETHIS, SEND_AUTHINFO_SIMPLE, SEND_AUTHINFOPASS, SEND_TRANSFER_ARTICLE, SERVICE_DISCONTINUED, SLAVE, SLAVE_ACKNOWLEDGED, STAT, STREAMING_OK, SYNTAX_ERROR, TAKETHIS, TRANSFER_FAILED, TRANSFER_PERMISSION_DENIED, TRY_AGAIN_LATER, XGTITLE, XGTITLE_LIST_FOLLOWS, XHDR, XINDEX, XOVER, XPAT, XPATH, XREPLIC, XROVER| Constructor and Description |
|---|
NNTPConnection(String hostname)
Creates a new connection object.
|
NNTPConnection(String hostname,
int port)
Creates a new connection object.
|
NNTPConnection(String hostname,
int port,
int connectionTimeout,
int timeout)
Creates a new connection object.
|
| Modifier and Type | Method and Description |
|---|---|
ArticleResponse |
article(int articleNumber)
Send an article retrieval request to the server.
|
ArticleResponse |
article(String messageId)
Send an article retrieval request to the server.
|
protected ArticleResponse |
articleImpl(String command,
String messageId)
Performs an ARTICLE, BODY, HEAD, or STAT command.
|
boolean |
authinfo(String username,
String password)
Basic authentication strategy.
|
boolean |
authinfoGeneric(String mechanism,
String username,
String password)
Authenticates the connection using the specified SASL mechanism,
username and password.
|
boolean |
authinfoSimple(String username,
String password)
Implementation of NNTP simple authentication.
|
ArticleResponse |
body(int articleNumber)
Send an article body retrieval request to the server.
|
ArticleResponse |
body(String messageId)
Send an article body retrieval request to the server.
|
boolean |
check(String messageId) |
Date |
date()
Returns the date on the server.
|
String |
getWelcome()
Return the welcome message sent by the server in reply to the initial
connection.
|
GroupResponse |
group(String name)
Send a group selection command to the server.
|
ArticleResponse |
head(int articleNumber)
Send an article head retrieval request to the server.
|
ArticleResponse |
head(String messageId)
Send an article head retrieval request to the server.
|
LineIterator |
help()
Requests a help listing.
|
PostStream |
ihave(String messageId)
Sends an ihave command indicating that the client has an article with
the specified message-id.
|
ArticleResponse |
last()
Sends a previous article positioning command to the server.
|
GroupIterator |
list()
Send a group listing command to the server.
|
GroupIterator |
listActive(String wildmat)
Returns an iterator over the groups specified according to the wildmat
pattern.
|
ActiveTimesIterator |
listActiveTimes()
Returns an iterator over the active.times file.
|
ArticleNumberIterator |
listGroup(String group)
Returns a listing of all the article numbers in the specified
newsgroup.
|
PairIterator |
listNewsgroups(String wildmat)
Returns an iterator over the group descriptions for the given groups.
|
LineIterator |
listOverviewFmt()
Returns an iterator over the order in which headers are stored in the
overview database.
|
GroupIterator |
listSubscriptions()
Returns a list of newsgroups suitable for new users of the server.
|
boolean |
modeReader()
Indicates to the server that this is a user-agent.
|
boolean |
modeStream()
Attempt to initialise the connection in streaming mode.
|
LineIterator |
newGroups(Date since,
String[] distributions)
Returns an iterator over the list of new groups on the server since the
specified date.
|
LineIterator |
newNews(String newsgroup,
Date since,
String[] distributions)
Returns an iterator over the list of message-ids posted or received to
the specified newsgroup(s) since the specified date.
|
ArticleResponse |
next()
Sends a next article positioning command to the server.
|
protected StatusResponse |
parseResponse(String line)
Parse a response object from a response line sent by the server.
|
protected StatusResponse |
parseResponse(String line,
boolean isListGroup)
Parse a response object from a response line sent by the server.
|
OutputStream |
post()
Post an article.
|
void |
quit()
Close the connection.
|
protected String |
read()
Read a single line from the server.
|
protected void |
send(String line)
Send a single line to the server.
|
void |
slave()
Indicates to the server that this is a slave connection.
|
ArticleResponse |
stat(int articleNumber)
Send an article status request to the server.
|
ArticleResponse |
stat(String messageId)
Send an article status request to the server.
|
OutputStream |
takethis(String messageId)
Implements the out-of-order takethis command.
|
PairIterator |
xgtitle(String wildmat)
Returns an iterator over the list of newsgroup descriptions.
|
HeaderIterator |
xhdr(String header,
String range) |
OverviewIterator |
xover(Range range) |
public static final Logger logger
public static final Level NNTP_TRACE
public static final int DEFAULT_PORT
protected String hostname
protected int port
protected Socket socket
protected LineInputStream in
protected CRLFOutputStream out
protected boolean canPost
protected String welcome
protected PendingData pendingData
public NNTPConnection(String hostname) throws IOException
hostname - the hostname or IP address of the news serverIOExceptionpublic NNTPConnection(String hostname, int port) throws IOException
hostname - the hostname or IP address of the news serverport - the port to connect toIOExceptionpublic NNTPConnection(String hostname, int port, int connectionTimeout, int timeout) throws IOException
hostname - the hostname or IP address of the news serverport - the port to connect toconnectionTimeout - the socket connection timeouttimeout - the read timeout on the socketIOExceptionpublic String getWelcome()
public ArticleResponse article(int articleNumber) throws IOException
articleNumber - the article number of the article to retrieveIOExceptionpublic ArticleResponse article(String messageId) throws IOException
messageId - the message-id of the article to retrieveIOExceptionpublic ArticleResponse head(int articleNumber) throws IOException
articleNumber - the article number of the article to headIOExceptionpublic ArticleResponse head(String messageId) throws IOException
messageId - the message-id of the article to headIOExceptionpublic ArticleResponse body(int articleNumber) throws IOException
articleNumber - the article number of the article to bodyIOExceptionpublic ArticleResponse body(String messageId) throws IOException
messageId - the message-id of the article to bodyIOExceptionpublic ArticleResponse stat(int articleNumber) throws IOException
articleNumber - the article number of the article to statIOExceptionpublic ArticleResponse stat(String messageId) throws IOException
messageId - the message-id of the article to statIOExceptionprotected ArticleResponse articleImpl(String command, String messageId) throws IOException
command - one of the above commandsmessageId - the article-number or message-id in string formIOExceptionpublic GroupResponse group(String name) throws IOException
name - the name of the group to selectIOExceptionpublic LineIterator help() throws IOException
IOExceptionpublic PostStream ihave(String messageId) throws IOException
messageId - the article message-idIOExceptionpublic ArticleResponse last() throws IOException
IOExceptionpublic GroupIterator list() throws IOException
IOExceptionpublic LineIterator newGroups(Date since, String[] distributions) throws IOException
since - the date from which to list new groupsdistributions - if non-null, an array of distributions to matchIOExceptionpublic LineIterator newNews(String newsgroup, Date since, String[] distributions) throws IOException
newsgroup - the newsgroup wildmatsince - the date from which to list new articlesdistributions - if non-null, a list of distributions to matchIOExceptionpublic ArticleResponse next() throws IOException
IOExceptionpublic OutputStream post() throws IOException
write() on the stream for all the
bytes of the article, and finally call close()
on the stream.
No other method should be called in between.IOExceptionpostComplete()public void quit()
throws IOException
IOExceptionpublic void slave()
throws IOException
IOExceptionpublic boolean check(String messageId) throws IOException
IOExceptionpublic boolean modeStream()
throws IOException
IOExceptionpublic OutputStream takethis(String messageId) throws IOException
close() on the
stream.IOExceptiontakethisComplete()public GroupIterator listActive(String wildmat) throws IOException
wildmat - the wildmat pattern. If null, returns all groups. If no
groups are matched, returns an empty iterator.IOExceptionpublic ActiveTimesIterator listActiveTimes() throws IOException
IOExceptionpublic PairIterator listNewsgroups(String wildmat) throws IOException
wildmat - if non-null, limits the groups in the iterator to the
specified patternIOExceptionxgtitle(java.lang.String)public LineIterator listOverviewFmt() throws IOException
IOExceptionxover(gnu.inet.nntp.Range)public GroupIterator listSubscriptions() throws IOException
IOExceptionpublic ArticleNumberIterator listGroup(String group) throws IOException
group parameter is null, the currently
selected group is assumed.group - the name of the group to list articles forIOExceptionpublic boolean modeReader()
throws IOException
IOExceptionpublic PairIterator xgtitle(String wildmat) throws IOException
wildmat - if non-null, the newsgroups to matchIOExceptionpublic HeaderIterator xhdr(String header, String range) throws IOException
IOExceptionpublic OverviewIterator xover(Range range) throws IOException
IOExceptionpublic boolean authinfo(String username, String password) throws IOException
username - the user to authenticatepassword - the(cleartext) passwordIOExceptionpublic boolean authinfoSimple(String username, String password) throws IOException
IOExceptionpublic boolean authinfoGeneric(String mechanism, String username, String password) throws IOException
mechanism - a SASL authentication mechanism, e.g. LOGIN, PLAIN,
CRAM-MD5, GSSAPIusername - the authentication principalpassword - the authentication credentialsIOExceptionpublic Date date() throws IOException
IOExceptionprotected StatusResponse parseResponse(String line) throws ProtocolException
ProtocolExceptionprotected StatusResponse parseResponse(String line, boolean isListGroup) throws ProtocolException
isListGroup - whether we are invoking the LISTGROUP commandProtocolExceptionprotected void send(String line) throws IOException
line - the line to sendIOExceptionprotected String read() throws IOException
IOExceptionCopyright © 2017. All rights reserved.