Class CharsetUtil

java.lang.Object
org.apache.james.mime4j.util.CharsetUtil

public class CharsetUtil extends Object
Utility class for working with character sets.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    US-ASCII CR, carriage return (13)
    static final String
    carriage return - line feed sequence
    static final int
    US-ASCII HT, horizontal-tab (9)
    static final int
    US-ASCII LF, line feed (10)
    static final int
    US-ASCII SP, space (32)
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isASCII(char ch)
    Returns true if the specified character falls into the US ASCII character set (Unicode range 0000 to 007f).
    static boolean
    Returns true if the specified string consists entirely of US ASCII characters.
    static boolean
    Returns true if the specified byte array consists entirely of US ASCII characters.
    static boolean
    isWhitespace(char ch)
    Returns true if the specified character is a whitespace character (CR, LF, SP or HT).
    static boolean
    Returns true if the specified string consists entirely of whitespace characters.
    static Charset
    lookup(String name)
    Returns a Charset instance if character set with the given name is recognized and supported by Java runtime.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • CharsetUtil

      public CharsetUtil()
  • Method Details

    • isASCII

      public static boolean isASCII(char ch)
      Returns true if the specified character falls into the US ASCII character set (Unicode range 0000 to 007f).
      Parameters:
      ch - character to test.
      Returns:
      true if the specified character falls into the US ASCII character set, false otherwise.
    • isASCII

      public static boolean isASCII(ByteSequence raw)
      Returns true if the specified byte array consists entirely of US ASCII characters.
      Parameters:
      raw - byte array to test.
      Returns:
      true if the specified string consists entirely of US ASCII characters, false otherwise.
    • isASCII

      public static boolean isASCII(String s)
      Returns true if the specified string consists entirely of US ASCII characters.
      Parameters:
      s - string to test.
      Returns:
      true if the specified string consists entirely of US ASCII characters, false otherwise.
    • isWhitespace

      public static boolean isWhitespace(char ch)
      Returns true if the specified character is a whitespace character (CR, LF, SP or HT).
      Parameters:
      ch - character to test.
      Returns:
      true if the specified character is a whitespace character, false otherwise.
    • isWhitespace

      public static boolean isWhitespace(String s)
      Returns true if the specified string consists entirely of whitespace characters.
      Parameters:
      s - string to test.
      Returns:
      true if the specified string consists entirely of whitespace characters, false otherwise.
    • lookup

      public static Charset lookup(String name)

      Returns a Charset instance if character set with the given name is recognized and supported by Java runtime. Returns null otherwise.

      This method is a wrapper around Charset.forName(String) method that catches IllegalCharsetNameException and UnsupportedCharsetException and returns null.