Class HeaderUtils


  • public class HeaderUtils
    extends java.lang.Object
    HTTP-style header utilities.
    Author:
    Jerome Louvel
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addEntityHeaders​(org.restlet.client.representation.Representation entity, org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Adds the entity headers based on the Representation to the Series.
      static void addExtensionHeaders​(org.restlet.client.util.Series<org.restlet.client.data.Header> existingHeaders, org.restlet.client.util.Series<org.restlet.client.data.Header> additionalHeaders)
      Adds extension headers if they are non-standard headers.
      static void addGeneralHeaders​(org.restlet.client.Message message, org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Adds the general headers from the Message to the Series.
      static void addHeader​(java.lang.String headerName, java.lang.String headerValue, org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Adds a header to the given list.
      static void addNotModifiedEntityHeaders​(org.restlet.client.representation.Representation entity, org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Adds the entity headers based on the Representation to the Series when a 304 (Not Modified) status is returned.
      static void addRequestHeaders​(org.restlet.client.Request request, org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Adds the headers based on the Request to the given Series .
      static void copyExtensionHeaders​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers, org.restlet.client.Message message)
      Copies extension headers into a request or a response.
      static void copyResponseTransportHeaders​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers, org.restlet.client.Response response)
      Copies headers into a response.
      static org.restlet.client.representation.Representation extractEntityHeaders​(java.lang.Iterable<org.restlet.client.data.Header> headers, org.restlet.client.representation.Representation representation)
      Extracts entity headers and updates a given representation or create an empty one when at least one entity header is present.
      static long getContentLength​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Returns the content length of the request entity if know, Representation.UNKNOWN_SIZE otherwise.
      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 isChunkedEncoding​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Indicates if the entity is chunked.
      static boolean isComma​(int character)
      Indicates if the given character is a comma, the character used as header value separator.
      static boolean isCommentText​(int character)
      Indicates if the given character is a comment text.
      static boolean isConnectionClose​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
      Indicates if the connection must be closed.
      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 isLatin1Char​(int character)
      Indicates if the given character is in ISO Latin 1 (8859-1) range.
      static boolean isLinearWhiteSpace​(int character)
      Indicates if the given character is a value separator.
      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 isQuoteCharacter​(int character)
      Indicates if the given character marks the start of a quoted pair.
      static boolean isQuotedText​(int character)
      Indicates if the given character is a quoted text.
      static boolean isSemiColon​(int character)
      Indicates if the given character is a semicolon, the character used as header parameter separator.
      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 (ISO Latin 1 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 void keepExtensionHeadersOnly​(org.restlet.client.Message message)
      Remove the headers that are mapped to the framework's API from the given message's list of headers.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • addEntityHeaders

        public static void addEntityHeaders​(org.restlet.client.representation.Representation entity,
                                            org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Adds the entity headers based on the Representation to the Series.
        Parameters:
        entity - The source entity Representation.
        headers - The target headers Series.
      • addExtensionHeaders

        public static void addExtensionHeaders​(org.restlet.client.util.Series<org.restlet.client.data.Header> existingHeaders,
                                               org.restlet.client.util.Series<org.restlet.client.data.Header> additionalHeaders)
        Adds extension headers if they are non-standard headers.
        Parameters:
        existingHeaders - The headers to update.
        additionalHeaders - The headers to add.
      • addGeneralHeaders

        public static void addGeneralHeaders​(org.restlet.client.Message message,
                                             org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Adds the general headers from the Message to the Series.
        Parameters:
        message - The source Message.
        headers - The target headers Series.
      • addHeader

        public static void addHeader​(java.lang.String headerName,
                                     java.lang.String headerValue,
                                     org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Adds a header to the given list. Checks for exceptions and logs them.
        Parameters:
        headerName - The header name.
        headerValue - The header value.
        headers - The headers list.
      • addNotModifiedEntityHeaders

        public static void addNotModifiedEntityHeaders​(org.restlet.client.representation.Representation entity,
                                                       org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Adds the entity headers based on the Representation to the Series when a 304 (Not Modified) status is returned.
        Parameters:
        entity - The source entity Representation.
        headers - The target headers Series.
      • addRequestHeaders

        public static void addRequestHeaders​(org.restlet.client.Request request,
                                             org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Adds the headers based on the Request to the given Series .
        Parameters:
        request - The Request to copy the headers from.
        headers - The Series to copy the headers to.
      • keepExtensionHeadersOnly

        public static void keepExtensionHeadersOnly​(org.restlet.client.Message message)
        Remove the headers that are mapped to the framework's API from the given message's list of headers.
        Parameters:
        message - The message to update.
      • copyExtensionHeaders

        public static void copyExtensionHeaders​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers,
                                                org.restlet.client.Message message)
        Copies extension headers into a request or a response.
        Parameters:
        headers - The headers to copy.
        message - The message to update.
      • copyResponseTransportHeaders

        public static void copyResponseTransportHeaders​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers,
                                                        org.restlet.client.Response response)
        Copies headers into a response.
        Parameters:
        headers - The headers to copy.
        response - The response to update.
      • extractEntityHeaders

        public static org.restlet.client.representation.Representation extractEntityHeaders​(java.lang.Iterable<org.restlet.client.data.Header> headers,
                                                                                            org.restlet.client.representation.Representation representation)
                                                                                     throws java.lang.NumberFormatException
        Extracts entity headers and updates a given representation or create an empty one when at least one entity header is present.
        Parameters:
        headers - The headers to copy.
        representation - The representation to update or null.
        Returns:
        a representation updated with the given entity headers.
        Throws:
        java.lang.NumberFormatException
        See Also:
        copyResponseTransportHeaders(Series, Response)
      • getContentLength

        public static long getContentLength​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Returns the content length of the request entity if know, Representation.UNKNOWN_SIZE otherwise.
        Returns:
        The request content length.
      • 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.
      • isChunkedEncoding

        public static boolean isChunkedEncoding​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Indicates if the entity is chunked.
        Returns:
        True if the entity is chunked.
      • isComma

        public static boolean isComma​(int character)
        Indicates if the given character is a comma, the character used as header value separator.
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is a comma.
      • isCommentText

        public static boolean isCommentText​(int character)
        Indicates if the given character is a comment text. It means isText(int) returns true and the character is not '(' or ')'.
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is a quoted text.
      • isConnectionClose

        public static boolean isConnectionClose​(org.restlet.client.util.Series<org.restlet.client.data.Header> headers)
        Indicates if the connection must be closed.
        Parameters:
        headers - The headers to test.
        Returns:
        True if the connection must be closed.
      • 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.
      • isLatin1Char

        public static boolean isLatin1Char​(int character)
        Indicates if the given character is in ISO Latin 1 (8859-1) range. Note that this range is a superset of ASCII and a subrange of Unicode (UTF-8).
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is in ISO Latin 1 range.
      • isLinearWhiteSpace

        public static boolean isLinearWhiteSpace​(int character)
        Indicates if the given character is a value separator.
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is a value separator.
      • 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).
      • isQuoteCharacter

        public static boolean isQuoteCharacter​(int character)
        Indicates if the given character marks the start of a quoted pair.
        Parameters:
        character - The character to test.
        Returns:
        True if the given character marks the start of a quoted pair.
      • isQuotedText

        public static boolean isQuotedText​(int character)
        Indicates if the given character is a quoted text. It means isText(int) returns true and isDoubleQuote(int) returns false.
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is a quoted text.
      • isSemiColon

        public static boolean isSemiColon​(int character)
        Indicates if the given character is a semicolon, the character used as header parameter separator.
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is a semicolon.
      • 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 (ISO Latin 1 and not a control character).
        Parameters:
        character - The character to test.
        Returns:
        True if the given character is textual.
      • 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).