com.noelios.restlet.http
Class HttpUtils

java.lang.Object
  extended by com.noelios.restlet.http.HttpUtils
Direct Known Subclasses:
HttpsUtils

public class HttpUtils
extends Object

Various HTTP utilities.

Author:
Jerome Louvel

Constructor Summary
HttpUtils()
           
 
Method Summary
static Appendable appendComment(CharSequence source, Appendable destination)
          Appends a source string as an HTTP comment.
static Appendable appendQuote(CharSequence source, Appendable destination)
          Appends a source string as an HTTP quoted string.
static Appendable appendUriEncoded(CharSequence source, Appendable destination, CharacterSet characterSet)
          Appends a source string as an URI encoded string.
static Parameter createParameter(CharSequence name, CharSequence value)
          Creates a parameter.
static String createVaryHeader(Collection<Dimension> dimensions)
          Creates a vary header from the given dimensions.
static void formatProduct(CharSequence nameToken, CharSequence versionToken, Appendable destination)
          Formats a product description.
static boolean isAlpha(int character)
          Indicates if the given character is alphabetical (a-z or A-Z).
static boolean isAsciiChar(int character)
          Indicates if the given character is in ASCII range.
static boolean isCarriageReturn(int character)
          Indicates if the given character is a carriage return.
static boolean isControlChar(int character)
          Indicates if the given character is a control character.
static boolean isDigit(int character)
          Indicates if the given character is a digit (0-9).
static boolean isDoubleQuote(int character)
          Indicates if the given character is a double quote.
static boolean isHorizontalTab(int character)
          Indicates if the given character is an horizontal tab.
static boolean isLineFeed(int character)
          Indicates if the given character is a line feed.
static boolean isLowerCase(int character)
          Indicates if the given character is lower case (a-z).
static boolean isSeparator(int character)
          Indicates if the given character is a separator.
static boolean isSpace(int character)
          Indicates if the given character is a space.
static boolean isText(int character)
          Indicates if the given character is textual (ASCII and not a control character).
static boolean isToken(CharSequence token)
          Indicates if the token is valid.
Only contains valid token characters.
static boolean isTokenChar(int character)
          Indicates if the given character is a token character (text and not a separator).
static boolean isUpperCase(int character)
          Indicates if the given character is upper case (A-Z).
static Parameter readHeader(InputStream is, StringBuilder sb)
          Read a header.
static void writeCRLF(OutputStream os)
          Writes a new line.
static void writeHeader(Parameter header, OutputStream os)
          Writes a header line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpUtils

public HttpUtils()
Method Detail

appendComment

public static Appendable appendComment(CharSequence source,
                                       Appendable destination)
                                throws IOException
Appends a source string as an HTTP comment.

Parameters:
source - The source string to format.
destination - The appendable destination.
Throws:
IOException

appendQuote

public static Appendable appendQuote(CharSequence source,
                                     Appendable destination)
                              throws IOException
Appends a source string as an HTTP quoted string.

Parameters:
source - The unquoted source string.
destination - The destination to append to.
Throws:
IOException

appendUriEncoded

public static Appendable appendUriEncoded(CharSequence source,
                                          Appendable destination,
                                          CharacterSet characterSet)
                                   throws IOException
Appends a source string as an URI encoded string.

Parameters:
source - The source string to format.
destination - The appendable destination.
characterSet - The supported character encoding.
Throws:
IOException

createParameter

public static Parameter createParameter(CharSequence name,
                                        CharSequence value)
Creates a parameter.

Parameters:
name - The parameter name buffer.
value - The parameter value buffer (can be null).
Returns:
The created parameter.
Throws:
IOException

createVaryHeader

public static String createVaryHeader(Collection<Dimension> dimensions)
Creates a vary header from the given dimensions.

Parameters:
dimensions - The dimensions to copy to the response.
Returns:
Returns the Vary header or null, if dimensions is null or empty.

formatProduct

public static void formatProduct(CharSequence nameToken,
                                 CharSequence versionToken,
                                 Appendable destination)
                          throws IOException
Formats a product description.

Parameters:
nameToken - The product name token.
versionToken - The product version token.
destination - The appendable destination;
Throws:
IOException

isAlpha

public static boolean isAlpha(int character)
Indicates if the given character is alphabetical (a-z or A-Z).

Parameters:
character - The character to test.
Returns:
True if the given character is alphabetical (a-z or A-Z).

isAsciiChar

public static boolean isAsciiChar(int character)
Indicates if the given character is in ASCII range.

Parameters:
character - The character to test.
Returns:
True if the given character is in ASCII range.

isCarriageReturn

public static boolean isCarriageReturn(int character)
Indicates if the given character is a carriage return.

Parameters:
character - The character to test.
Returns:
True if the given character is a carriage return.

isControlChar

public static boolean isControlChar(int character)
Indicates if the given character is a control character.

Parameters:
character - The character to test.
Returns:
True if the given character is a control character.

isDigit

public static boolean isDigit(int character)
Indicates if the given character is a digit (0-9).

Parameters:
character - The character to test.
Returns:
True if the given character is a digit (0-9).

isDoubleQuote

public static boolean isDoubleQuote(int character)
Indicates if the given character is a double quote.

Parameters:
character - The character to test.
Returns:
True if the given character is a double quote.

isHorizontalTab

public static boolean isHorizontalTab(int character)
Indicates if the given character is an horizontal tab.

Parameters:
character - The character to test.
Returns:
True if the given character is an horizontal tab.

isLineFeed

public static boolean isLineFeed(int character)
Indicates if the given character is a line feed.

Parameters:
character - The character to test.
Returns:
True if the given character is a line feed.

isLowerCase

public static boolean isLowerCase(int character)
Indicates if the given character is lower case (a-z).

Parameters:
character - The character to test.
Returns:
True if the given character is lower case (a-z).

isSeparator

public static boolean isSeparator(int character)
Indicates if the given character is a separator.

Parameters:
character - The character to test.
Returns:
True if the given character is a separator.

isSpace

public static boolean isSpace(int character)
Indicates if the given character is a space.

Parameters:
character - The character to test.
Returns:
True if the given character is a space.

isText

public static boolean isText(int character)
Indicates if the given character is textual (ASCII and not a control character).

Parameters:
character - The character to test.
Returns:
True if the given character is textual (ASCII and not a control character).

isToken

public static boolean isToken(CharSequence token)
Indicates if the token is valid.
Only contains valid token characters.

Parameters:
token - The token to check
Returns:
True if the token is valid.

isTokenChar

public static boolean isTokenChar(int character)
Indicates if the given character is a token character (text and not a separator).

Parameters:
character - The character to test.
Returns:
True if the given character is a token character (text and not a separator).

isUpperCase

public static boolean isUpperCase(int character)
Indicates if the given character is upper case (A-Z).

Parameters:
character - The character to test.
Returns:
True if the given character is upper case (A-Z).

readHeader

public static Parameter readHeader(InputStream is,
                                   StringBuilder sb)
                            throws IOException
Read a header. Return null if the last header was already read.

Parameters:
is - The message input stream.
sb - The string builder to reuse.
Returns:
The header read or null.
Throws:
IOException

writeCRLF

public static void writeCRLF(OutputStream os)
                      throws IOException
Writes a new line.

Parameters:
os - The output stream.
Throws:
IOException

writeHeader

public static void writeHeader(Parameter header,
                               OutputStream os)
                        throws IOException
Writes a header line.

Parameters:
header - The header to write.
os - The output stream.
Throws:
IOException


Copyright © 2005-2008 Noelios Technologies.