/** * Convert the given sequence of (pseudo-)utf8 formatted bytes into a String. * * <p>The acceptable input formats are controlled by the STRICTLY_CHECK_FORMAT, ALLOW_NORMAL_UTF8, * and ALLOW_PSEUDO_UTF8 flags. * * @param utf8 (pseudo-)utf8 byte array * @throws UTFDataFormatException if the (pseudo-)utf8 byte array is not valid (pseudo-)utf8 * @return unicode string */ public static String fromUTF8(ByteBuffer utf8) throws UTFDataFormatException { UTF8CharacterVisitor visitor = new ByteBufferStringEncoderVisitor(utf8.remaining()); visitUTF8(utf8, visitor); return visitor.toString(); }
/** * Convert the given sequence of (pseudo-)utf8 formatted bytes into a String hashCode. * * <p>The acceptable input formats are controlled by the STRICTLY_CHECK_FORMAT, ALLOW_NORMAL_UTF8, * and ALLOW_PSEUDO_UTF8 flags. * * @param utf8 (pseudo-)utf8 byte array * @throws UTFDataFormatException if the (pseudo-)utf8 byte array is not valid (pseudo-)utf8 * @return hashCode corresponding to if this were a String.hashCode */ public static int computeStringHashCode(byte[] utf8) throws UTFDataFormatException { StringHashCodeVisitor visitor = new StringHashCodeVisitor(); visitUTF8(utf8, visitor); return visitor.getResult(); }
/** * Convert the given sequence of (pseudo-)utf8 formatted bytes into a String. * * <p>The acceptable input formats are controlled by the STRICTLY_CHECK_FORMAT, ALLOW_NORMAL_UTF8, * and ALLOW_PSEUDO_UTF8 flags. * * @param utf8 (pseudo-)utf8 byte array * @throws UTFDataFormatException if the (pseudo-)utf8 byte array is not valid (pseudo-)utf8 * @return unicode string */ public static String fromUTF8(byte[] utf8) throws UTFDataFormatException { UTF8CharacterVisitor visitor = new ByteArrayStringEncoderVisitor(utf8.length); visitUTF8(utf8, visitor); return visitor.toString(); }