org.mockftpserver.core.util
Class PortParser

java.lang.Object
  extended by org.mockftpserver.core.util.PortParser

public final class PortParser
extends Object

Utility class for parsing host and port values from command arguments.

Version:
$Revision: 232 $ - $Date: 2009-06-13 19:18:01 -0400 (Sat, 13 Jun 2009) $
Author:
Chris Mair

Method Summary
static String convertHostAndPortToCommaDelimitedBytes(InetAddress host, int port)
          Convert the InetAddess and port number to a comma-delimited list of byte values, suitable for the response String from the PASV command.
static HostAndPort parseExtendedAddressHostAndPort(String parameter)
          Parse the host address and port number of an extended address.
static HostAndPort parseHostAndPort(String[] parameters)
          Parse a 32-bit IP address and 16-bit port number from the String[] of FTP command parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parseExtendedAddressHostAndPort

public static HostAndPort parseExtendedAddressHostAndPort(String parameter)
Parse the host address and port number of an extended address. This encoded format is used by the EPRT FTP command, and supports IPv6.

The client network address can be in IPv4 format (e.g., "132.235.1.2") or IPv6 format (e.g., "1080::8:800:200C:417A"). See RFC2428 for more information.

Parameters:
parameter - - the single parameter String containing the encoded host and port number
Returns:
the populated HostAndPort object

parseHostAndPort

public static HostAndPort parseHostAndPort(String[] parameters)
Parse a 32-bit IP address and 16-bit port number from the String[] of FTP command parameters. This is used by the FTP "PORT" command.

Parameters:
parameters - - the String[] of command parameters. It is the concatenation of a 32-bit internet host address and a 16-bit TCP port address. This address information is broken into 8-bit fields and the value of each field is encoded as a separate parameter whose value is a decimal number (in character string representation). Thus, the six parameters for the port command would be: h1,h2,h3,h4,p1,p2 where h1 is the high order 8 bits of the internet host address, and p1 is the high order 8 bits of the port number.
Returns:
the HostAndPort object with the host InetAddres and int port parsed from the parameters
Throws:
AssertFailedException - - if parameters is null or contains an insufficient number of elements
NumberFormatException - - if one of the parameters does not contain a parsable integer

convertHostAndPortToCommaDelimitedBytes

public static String convertHostAndPortToCommaDelimitedBytes(InetAddress host,
                                                             int port)
Convert the InetAddess and port number to a comma-delimited list of byte values, suitable for the response String from the PASV command.

Parameters:
host - - the InetAddress
port - - the port number
Returns:
the comma-delimited list of byte values, e.g., "196,168,44,55,23,77"


Copyright © 2014. All rights reserved.