Class StringUtils


  • public class StringUtils
    extends java.lang.Object
    Utilities for strings.
    Since:
    1.8
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String LINE_SEPARATOR
      Line separator to use for this OS, i.e.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StringUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] getBytesUtf8​(java.lang.String string)
      Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.
      static java.lang.String newStringUtf8​(byte[] bytes)
      Constructs a new String by decoding the specified array of bytes using the UTF-8 charset.
      • Methods inherited from class java.lang.Object

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

      • LINE_SEPARATOR

        public static final java.lang.String LINE_SEPARATOR
        Line separator to use for this OS, i.e. "\n" or "\r\n".
        Since:
        1.8
    • Constructor Detail

      • StringUtils

        private StringUtils()
    • Method Detail

      • getBytesUtf8

        public static byte[] getBytesUtf8​(java.lang.String string)
        Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.
        Parameters:
        string - the String to encode, may be null
        Returns:
        encoded bytes, or null if the input string was null
        Throws:
        java.lang.IllegalStateException - Thrown when the charset is missing, which should be never according the Java specification.
        Since:
        1.8
        See Also:
        Standard charsets
      • newStringUtf8

        public static java.lang.String newStringUtf8​(byte[] bytes)
        Constructs a new String by decoding the specified array of bytes using the UTF-8 charset.
        Parameters:
        bytes - The bytes to be decoded into characters
        Returns:
        A new String decoded from the specified array of bytes using the UTF-8 charset, or null if the input byte array was null.
        Throws:
        java.lang.IllegalStateException - Thrown when a UnsupportedEncodingException is caught, which should never happen since the charset is required.
        Since:
        1.8