Class CharsetUtil

java.lang.Object
com.norconex.importer.charset.CharsetUtil

public final class CharsetUtil extends Object
Character set utility methods.
  • Method Details

    • convertCharset

      public static String convertCharset(String input, @NonNull @NonNull Charset inputCharset, @NonNull @NonNull Charset outputCharset) throws IOException
      Converts the character encoding of the supplied input value.
      Parameters:
      input - input value to apply conversion
      inputCharset - character set of the input value
      outputCharset - desired character set of the output value
      Returns:
      the converted value
      Throws:
      IOException - problem converting character set
    • convertCharset

      public static String convertCharset(String input, String inputCharset, String outputCharset) throws IOException
      Converts the character encoding of the supplied input value.
      Parameters:
      input - input value to apply conversion
      inputCharset - character set of the input value
      outputCharset - desired character set of the output value
      Returns:
      the converted value
      Throws:
      IOException - problem converting character set
    • convertCharset

      public static void convertCharset(@NonNull @NonNull InputStream input, @NonNull @NonNull Charset inputCharset, @NonNull @NonNull OutputStream output, @NonNull @NonNull Charset outputCharset) throws IOException
      Converts the character encoding of the supplied input.
      Parameters:
      input - input stream to apply conversion
      inputCharset - character set of the input stream
      output - where converted stream will be stored
      outputCharset - desired character set of the output stream
      Throws:
      IOException - problem converting character set
    • convertCharset

      public static void convertCharset(InputStream input, String inputCharset, OutputStream output, String outputCharset) throws IOException
      Converts the character encoding of the supplied input.
      Parameters:
      input - input stream to apply conversion
      inputCharset - character set of the input stream
      output - where converted stream will be stored
      outputCharset - desired character set of the output stream
      Throws:
      IOException - problem converting character set
    • firstNonBlankOrUTF8

      public static String firstNonBlankOrUTF8(String... charsets)
      Returns the first non-blank character encoding, or returns UTF-8 if they are all blank.
      Parameters:
      charsets - character encodings to test
      Returns:
      first non-blank, or UTF-8
    • firstNonBlankOrUTF8

      public static String firstNonBlankOrUTF8(ParseState parseState, String... charsets)
      Returns the first non-blank character encoding, or returns UTF-8 if they are all blank or in post-parse state. That is, UTF-8 is always returned if parsing has already occurred (since parsing converts content encoding to UTF-8).
      Parameters:
      parseState - document parsing state
      charsets - character encodings to test
      Returns:
      first non-blank, or UTF-8
    • firstNonNullOrUTF8

      public static Charset firstNonNullOrUTF8(Charset... charsets)
      Returns the first non-blank character encoding, or returns UTF-8 if they are all blank.
      Parameters:
      charsets - character encodings to test
      Returns:
      first non-blank, or UTF-8
    • firstNonNullOrUTF8

      public static Charset firstNonNullOrUTF8(ParseState parseState, Charset... charsets)
      Returns the first non-blank character encoding, or returns UTF-8 if they are all blank or in post-parse state. That is, UTF-8 is always returned if parsing has already occurred (since parsing converts content encoding to UTF-8).
      Parameters:
      parseState - document parsing state
      charsets - character encodings to test
      Returns:
      first non-blank, or UTF-8