Class RFC2616Codec

java.lang.Object
com.helger.base.codec.impl.RFC2616Codec
All Implemented Interfaces:
ICharArrayCodec, ICharArrayDecoder, ICharArrayEncoder, ICharArrayStreamDecoder, ICharArrayStreamEncoder, ICodec<char[]>, IDecoder<char[],char[]>, IEncoder<char[],char[]>

public class RFC2616Codec extends Object implements ICharArrayCodec
Codec for RFC 2616 (HTTP/1.1) HTTP header values.
Since:
9.3.6
Author:
Philip Helger
  • Constructor Details

    • RFC2616Codec

      public RFC2616Codec()
      Constructor.
  • Method Details

    • isToken

      public static boolean isToken(@Nullable String s)
      Check if the passed string is a valid RFC 2616 token (i.e. contains no non-token characters).
      Parameters:
      s - The string to check. May be null.
      Returns:
      true if the string is a valid token, false otherwise.
    • isToken

      public static boolean isToken(char @Nullable [] aChars)
      Check if the passed char array is a valid RFC 2616 token.
      Parameters:
      aChars - The char array to check. May be null.
      Returns:
      true if the char array is a valid token, false otherwise.
    • isMaybeEncoded

      public static boolean isMaybeEncoded(@Nullable String s)
      Check if the passed string looks like it might be RFC 2616 encoded (starts and ends with a double quote character).
      Parameters:
      s - The string to check. May be null.
      Returns:
      true if the string might be encoded, false otherwise.
    • isMaybeEncoded

      public static boolean isMaybeEncoded(char @Nullable [] s)
      Check if the passed char array looks like it might be RFC 2616 encoded (starts and ends with a double quote character).
      Parameters:
      s - The char array to check. May be null.
      Returns:
      true if the char array might be encoded, false otherwise.
    • getMaximumEncodedLength

      @Nonnegative public int getMaximumEncodedLength(@Nonnegative int nDecodedLen)
      Description copied from interface: ICharArrayStreamEncoder
      Get the maximum encoded length based on the provided decoded length. This is purely for performance reasons. The name of the method would be better called "getMaximumEncodedLength".
      Specified by:
      getMaximumEncodedLength in interface ICharArrayEncoder
      Specified by:
      getMaximumEncodedLength in interface ICharArrayStreamEncoder
      Parameters:
      nDecodedLen - The decoded length. Always ≥ 0.
      Returns:
      The maximum encoded length. Always ≥ 0.
    • encode

      public void encode(char @Nullable [] aDecodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull Writer aWriter)
      Encode (part of) a char array to an Writer.
      Specified by:
      encode in interface ICharArrayStreamEncoder
      Parameters:
      aDecodedBuffer - The char array to be encoded. May be null.
      nOfs - Offset into the char array to start from.
      nLen - Number of chars starting from offset to consider.
      aWriter - The writer to write to. May not be null and is NOT closed afterwards!
    • getMaximumDecodedLength

      @Nonnegative public int getMaximumDecodedLength(@Nonnegative int nEncodedLen)
      Description copied from interface: ICharArrayDecoder
      Get the maximum decoded length based on the provided encoded length. This is purely for performance reasons.
      Specified by:
      getMaximumDecodedLength in interface ICharArrayDecoder
      Parameters:
      nEncodedLen - The encoded length. Always ≥ 0.
      Returns:
      The maximum decoded length. Always ≥ 0.
    • decode

      public void decode(char @Nullable [] aEncodedBuffer, @Nonnegative int nOfs, @Nonnegative int nLen, @WillNotClose @NonNull Writer aWriter)
      Decode (part of) a char array.
      Specified by:
      decode in interface ICharArrayStreamDecoder
      Parameters:
      aEncodedBuffer - The char array to be decoded. May be null.
      nOfs - Offset into the char array to start from.
      nLen - Number of chars starting from offset to consider.
      aWriter - The writer to write to. May not be null and is NOT closed afterwards!