Class FtpResponse
- java.lang.Object
-
- org.opennms.netmgt.poller.monitors.support.FtpResponse
-
public class FtpResponse extends java.lang.Object
Represents an FTP command response.- Version:
- $Id: $
- Author:
- DJ Gregor
-
-
Constructor Summary
Constructors Constructor Description FtpResponse(int code, java.lang.String[] response)
Creates an FTP response with given status code and response string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getCode()
Gets the numeric response code.java.lang.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(java.io.BufferedReader in)
Reads a server response.boolean
responseContains(java.lang.String contain)
Search for a text string in each line of the response result.static void
sendCommand(java.net.Socket socket, java.lang.String command)
Helper method to send commands to the remote server.void
setCode(int code)
Sets the numeric response code.void
setResponse(java.lang.String[] response)
Sets the response string array.java.lang.String
toString()
Converts FTP response to string.
-
-
-
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 java.lang.String[] getResponse()
Gets the response string array.- Returns:
- response detail message (one line per array element)
-
setResponse
public void setResponse(java.lang.String[] response)
Sets the response string array.- Parameters:
response
- response detail message (one line per array element)
-
responseContains
public boolean responseContains(java.lang.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 java.lang.String toString()
Converts FTP response to string.- Overrides:
toString
in classjava.lang.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(java.net.Socket socket, java.lang.String command) throws java.io.IOException
Helper method to send commands to the remote server.- Parameters:
socket
- connection to the servercommand
- command to send, without trailing EOL (CRLF, \r\n).- Throws:
java.io.IOException
- if we can't write() to the OutputStream for the Socket
-
readResponse
public static FtpResponse readResponse(java.io.BufferedReader in) throws java.io.IOException
Reads a server response.- Parameters:
in
- input reader- Returns:
- response from server
- Throws:
java.io.IOException
- if any.
-
-