List of usage examples for org.apache.commons.net MalformedServerReplyException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:nl.nn.adapterframework.ftp.FTPsClient.java
private Object _readReply(InputStream in, boolean concatenateLines) throws IOException { // obtain the result BufferedReader reader = new BufferedReader(new InputStreamReader(in, "ISO-8859-1")); int replyCode = 0; StringBuffer reply = new StringBuffer(); List replyList = new ArrayList(); String line = reader.readLine(); if (line == null) throw new FTPConnectionClosedException("Connection closed without indication."); reply.append(line).append("\n"); replyList.add(line);/* w w w . ja v a2s . co m*/ // In case we run into an anomaly we don't want fatal index exceptions // to be thrown. int length = line.length(); if (length < 3) throw new MalformedServerReplyException("Truncated server reply: " + line); try { String code = line.substring(0, 3); replyCode = Integer.parseInt(code); } catch (NumberFormatException e) { MalformedServerReplyException mfre = new MalformedServerReplyException( "Could not parse response code.\nServer Reply [" + line + "]"); mfre.initCause(e); throw mfre; } // Get extra lines if message continues. if (length > 3 && line.charAt(3) == '-') { do { line = reader.readLine(); if (line == null) throw new FTPConnectionClosedException( "Connection closed without indication after having read [" + reply.toString() + "]"); reply.append(line).append("\n"); replyList.add(line); } while (!(line.length() >= 4 && line.charAt(3) != '-' && Character.isDigit(line.charAt(0)))); } if (replyCode == FTPReply.SERVICE_NOT_AVAILABLE) throw new FTPConnectionClosedException("FTP response 421 received. Server closed connection."); if (!FTPReply.isPositiveCompletion(replyCode)) throw new IOException("Exception while sending command \n" + reply.toString()); log.debug("_readReply [" + reply.toString() + "]"); if (concatenateLines) { return reply.toString(); } return (String[]) replyList.toArray(new String[0]); }