com.noelios.restlet.http
Class HttpUtils

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

public class HttpUtils
extends java.lang.Object

Various HTTP utilities.

Author:
Jerome Louvel

Constructor Summary
HttpUtils()
           
 
Method Summary
static java.lang.Appendable appendComment(java.lang.CharSequence source, java.lang.Appendable destination)
          Appends a source string as an HTTP comment.
static java.lang.Appendable appendQuote(java.lang.CharSequence source, java.lang.Appendable destination)
          Appends a source string as an HTTP quoted string.
static java.lang.Appendable appendUriEncoded(java.lang.CharSequence source, java.lang.Appendable destination, CharacterSet characterSet)
          Appends a source string as an URI encoded string.
static Parameter createParameter(java.lang.CharSequence name, java.lang.CharSequence value)
          Creates a parameter.
static java.lang.String createVaryHeader(java.util.Collection<Dimension> dimensions)
          Creates a vary header from the given dimensions.
static void formatProduct(java.lang.CharSequence nameToken, java.lang.CharSequence versionToken, java.lang.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(java.lang.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(java.io.InputStream is, java.lang.StringBuilder sb)
          Read a header.
static void writeCRLF(java.io.OutputStream os)
          Writes a new line.
static void writeHeader(Parameter header, java.io.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 java.lang.Appendable appendComment(java.lang.CharSequence source,
                                                 java.lang.Appendable destination)
                                          throws java.io.IOException
Appends a source string as an HTTP comment.

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

appendQuote

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

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

appendUriEncoded

public static java.lang.Appendable appendUriEncoded(java.lang.CharSequence source,
                                                    java.lang.Appendable destination,
                                                    CharacterSet characterSet)
                                             throws java.io.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:
java.io.IOException

createParameter

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

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

createVaryHeader

public static java.lang.String createVaryHeader(java.util.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(java.lang.CharSequence nameToken,
                                 java.lang.CharSequence versionToken,
                                 java.lang.Appendable destination)
                          throws java.io.IOException
Formats a product description.

Parameters:
nameToken - The product name token.
versionToken - The product version token.
destination - The appendable destination;
Throws:
java.io.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(java.lang.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(java.io.InputStream is,
                                   java.lang.StringBuilder sb)
                            throws java.io.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:
java.io.IOException

writeCRLF

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

Parameters:
os - The output stream.
Throws:
java.io.IOException

writeHeader

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

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


Copyright © 2005-2008 Noelios Technologies.