in src/main/java/org/apache/commons/net/ftp/FTP.java [619:669]
private int getReply(final boolean reportReply) throws IOException {
final int length;
_newReplyString = true;
_replyLines.clear();
String line = _controlInput_.readLine();
if (line == null) {
throw new FTPConnectionClosedException("Connection closed without indication.");
}
// In case we run into an anomaly we don't want fatal index exceptions
// to be thrown.
length = line.length();
if (length < REPLY_CODE_LEN) {
throw new MalformedServerReplyException("Truncated server reply: " + line);
}
final String code;
try {
code = line.substring(0, REPLY_CODE_LEN);
_replyCode = Integer.parseInt(code);
} catch (final NumberFormatException e) {
throw new MalformedServerReplyException("Could not parse response code.\nServer Reply: " + line);
}
_replyLines.add(line);
// Check the server reply type
if (length > REPLY_CODE_LEN) {
final char sep = line.charAt(REPLY_CODE_LEN);
// Get extra lines if message continues.
if (sep == '-') {
do {
line = _controlInput_.readLine();
if (line == null) {
throw new FTPConnectionClosedException("Connection closed without indication.");
}
_replyLines.add(line);
// The length() check handles problems that could arise from readLine()
// returning too soon after encountering a naked CR or some other
// anomaly.
} while (isStrictMultilineParsing() ? strictCheck(line, code) : lenientCheck(line));
} else if (isStrictReplyParsing() && sep != SP) {
throw new MalformedServerReplyException("Invalid server reply: '" + line + "'");
}
} else if (isStrictReplyParsing()) {
throw new MalformedServerReplyException("Truncated server reply: '" + line + "'");
}
if (reportReply) {
fireReplyReceived(_replyCode, getReplyString());
}
if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE) {
throw new FTPConnectionClosedException("FTP response 421 received. Server closed connection.");
}
return _replyCode;
}