Class EncodingUtil


  • public class EncodingUtil
    extends org.apache.commons.lang3.StringUtils
    • Field Summary

      • Fields inherited from class org.apache.commons.lang3.StringUtils

        CR, EMPTY, INDEX_NOT_FOUND, LF, SPACE
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static String asHex​(byte[] binaryData)
      Encodes the specified binary data into a String representing the hexadecimal values of each byte in order.
      static String detectStringEncoding​(byte[] data, String declaredEncoding)
      Method for trying to detect encoding.
      static byte[] fromHex​(String hexText)
      Decodes the specified text with hexadecimal values in bytes of those same values.
      • Methods inherited from class org.apache.commons.lang3.StringUtils

        abbreviate, abbreviate, abbreviate, abbreviate, abbreviateMiddle, appendIfMissing, appendIfMissingIgnoreCase, capitalize, center, center, center, chomp, chomp, chop, compare, compare, compareIgnoreCase, compareIgnoreCase, contains, contains, containsAny, containsAny, containsAny, containsAnyIgnoreCase, containsIgnoreCase, containsNone, containsNone, containsOnly, containsOnly, containsWhitespace, countMatches, countMatches, defaultIfBlank, defaultIfEmpty, defaultString, defaultString, deleteWhitespace, difference, endsWith, endsWithAny, endsWithIgnoreCase, equals, equalsAny, equalsAnyIgnoreCase, equalsIgnoreCase, firstNonBlank, firstNonEmpty, getBytes, getBytes, getCommonPrefix, getDigits, getFuzzyDistance, getIfBlank, getIfEmpty, getJaroWinklerDistance, getLevenshteinDistance, getLevenshteinDistance, indexOf, indexOf, indexOf, indexOf, indexOfAny, indexOfAny, indexOfAny, indexOfAnyBut, indexOfAnyBut, indexOfDifference, indexOfDifference, indexOfIgnoreCase, indexOfIgnoreCase, isAllBlank, isAllEmpty, isAllLowerCase, isAllUpperCase, isAlpha, isAlphanumeric, isAlphanumericSpace, isAlphaSpace, isAnyBlank, isAnyEmpty, isAsciiPrintable, isBlank, isEmpty, isMixedCase, isNoneBlank, isNoneEmpty, isNotBlank, isNotEmpty, isNumeric, isNumericSpace, isWhitespace, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, join, joinWith, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexOfAny, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, lastOrdinalIndexOf, left, leftPad, leftPad, leftPad, length, lowerCase, lowerCase, mid, normalizeSpace, ordinalIndexOf, overlay, prependIfMissing, prependIfMissingIgnoreCase, remove, remove, removeAll, removeEnd, removeEndIgnoreCase, removeFirst, removeIgnoreCase, removePattern, removeStart, removeStartIgnoreCase, repeat, repeat, repeat, replace, replace, replaceAll, replaceChars, replaceChars, replaceEach, replaceEachRepeatedly, replaceFirst, replaceIgnoreCase, replaceIgnoreCase, replaceOnce, replaceOnceIgnoreCase, replacePattern, reverse, reverseDelimited, right, rightPad, rightPad, rightPad, rotate, split, split, split, split, splitByCharacterType, splitByCharacterTypeCamelCase, splitByWholeSeparator, splitByWholeSeparator, splitByWholeSeparatorPreserveAllTokens, splitByWholeSeparatorPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, splitPreserveAllTokens, startsWith, startsWithAny, startsWithIgnoreCase, strip, strip, stripAccents, stripAll, stripAll, stripEnd, stripStart, stripToEmpty, stripToNull, substring, substring, substringAfter, substringAfter, substringAfterLast, substringAfterLast, substringBefore, substringBefore, substringBeforeLast, substringBetween, substringBetween, substringsBetween, swapCase, toCodePoints, toEncodedString, toRootLowerCase, toRootUpperCase, toString, trim, trimToEmpty, trimToNull, truncate, truncate, uncapitalize, unwrap, unwrap, upperCase, upperCase, valueOf, wrap, wrap, wrapIfMissing, wrapIfMissing
    • Method Detail

      • detectStringEncoding

        public static String detectStringEncoding​(byte[] data,
                                                  String declaredEncoding)
                                           throws UnsupportedEncodingException
        Method for trying to detect encoding.
        Parameters:
        data - some data to try to detect the encoding.
        declaredEncoding - expected encoding.
        Returns:
        the detected encoding.
        Throws:
        UnsupportedEncodingException
      • fromHex

        public static byte[] fromHex​(String hexText)
                              throws ParseException
        Decodes the specified text with hexadecimal values in bytes of those same values. The text is considered to be in the UTF-8 charset.
        Parameters:
        hexText - the text with hexadecimal-based characters.
        Returns:
        the binary representation of the text.
        Throws:
        ParseException - if an odd number or illegal of characters is supplied.
      • asHex

        public static String asHex​(byte[] binaryData)
        Encodes the specified binary data into a String representing the hexadecimal values of each byte in order. The String is in the UTF-8 charset.
        Parameters:
        binaryData - the binary data to concert in hexadecimal-based String.
        Returns:
        a String representation of the binary data in Hexadecimal characters.