List of usage examples for org.apache.commons.net.io DotTerminatedMessageReader DotTerminatedMessageReader
public DotTerminatedMessageReader(Reader reader)
From source file:net.longfalcon.newsj.nntp.client.ReplyIterator.java
/** * * @param _reader the reader to wrap// w w w .j av a 2 s. c o m * @param addDotReader whether to additionally wrap the reader in a DotTerminatedMessageReader * @throws IOException */ ReplyIterator(BufferedReader _reader, boolean addDotReader) throws IOException { reader = addDotReader ? new DotTerminatedMessageReader(_reader) : _reader; line = reader.readLine(); // prime the iterator if (line == null) { Util.closeQuietly(reader); } }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
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); String line;/*from ww w .ja v a2 s. com*/ try { while ((line = reader.readLine()) != null) { NewsgroupInfo tmp = __parseNewsgroupListEntry(line); if (tmp != null) { list.addElement(tmp); } else { throw new MalformedServerReplyException(line); } } } finally { reader.close(); } int size; if ((size = list.size()) < 1) { return new NewsgroupInfo[0]; } NewsgroupInfo[] info = new NewsgroupInfo[size]; list.copyInto(info); return info; }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
private BufferedReader __retrieve(int command, String articleId, ArticleInfo pointer) throws IOException { if (articleId != null) { if (!NNTPReply.isPositiveCompletion(sendCommand(command, articleId))) { return null; }//from ww w . j a v a 2s . c o m } else { if (!NNTPReply.isPositiveCompletion(sendCommand(command))) { return null; } } if (pointer != null) { __parseArticlePointer(getReplyString(), pointer); } return new DotTerminatedMessageReader(_reader_); }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
private BufferedReader __retrieve(int command, long articleNumber, ArticleInfo pointer) throws IOException { if (!NNTPReply.isPositiveCompletion(sendCommand(command, Long.toString(articleNumber)))) { return null; }/* www . j a v a2s . c o m*/ if (pointer != null) { __parseArticlePointer(getReplyString(), pointer); } return new DotTerminatedMessageReader(_reader_); }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
/*** * List the command help from the server. * <p>/* ww w . j ava 2 s .c om*/ * @return The sever help information. * @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. ***/ @Override public String listHelp() throws IOException { if (!NNTPReply.isInformational(help())) { return null; } StringWriter help = new StringWriter(); BufferedReader reader = new DotTerminatedMessageReader(_reader_); Util.copyReader(reader, help); reader.close(); help.close(); return help.toString(); }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
/** * Send a "LIST OVERVIEW.FMT" command to the server. * * @return the contents of the Overview format, of {@code null} if the command failed * @throws IOException//from w w w . j a v a 2 s. c o m */ @Override public String[] listOverviewFmt() throws IOException { if (!NNTPReply.isPositiveCompletion(sendCommand("LIST", "OVERVIEW.FMT"))) { return null; } BufferedReader reader = new DotTerminatedMessageReader(_reader_); String line; ArrayList<String> list = new ArrayList<String>(); while ((line = reader.readLine()) != null) { list.add(line); } reader.close(); return list.toArray(new String[list.size()]); }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
/*** * List all new articles added to the NNTP server since a particular * date subject to the conditions of the specified query. If no new * new news is found, a zero length array will be returned. If the * command fails, null will be returned. You must add at least one * newsgroup to the query, else the command will fail. Each String * in the returned array is a unique message identifier including the * enclosing < and >.// w w w . ja v a2 s . c om * This uses the "NEWNEWS" command. * <p> * @param query The query restricting how to search for new news. You * must add at least one newsgroup to the query. * @return An array of String instances containing the unique message * identifiers for each new article added to the NNTP server. If no * new news is found, a zero length array will be returned. If the * command fails, null will be returned. * @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. * * @see #iterateNewNews(NewGroupsOrNewsQuery) ***/ @Override public String[] listNewNews(NewGroupsOrNewsQuery query) throws IOException { if (!NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(), query.isGMT(), query.getDistributions()))) { return null; } Vector<String> list = new Vector<String>(); BufferedReader reader = new DotTerminatedMessageReader(_reader_); String line; try { while ((line = reader.readLine()) != null) { list.addElement(line); } } finally { reader.close(); } int size = list.size(); if (size < 1) { return new String[0]; } String[] result = new String[size]; list.copyInto(result); return result; }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
/*** * Private implementation of XOVER functionality. * * See {@link NNTP#xover}/*w w w. jav a 2 s . com*/ * for legal agument formats. Alternatively, read RFC 2980 :-) * <p> * @param articleRange * @return Returns a DotTerminatedMessageReader if successful, null * otherwise * @exception IOException */ private BufferedReader __retrieveArticleInfo(String articleRange) throws IOException { if (!NNTPReply.isPositiveCompletion(xover(articleRange))) { return null; } return new DotTerminatedMessageReader(_reader_); }
From source file:net.longfalcon.newsj.nntp.client.CustomNNTPClient.java
/*** * Private implementation of XHDR functionality. * * See {@link NNTP#xhdr}/*from w ww.j ava 2s.c o m*/ * for legal agument formats. Alternatively, read RFC 1036. * <p> * @param header * @param articleRange * @return Returns a DotTerminatedMessageReader if successful, null * otherwise * @exception IOException */ private BufferedReader __retrieveHeader(String header, String articleRange) throws IOException { if (!NNTPReply.isPositiveCompletion(xhdr(header, articleRange))) { return null; } return new DotTerminatedMessageReader(_reader_); }
From source file:org.random_access.newsreader.nntp.CustomNNTPClient.java
private BufferedReader __retrieve(int command, String articleId, ArticleInfo pointer) throws IOException { if (articleId != null) { if (!NNTPReply.isPositiveCompletion(this.sendCommand(command, articleId))) { return null; }// w ww .j a v a 2 s. c o m } else if (!NNTPReply.isPositiveCompletion(this.sendCommand(command))) { return null; } if (pointer != null) { this.__parseArticlePointer(this.getReplyString(), pointer); } return new DotTerminatedMessageReader(this._reader_); }