com.noelios.restlet.http
Class HttpUtils

java.lang.Object
  extended by com.noelios.restlet.http.HttpUtils

public class HttpUtils
extends Object

HTTP-style header manipulation utilities.

Author:
Jerome Louvel (contact@noelios.com)

Constructor Summary
HttpUtils()
           
 
Method Summary
 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 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 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 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

createParameter

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

Parameters:
name - The parameter name buffer.
value - The parameter value buffer (can be null).
Returns:
The created parameter.
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

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

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.

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).

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).

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).

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).

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.

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.

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.

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.

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.

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.

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).

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.

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).

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.

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

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-2007 Noelios Consulting.