org.opennms.netmgt.capsd.plugins
Class FtpResponse

java.lang.Object
  extended by org.opennms.netmgt.capsd.plugins.FtpResponse

public class FtpResponse
extends Object

Represents an FTP command response.

Version:
$Id: $
Author:
DJ Gregor

Constructor Summary
FtpResponse()
          Creates an empty FTP response.
FtpResponse(int code, String[] response)
          Creates an FTP response with given status code and response string.
 
Method Summary
 int getCode()
          Gets the numeric response code.
 String[] getResponse()
          Gets the response string array.
 boolean isCodeValid()
          Does this response have a valid code?
 boolean isIntermediate()
          Is this response an intermediate message?
 boolean isSuccess()
          Is this response a successful message?
static FtpResponse readResponse(BufferedReader in)
          Reads a server response.
 boolean responseContains(String contain)
          Search for a text string in each line of the response result.
static void sendCommand(Socket socket, String command)
          Helper method to send commands to the remote server.
 void setCode(int code)
          Sets the numeric response code.
 void setResponse(String[] response)
          Sets the response string array.
 String toString()
          Converts FTP response to string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FtpResponse

public FtpResponse()
Creates an empty FTP response.


FtpResponse

public FtpResponse(int code,
                   String[] response)
Creates an FTP response with given status code and response string.

Parameters:
code - numeric status code
response - response detail message (one line per array element)
Method Detail

getCode

public int getCode()
Gets the numeric response code.

Returns:
numeric status code

setCode

public void setCode(int code)
Sets the numeric response code.

Parameters:
code - numeric status code

getResponse

public String[] getResponse()
Gets the response string array.

Returns:
response detail message (one line per array element)

setResponse

public void setResponse(String[] response)
Sets the response string array.

Parameters:
response - response detail message (one line per array element)

responseContains

public boolean responseContains(String contain)
Search for a text string in each line of the response result. Note that each line is tested individually.

Parameters:
contain - text to search for (using String.contains(contain))
Returns:
true if the search string is found, false otherwise

toString

public String toString()
Converts FTP response to string.

Overrides:
toString in class Object
Returns:
FTP response as would be sent over FTP

isCodeValid

public boolean isCodeValid()
Does this response have a valid code?

Returns:
True if the response code is between 100 and 599, false otherwise.

isSuccess

public boolean isSuccess()
Is this response a successful message?

Returns:
True if the response code is between 200 and 299, false otherwise.

isIntermediate

public boolean isIntermediate()
Is this response an intermediate message?

Returns:
True if the response code is between 300 and 399, false otherwise.

sendCommand

public static void sendCommand(Socket socket,
                               String command)
                        throws IOException
Helper method to send commands to the remote server.

Parameters:
socket - connection to the server
command - command to send, without trailing EOL (CRLF, \r\n).
Throws:
IOException - if we can't write() to the OutputStream for the Socket

readResponse

public static FtpResponse readResponse(BufferedReader in)
                                throws IOException
Reads a server response.

Parameters:
in - input reader
Returns:
response from server
Throws:
IOException - if any.


Copyright © 2011. All Rights Reserved.