|
Secure iNet Factory | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jscape.inet.nntp.Nntp
public class Nntp
Implements the basic functionality of a NNTP client.
Example Usage:
Nntp nntp = new Nntp(); nntp.setHostname("news.myserver.com"); nntp.setUsername("jsmith"); nntp.setPassword("secret"); try { nntp.connect(); nntp.setNewsgroup("comp.lang.java.programmer"); // get all headers and print out subject Enumeration headers = nntp.getArticleHeaders(); while(headers.hasMoreElements()) { NntpArticleHeader header = (NntpArticleHeader)headers.nextElement(); System.out.println(header.getSubject()); } // disconnect nntp.disconnect(); } catch(Exception e) { System.out.println(e); }
Field Summary | |
---|---|
static int |
CMD_ARTICLE
Command to get article. |
static int |
CMD_AUTHPASS
Command to send password. |
static int |
CMD_AUTHUSER
Command to send username. |
static int |
CMD_BODY
Command to get body of article. |
static int |
CMD_GROUP
Command to select a newsgroup. |
static int |
CMD_HEAD
Command to get header of article. |
static int |
CMD_HELP
Command to get NNTP help. |
static int |
CMD_LAST
Command to get previous article. |
static int |
CMD_LIST
Command to list newsgroups. |
static int |
CMD_NEWGROUPS
Command to get new newsgroups. |
static int |
CMD_NEWNEWS
Command to get new articles. |
static int |
CMD_NEXT
Command to get next article. |
static int |
CMD_POST
Command to post article. |
static int |
CMD_QUIT
Command to logout. |
static int |
CMD_STAT
Command to get information about an article. |
static int |
MODE
Command to indicate to NNTP server that this is a NNTP reader. |
static int |
RESPONSE_ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS
Response code article list by message-id follows. |
static int |
RESPONSE_ARTICLE_NOT_WANTED
Response code article not wanted. |
static int |
RESPONSE_ARTICLE_POSTED_OK
Response code article posted. |
static int |
RESPONSE_ARTICLE_REJECTED
Response code article rejected. |
static int |
RESPONSE_ARTICLE_RETRIEVED_BODY_FOLLOWS
Response code article retrieved body follows. |
static int |
RESPONSE_ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW
Response code article retrieved head and body follows. |
static int |
RESPONSE_ARTICLE_RETRIEVED_HEAD_FOLLOWS
Response code article retrieved head follows. |
static int |
RESPONSE_ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY
Response code article retrieved request text separately. |
static int |
RESPONSE_ARTICLE_TRANSFERRED_OK
Response code article transferred. |
static int |
RESPONSE_AUTH_FAILED
Response code authentication failed. |
static int |
RESPONSE_AUTH_FAILED_OLD
Response code authentication failed. |
static int |
RESPONSE_AUTH_FAILED_OLD2
Response code authentication failed. |
static int |
RESPONSE_AUTH_OK
Response code authentication passed. |
static int |
RESPONSE_AUTH_OK_OLD
Response code authentication passed. |
static int |
RESPONSE_CLOSING_CONNECTION
Response code closing connection. |
static int |
RESPONSE_COMMAND_NOT_RECOGNIZED
Response code command not recognized. |
static int |
RESPONSE_COMMAND_SYNTAX_ERROR
Response code syntax error. |
static int |
RESPONSE_CONTINUE_AUTH
Response code continue authentication. |
static int |
RESPONSE_DEBUG
Response for help. |
static int |
RESPONSE_GROUP_SELECTED
Response code group selected. |
static int |
RESPONSE_HELP
Response for help. |
static int |
RESPONSE_NEW_NEWSGROUP_LIST_FOLLOWS
Response code newsgroup list follows. |
static int |
RESPONSE_NO_CURRENT_ARTICLE_SELECTED
Response code no current article selected. |
static int |
RESPONSE_NO_NEWSGROUP_SELECTED
Response code no newsgroup selected. |
static int |
RESPONSE_NO_NEXT_ARTICLE
Response code no next article. |
static int |
RESPONSE_NO_PREVIOUS_ARTICLE
Response code no previous article. |
static int |
RESPONSE_NO_SUCH_ARTICLE_FOUND
Response code article not found. |
static int |
RESPONSE_NO_SUCH_ARTICLE_NUMBER
Response code no such article number. |
static int |
RESPONSE_NO_SUCH_NEWSGROUP
Response code no such newsgroup. |
static int |
RESPONSE_OK_POSTING_ALLOWED
Response to indicate posting to NNTP server allowed. |
static int |
RESPONSE_OK_POSTING_NOT_ALLOWED
Response to indicate posting to NNTP server not allowed. |
static int |
RESPONSE_PERMISSION_DENIED
Response code permission denied. |
static int |
RESPONSE_POSTING_FAILED
Response code posting failed. |
static int |
RESPONSE_POSTING_NOT_ALLOWED
Response code posting not allowed. |
static int |
RESPONSE_POSTING_REJECTED
Response code post rejected. |
static int |
RESPONSE_POSTING_REJECTED_OLD
Response code post rejected. |
static int |
RESPONSE_PROGRAM_FAULT
Response code server error. |
static int |
RESPONSE_SEND_ARTICLE_TO_POST
Response code send article to post. |
static int |
RESPONSE_SEND_ARTICLE_TO_TRANSFER
Response code send article to transfer. |
static int |
RESPONSE_SERVICE_DISCONTINUED
Response code service temporarily unavailable. |
static int |
RESPONSE_SLAVE_NOTED
Response to indicate that slave status is noted. |
static int |
RESPONSE_TRANSFER_FAILED
Response code transfer failed. |
static int |
SCMD_IHAVE
Command to indicate to NNTP server that client has an article. |
static int |
SCMD_SLAVE
Command to indicate to NNTP server that this client connection is to a slave server rather than a user. |
static int |
XOVER
Command to get a set of articles from NNTP server. |
Constructor Summary | |
---|---|
Nntp()
Constructs new Nntp instance. |
|
Nntp(java.lang.String hostname)
Constructs Nntp instance with specified server name. |
|
Nntp(java.lang.String hostname,
java.lang.String username,
java.lang.String password)
Constructs Nntp instance with specified server name, port
and username / password for authentication. |
Method Summary | |
---|---|
void |
addNntpListener(NntpListener listener)
Adds Nntp event listener. |
void |
clearProxySettings()
Clears proxy server values. |
void |
connect()
Connects to NNTP server and authenticates using username and password if found. |
void |
disconnect()
Disconnects from NNTP server. |
NntpArticle |
getArticle(int articleId)
Gets an article from current newsgroup. |
NntpArticle |
getArticle(java.lang.String messageID)
Gets an article from current newsgroup based on its Message-ID header. |
NntpArticleHeader |
getArticleHeader(int articleId)
Gets article header from current newsgroup. |
java.util.Enumeration |
getArticleHeaders()
Gets all article headers from current newsgroup. |
java.util.Enumeration |
getArticleHeaders(java.util.Date date)
Gets all article headers for current active newsgroup since a specified date. |
java.util.Enumeration |
getArticleHeaders(int start,
int end)
Gets all article headers from NNTP server within a specific range using the XOVER command. |
java.util.Enumeration |
getArticleHeaders(java.lang.String group)
Gets all article headers for a newsgroup. |
java.util.Enumeration |
getArticleHeaders(java.lang.String[] groups,
java.util.Date date)
Gets article headers since a certain date in specified newsgroups. |
NntpNewsgroup |
getCurrentNewsgroup()
Gets the currently active newsgroup. |
boolean |
getDebug()
Get debugging state. |
java.io.PrintStream |
getDebugStream()
Gets PrintStream used in reporting debug statements. |
java.lang.String |
getHostname()
Gets hostname of NNTP server. |
NntpNewsgroup |
getNewsgroup(java.lang.String group)
Creates NntpNewsgroup from server response to GROUP command.Posting permission is not available in response to this command and it will be assigned to true. |
java.util.Enumeration |
getNewsgroups()
Gets all newsgroups from NNTP server. |
java.util.Enumeration |
getNewsgroups(java.util.Date date)
Gets new newgroups from NNTP server since a specified date. |
NntpArticle |
getNextArticle()
Gets next article from current newsgroup. |
NntpArticleHeader |
getNextHeader()
Gets next article header from newsgroup. |
int |
getPort()
Gets port of NNTP server. |
NntpArticle |
getPreviousArticle()
Gets previous article from current newsgroup. |
NntpArticleHeader |
getPreviousHeader()
Gets previous article header from current newsgroup. |
java.lang.String |
getProxyHost()
Gets the hostname of the proxy server to be used in Nntp communications. |
int |
getProxyPort()
Gets the port to be used when communicating with an Nntp proxy server. |
java.lang.String |
getResponseString()
Gets reponse from last NNTP command. |
java.util.Enumeration |
getResponseStrings()
Gets history of all NNTP responses for this session. |
int |
getTimeout()
Gets the timeout used when opening a NNTP server connection. |
java.lang.String |
getUsername()
Gets username currently used for authentication. |
java.lang.String |
issueCommand(java.lang.String command)
Sends command to NNTP server. |
void |
postArticle(NntpArticle article)
Posts an article to NNTP server. |
void |
removeNntpListener(NntpListener listener)
Removes specified Nntp event listener. |
void |
setDebug(boolean debug)
Set debugging state. |
void |
setDebugStream(java.io.PrintStream debugStream)
Sets PrintStream used in reporting debug statements. |
void |
setHostname(java.lang.String hostname)
Sets hostname of NNTP server. |
void |
setNewsgroup(NntpNewsgroup group)
Sets current active newsgroup. |
void |
setNewsgroup(java.lang.String group)
Sets current active newsgroup. |
void |
setPassword(java.lang.String password)
Sets password for authentication. |
void |
setPort(int port)
Sets port of NNTP server. |
void |
setProxyAuthentication(java.lang.String proxyUsername,
java.lang.String proxyPassword)
Sets the username and password to use when for authentication with proxy server. |
void |
setProxyHost(java.lang.String proxyHost)
Sets the hostname of the proxy server to be used in Nntp communications. |
void |
setProxyHost(java.lang.String proxyHostname,
int proxyPort)
Sets the proxy hostname and port for this connection. |
void |
setProxyPort(int proxyPort)
Sets the port to be used when communicating with an Nntp proxy server. |
void |
setProxyType(java.lang.String proxyType)
Sets the proxy type will be used for this connection. |
void |
setTimeout(int timeout)
Sets the timeout for opening a NNTP server connection. |
void |
setUsername(java.lang.String username)
Sets username for authentication. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int CMD_AUTHUSER
public static final int CMD_AUTHPASS
public static final int CMD_LIST
public static final int CMD_NEWGROUPS
public static final int CMD_NEWNEWS
public static final int CMD_GROUP
public static final int CMD_HEAD
public static final int CMD_BODY
public static final int CMD_ARTICLE
public static final int CMD_STAT
public static final int CMD_NEXT
public static final int CMD_LAST
public static final int CMD_POST
public static final int CMD_QUIT
public static final int CMD_HELP
public static final int SCMD_IHAVE
public static final int SCMD_SLAVE
public static final int MODE
public static final int XOVER
public static final int RESPONSE_HELP
public static final int RESPONSE_DEBUG
public static final int RESPONSE_OK_POSTING_ALLOWED
public static final int RESPONSE_OK_POSTING_NOT_ALLOWED
public static final int RESPONSE_SLAVE_NOTED
public static final int RESPONSE_CLOSING_CONNECTION
public static final int RESPONSE_GROUP_SELECTED
public static final int RESPONSE_ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW
public static final int RESPONSE_ARTICLE_RETRIEVED_HEAD_FOLLOWS
public static final int RESPONSE_ARTICLE_RETRIEVED_BODY_FOLLOWS
public static final int RESPONSE_ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY
public static final int RESPONSE_ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS
public static final int RESPONSE_NEW_NEWSGROUP_LIST_FOLLOWS
public static final int RESPONSE_ARTICLE_TRANSFERRED_OK
public static final int RESPONSE_ARTICLE_POSTED_OK
public static final int RESPONSE_AUTH_OK
public static final int RESPONSE_AUTH_OK_OLD
public static final int RESPONSE_SEND_ARTICLE_TO_TRANSFER
public static final int RESPONSE_SEND_ARTICLE_TO_POST
public static final int RESPONSE_CONTINUE_AUTH
public static final int RESPONSE_AUTH_FAILED_OLD
public static final int RESPONSE_SERVICE_DISCONTINUED
public static final int RESPONSE_NO_SUCH_NEWSGROUP
public static final int RESPONSE_NO_NEWSGROUP_SELECTED
public static final int RESPONSE_NO_CURRENT_ARTICLE_SELECTED
public static final int RESPONSE_NO_NEXT_ARTICLE
public static final int RESPONSE_NO_PREVIOUS_ARTICLE
public static final int RESPONSE_NO_SUCH_ARTICLE_NUMBER
public static final int RESPONSE_NO_SUCH_ARTICLE_FOUND
public static final int RESPONSE_ARTICLE_NOT_WANTED
public static final int RESPONSE_TRANSFER_FAILED
public static final int RESPONSE_ARTICLE_REJECTED
public static final int RESPONSE_POSTING_NOT_ALLOWED
public static final int RESPONSE_POSTING_FAILED
public static final int RESPONSE_AUTH_FAILED
public static final int RESPONSE_POSTING_REJECTED
public static final int RESPONSE_AUTH_FAILED_OLD2
public static final int RESPONSE_POSTING_REJECTED_OLD
public static final int RESPONSE_COMMAND_NOT_RECOGNIZED
public static final int RESPONSE_COMMAND_SYNTAX_ERROR
public static final int RESPONSE_PERMISSION_DENIED
public static final int RESPONSE_PROGRAM_FAULT
Constructor Detail |
---|
public Nntp()
Nntp
instance.
public Nntp(java.lang.String hostname, java.lang.String username, java.lang.String password)
Nntp
instance with specified server name, port
and username / password for authentication.
hostname
- the hostname of NNTP serverusername
- the username of NNTP userpassword
- the password of NNTP userpublic Nntp(java.lang.String hostname)
Nntp
instance with specified server name.
hostname
- the hostname of NNTP serverMethod Detail |
---|
public java.lang.String getResponseString()
public java.util.Enumeration getResponseStrings()
public void connect() throws NntpException
NntpException
- thrown for I/O or NNTP related errorspublic void disconnect()
public void setHostname(java.lang.String hostname)
hostname
- the hostname of NNTP serverpublic java.lang.String getHostname()
public void setPort(int port)
port
- the port of NNTP serverpublic int getPort()
public java.util.Enumeration getNewsgroups() throws NntpException
NntpNewsgroup
NntpException
- thrown for I/O or NNTP related errorspublic java.util.Enumeration getNewsgroups(java.util.Date date) throws NntpException
date
- the start Date
used to find new newsgroups
NntpNewsgroup
NntpException
- thrown for I/O or Nntp related errorspublic NntpNewsgroup getCurrentNewsgroup()
NntpNewsgroup
public NntpNewsgroup getNewsgroup(java.lang.String group) throws NntpException
NntpNewsgroup
from server response to GROUP command.
group
- the newsgroup to retrieve
NntpNewsgroup
NntpException
- thrown for I/O or Nntp related errorspublic void setNewsgroup(NntpNewsgroup group) throws NntpException
group
- the name of newsgroup
NntpException
- thrown for I/O or Nntp related errorspublic void setNewsgroup(java.lang.String group) throws NntpException
group
- the name of newsgroup
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticleHeader getNextHeader() throws NntpException
NntpArticleHeader
or null
if not
available
NntpException
- thrown for I/O or Nntp related errorspublic java.util.Enumeration getArticleHeaders(int start, int end) throws NntpException
start
- the start articleend
- the end article
NntpException
- if an error occurspublic java.util.Enumeration getArticleHeaders() throws NntpException
Enumeration
of NntpArticleHeader
NntpException
- thrown for I/O or Nntp related errorspublic java.util.Enumeration getArticleHeaders(java.lang.String group) throws NntpException
group
- the name of newsgroup
Enumeration
of NntpArticleHeader
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticleHeader getArticleHeader(int articleId) throws NntpException
articleId
- the article id to retrieve
NntpArticleHeader
or null
if not
available
NntpException
- thrown for I/O or Nntp related errorspublic java.util.Enumeration getArticleHeaders(java.util.Date date) throws NntpException
NntpArticleHeaderEvent
is generated for each new header.
date
- the start Date
used to find new article headers
Enumeration
of NntpArticleHeader
NntpException
- thrown for I/O or Nntp related errorspublic java.util.Enumeration getArticleHeaders(java.lang.String[] groups, java.util.Date date) throws NntpException
groups
- the groups to retrievedate
- the start date to retrieve articles
Enumeration
of NntpArticleHeader
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticle getArticle(int articleId) throws NntpException
articleId
- the index based id of article
NntpArticle
or null if not available
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticle getArticle(java.lang.String messageID) throws NntpException
NntpArticleHeader
.
messageID
- the unique message id for article
NntpArticle
or null if not found
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticle getNextArticle() throws NntpException
NntpArticle
or null
if not found
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticle getPreviousArticle() throws NntpException
NntpArticle
or null
if not found
NntpException
- thrown for I/O or Nntp related errorspublic NntpArticleHeader getPreviousHeader() throws NntpException
NntpArticleHeader
or null
if not
found
NntpException
- thrown for I/O or Nntp related errorspublic void postArticle(NntpArticle article) throws NntpException
article
- the NntpArticle
to post
NntpException
- thrown for I/O or Nntp related errorspublic void setUsername(java.lang.String username)
username
- the username of Nntp userpublic java.lang.String getUsername()
public void setPassword(java.lang.String password)
password
- the password of NNTP userpublic void setProxyHost(java.lang.String proxyHost)
proxyHost
- the hostname or ipaddress of the proxy serverpublic java.lang.String getProxyHost()
public void setProxyPort(int proxyPort)
proxyPort
- port of listening Nntp proxy serverpublic int getProxyPort()
public void setProxyAuthentication(java.lang.String proxyUsername, java.lang.String proxyPassword)
#clearProxySettings
method.
proxyUsername
- the proxy usernameproxyPassword
- the proxy passwordclearProxySettings()
public void setProxyHost(java.lang.String proxyHostname, int proxyPort)
#clearProxySettings
method.
proxyHostname
- the hostname or ip address of the proxy serverproxyPort
- the port of the proxy serverclearProxySettings()
public void setProxyType(java.lang.String proxyType)
proxyType
- The proxy type. Valid values: HTTP, SOCKS5public void clearProxySettings()
public void addNntpListener(NntpListener listener)
listener
- a NntpListener
NntpListener
public void removeNntpListener(NntpListener listener)
listener
- the listener to removeNntpListener
public void setTimeout(int timeout)
timeout
- in millisecondspublic int getTimeout()
public java.lang.String issueCommand(java.lang.String command) throws NntpException
command
- the command to send
NntpException
- if an I/O or NNTP related error occurspublic void setDebug(boolean debug)
debug
- true
turns debugging onpublic boolean getDebug()
true
if debugging is onpublic java.io.PrintStream getDebugStream()
PrintStream
public void setDebugStream(java.io.PrintStream debugStream)
debugStream
- the PrintStream to send debug statements toPrintStream
|
Secure iNet Factory | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |