Class StringUtilities

java.lang.Object
org.apache.mina.proxy.utils.StringUtilities

public class StringUtilities extends Object
StringUtilities.java - Various methods to handle strings.
Since:
MINA 2.0.0-M3
  • Constructor Details

    • StringUtilities

      private StringUtilities()
  • Method Details

    • getDirectiveValue

      public static String getDirectiveValue(Map<String,String> directivesMap, String directive, boolean mandatory) throws AuthenticationException
      A directive is a parameter of the digest authentication process. Returns the value of a directive from the map. If mandatory is true and the value is null, then it throws an AuthenticationException.
      Parameters:
      directivesMap - the directive's map
      directive - the name of the directive we want to retrieve
      mandatory - is the directive mandatory
      Returns:
      the mandatory value as a String
      Throws:
      AuthenticationException - if mandatory is true and if directivesMap.get(directive) == null
    • copyDirective

      public static void copyDirective(Map<String,String> directives, StringBuilder sb, String directive)
      Copy the directive to the StringBuilder if not null. (A directive is a parameter of the digest authentication process.)
      Parameters:
      directives - the directives map
      sb - the output buffer
      directive - the directive name to look for
    • copyDirective

      public static String copyDirective(Map<String,String> src, Map<String,String> dst, String directive)
      Copy the directive from the source map to the destination map, if it's value isn't null. (A directive is a parameter of the digest authentication process.)
      Parameters:
      src - the source map
      dst - the destination map
      directive - the directive name
      Returns:
      the value of the copied directive
    • parseDirectives

      public static Map<String,String> parseDirectives(byte[] buf) throws SaslException
      Parses digest-challenge string, extracting each token and value(s). Each token is a directive.
      Parameters:
      buf - A non-null digest-challenge string.
      Returns:
      A Map containing the aprsed directives
      Throws:
      SaslException - if the String cannot be parsed according to RFC 2831
    • extractDirective

      private static void extractDirective(Map<String,String> map, String key, String value) throws SaslException
      Processes directive/value pairs from the digest-challenge and fill out the provided map.
      Parameters:
      key - A non-null String challenge token name.
      value - A non-null String token value.
      Throws:
      SaslException - if either the key or the value is null or if the key already has a value.
    • isLws

      public static boolean isLws(byte b)
      Is character a linear white space ? LWS = [CRLF] 1*( SP | HT ) Note that we're checking individual bytes instead of CRLF
      Parameters:
      b - the byte to check
      Returns:
      true if it's a linear white space
    • skipLws

      private static int skipLws(byte[] buf, int start)
      Skip all linear white spaces
      Parameters:
      buf - the buf which is being scanned for lws
      start - the offset to start at
      Returns:
      the next position in buf which isn't a lws character
    • stringTo8859_1

      public static String stringTo8859_1(String str) throws UnsupportedEncodingException
      Used to convert username-value, passwd or realm to 8859_1 encoding if all chars in string are within the 8859_1 (Latin 1) encoding range.
      Parameters:
      str - a non-null String
      Returns:
      a non-null String containing the 8859_1 encoded string
      Throws:
      UnsupportedEncodingException - if we weren't able to decode using the ISO 8859_1 encoding
    • getSingleValuedHeader

      public static String getSingleValuedHeader(Map<String, List<String>> headers, String key)
      Returns the value of the named header. If it has multiple values then an IllegalArgumentException is thrown
      Parameters:
      headers - the http headers map
      key - the key of the header
      Returns:
      the value of the http header
    • addValueToHeader

      public static void addValueToHeader(Map<String, List<String>> headers, String key, String value, boolean singleValued)
      Adds an header to the provided map of headers.
      Parameters:
      headers - the http headers map
      key - the name of the new header to add
      value - the value of the added header
      singleValued - if true and the map already contains one value then it is replaced by the new value. Otherwise it simply adds a new value to this multi-valued header.