Class CharsetUtil


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

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

      Constructors 
      Constructor Description
      CharsetUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      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 isASCII​(java.lang.String s)
      Returns true if the specified string consists entirely of US ASCII characters.
      static boolean isASCII​(ByteSequence raw)
      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 isWhitespace​(java.lang.String s)
      Returns true if the specified string consists entirely of whitespace characters.
      static java.nio.charset.Charset lookup​(java.lang.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
    • Constructor Detail

      • CharsetUtil

        public CharsetUtil()
    • Method Detail

      • 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​(java.lang.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​(java.lang.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 java.nio.charset.Charset lookup​(java.lang.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.