pygmy.core
Class Http

java.lang.Object
  extended by pygmy.core.Http

public class Http
extends java.lang.Object

Utility class for HTTP error codes, and other command HTTP tasks.


Field Summary
static java.lang.String CRLF
           
 
Constructor Summary
Http()
           
 
Method Summary
static java.lang.String encodeHtml(java.lang.String message)
          This encodes the message into Html.
static java.util.List findAllHostAddresses(boolean includeLoopback)
           
static java.net.InetAddress findRoutableHostAddress()
          This method tries to find a suitable InetAddress that is routable.
static java.lang.String formatTime(long time)
          This formats the given time as a HTTP formatted string.
static java.lang.String getCurrentTime()
          This creates the current time as a string conforming to a HTTP date following the format EEE, dd MMM yyyy HH:mm:ss z.
static java.lang.String getStatusPhrase(int code)
          Given a HTTP response code, this method will return the english phrase.
static boolean isSecure(java.lang.String root, java.io.File file)
           
static java.lang.String join(java.lang.String path, java.lang.String relativePath)
          Takes two paths a joins them together properly adding the '/' charater between them.
static long parseTime(java.lang.String date)
          This parses the given time as a HTTP formatted string.
static java.io.File translatePath(java.lang.String root, java.lang.String url)
          This translates a url into a path on the filesystem.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRLF

public static final java.lang.String CRLF
See Also:
Constant Field Values
Constructor Detail

Http

public Http()
Method Detail

getStatusPhrase

public static java.lang.String getStatusPhrase(int code)
Given a HTTP response code, this method will return the english phrase.

Parameters:
code - the HTTP response code to look up.
Returns:
A string describing what the HTTP response code is.

encodeHtml

public static java.lang.String encodeHtml(java.lang.String message)
This encodes the message into Html. It encodes characters '&', ''', '<', '>', and '"' into &, ', <, >, and ".

Parameters:
message - the message to encode.
Returns:
the encoded message.

getCurrentTime

public static java.lang.String getCurrentTime()
This creates the current time as a string conforming to a HTTP date following the format EEE, dd MMM yyyy HH:mm:ss z.

Returns:
The a HTTP formated string of the current time.

formatTime

public static java.lang.String formatTime(long time)
This formats the given time as a HTTP formatted string. The format is EEE, dd MMM yyyy HH:mm:ss z.

Parameters:
time - the time to format into a string.
Returns:
the formatted date.

parseTime

public static long parseTime(java.lang.String date)
                      throws java.text.ParseException
This parses the given time as a HTTP formatted string.

Parameters:
date - The date represented as the format String EEE, dd MMM yyyy HH:mm:ss z.
Returns:
the time in milliseconds.
Throws:
java.text.ParseException - throws this exeception when it cannot parse the date.

join

public static java.lang.String join(java.lang.String path,
                                    java.lang.String relativePath)
Takes two paths a joins them together properly adding the '/' charater between them.

Parameters:
path - the first part of the path.
relativePath - the second part to join to the first path.
Returns:
the combined path of path and relativePath.

translatePath

public static java.io.File translatePath(java.lang.String root,
                                         java.lang.String url)
                                  throws java.io.UnsupportedEncodingException
This translates a url into a path on the filesystem. This decodes the url using the URLDecoder class, and creates an absolute path beginning with root.

Parameters:
root - this is an absolute path to prepend onto the url.
url - the url to resolve into the filesystem.
Returns:
the a File object representing this URL.
Throws:
java.io.UnsupportedEncodingException

isSecure

public static boolean isSecure(java.lang.String root,
                               java.io.File file)
                        throws java.io.IOException
Throws:
java.io.IOException

findRoutableHostAddress

public static java.net.InetAddress findRoutableHostAddress()
                                                    throws java.net.UnknownHostException,
                                                           java.net.SocketException
This method tries to find a suitable InetAddress that is routable. It calls InetAddress.getLocalHost() to find the local host. If that address it a site local address (192.168.*.*, 10.*.*.*, or 172.16.*.*) or the loopback address (127.0.0.1), it enumerates all the NetworkInterfaces, and tries to find an address that is not site local or loopback address. If it cannot it simply returns whatever InetAddress.getLocalHost().

Returns:
the address of a non site local or non loopback address, unless there is only loopback or site local addresses.
Throws:
java.net.UnknownHostException
java.net.SocketException

findAllHostAddresses

public static java.util.List findAllHostAddresses(boolean includeLoopback)
                                           throws java.net.SocketException
Throws:
java.net.SocketException