Class UTF8Encoder


  • public class UTF8Encoder
    extends java.lang.Object
    Utility class related to encoding characters into (UTF-8) byte sequences.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canEncode​(java.lang.CharSequence input)
      See CharsetEncoder.canEncode(CharSequence).
      static byte[] encodeAsByteArray​(java.lang.String input)
      Like String.getBytes(java.nio.charset.Charset) (with "UTF-8"), except that invalid character sequences (such as unpaired surrogates) are reported as exceptions (see CodingErrorAction.REPORT, instead of being silently replaced by a replacement character as it would happen otherwise.
      • Methods inherited from class java.lang.Object

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

      • encodeAsByteArray

        public static byte[] encodeAsByteArray​(java.lang.String input)
                                        throws java.io.IOException
        Like String.getBytes(java.nio.charset.Charset) (with "UTF-8"), except that invalid character sequences (such as unpaired surrogates) are reported as exceptions (see CodingErrorAction.REPORT, instead of being silently replaced by a replacement character as it would happen otherwise.
        Parameters:
        input - String to encode
        Returns:
        String encoded using StandardCharsets.UTF_8
        Throws:
        java.io.IOException - on encoding error
      • canEncode

        public static boolean canEncode​(java.lang.CharSequence input)
        See CharsetEncoder.canEncode(CharSequence).