/** * * @param _reader the reader to wrap * @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); } }
/** * Reads the next characters from the message into an array and * returns the number of characters read. Returns -1 if the end of the * message has been reached. * @param buffer The character array in which to store the characters. * @return The number of characters read. Returns -1 if the * end of the message has been reached. * @throws IOException If an error occurs in reading the underlying * stream. */ @Override public int read(char[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
atBeginning = false; if (chint == DOT) { // Have DOT mark(2); // need to check for CR LF or DOT chint = super.read(); if (chint == -1) { // Should not happen if (chint == -1) { // Still only DOT CR - should not happen reset(); // So CR is picked up next time return DOT; // return the trailing DOT reset(); return DOT;
/** * 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 on error */ 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()]); }
/** * Closes the message for reading. This doesn't actually close the * underlying stream. The underlying stream may still be used for * communicating with the server and therefore is not closed. * <p> * If the end of the message has not yet been reached, this method * will read the remainder of the message until it reaches the end, * so that the underlying stream may continue to be used properly * for communicating with the server. If you do not fully read * a message, you MUST close it, otherwise your program will likely * hang or behave improperly. * @throws IOException If an error occurs while reading the * underlying stream. */ @Override public void close() throws IOException { synchronized (lock) { if (!eof) { while (read() != -1) { // read to EOF } } eof = true; atBeginning = false; } }
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; 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; }
/*** * List the command help from the server. * <p> * @return The sever help information. * @throws 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. * @throws IOException If an I/O error occurs while either sending a * command to the server or receiving a reply from the server. ***/ 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(); }
/** * Read a line of text. * A line is considered to be terminated by carriage return followed immediately by a linefeed. * This contrasts with BufferedReader which also allows other combinations. * @since 3.0 */ @Override public String readLine() throws IOException { StringBuilder sb = new StringBuilder(); int intch; synchronized(lock) { // make thread-safe (hopefully!) while((intch = read()) != -1) { if (intch == LF && atBeginning) { return sb.substring(0, sb.length()-1); } sb.append((char) intch); } } String string = sb.toString(); if (string.length() == 0) { // immediate EOF return null; } // Should not happen - EOF without CRLF //new Throwable(string).printStackTrace(); return string; } }
/*** * Private implementation of XOVER functionality. * * See {@link NNTP#xover} * for legal agument formats. Alternatively, read RFC 2980 :-) * <p> * @param articleRange * @return Returns a DotTerminatedMessageReader if successful, null * otherwise * @throws IOException */ private BufferedReader __retrieveArticleInfo(String articleRange) throws IOException { if (!NNTPReply.isPositiveCompletion(xover(articleRange))) { return null; } return new DotTerminatedMessageReader(_reader_); }
/** * Reads the next characters from the message into an array and * returns the number of characters read. Returns -1 if the end of the * message has been reached. * @param buffer The character array in which to store the characters. * @return The number of characters read. Returns -1 if the * end of the message has been reached. * @exception IOException If an error occurs in reading the underlying * stream. */ public int read(char[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
/*** * Private implementation of XHDR functionality. * * See {@link NNTP#xhdr} * for legal agument formats. Alternatively, read RFC 1036. * <p> * @param header * @param articleRange * @return Returns a DotTerminatedMessageReader if successful, null * otherwise * @throws IOException */ private BufferedReader __retrieveHeader(String header, String articleRange) throws IOException { if (!NNTPReply.isPositiveCompletion(xhdr(header, articleRange))) { return null; } return new DotTerminatedMessageReader(_reader_); }
/** * Reads the next characters from the message into an array and * returns the number of characters read. Returns -1 if the end of the * message has been reached. * @param buffer The character array in which to store the characters. * @return The number of characters read. Returns -1 if the * end of the message has been reached. * @exception IOException If an error occurs in reading the underlying * stream. */ @Override public int read(char[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
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); } return new DotTerminatedMessageReader(_reader_); }
return new DotTerminatedMessageReader(_reader);
return new DotTerminatedMessageReader(_reader);
BufferedReader reader = new DotTerminatedMessageReader(_reader_);