Class EncodingUtil

java.lang.Object
com.itextpdf.commons.utils.EncodingUtil

public final class EncodingUtil extends Object
This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    convertToBytes(char[] chars, String encoding)
    Converts to byte array an array of chars, taking the provided encoding into account.
    static String
    convertToString(byte[] bytes, String encoding)
    Converts to String an array of bytes, taking the provided encoding into account.
    static byte[]
    Decodes base64 string into byte array with tolerance to new lines and spaces.
    static String
    toBase64(byte[] bytes)
    Encodes byte array to base64 string.

    Methods inherited from class Object

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

  • Constructor Details

    • EncodingUtil

      private EncodingUtil()
  • Method Details

    • convertToBytes

      public static byte[] convertToBytes(char[] chars, String encoding) throws CharacterCodingException
      Converts to byte array an array of chars, taking the provided encoding into account.
      Parameters:
      chars - an array of chars to be converted to bytes
      encoding - the encoding to be taken into account while converting the provided array of chars
      Returns:
      the resultant array of bytes
      Throws:
      CharacterCodingException - if anything goes wrong while encoding
    • convertToString

      public static String convertToString(byte[] bytes, String encoding) throws UnsupportedEncodingException
      Converts to String an array of bytes, taking the provided encoding into account.
      Parameters:
      bytes - an array of bytes to be converted to String
      encoding - the encoding to be taken into account while converting the provided bytes
      Returns:
      the resultant string
      Throws:
      UnsupportedEncodingException - if anything goes wrong while encoding
    • fromBase64

      public static byte[] fromBase64(String base64)
      Decodes base64 string into byte array with tolerance to new lines and spaces.
      Parameters:
      base64 - base64 string to decode
      Returns:
      decode string as byte array
    • toBase64

      public static String toBase64(byte[] bytes)
      Encodes byte array to base64 string.
      Parameters:
      bytes - the byte array to encode
      Returns:
      encoded base64 string