/** * Convert a String to a byte array using UTF-8 encoding. * * @return the encoded byte array or null if str is null */ public static byte[] utf8ToBytes(final String str) { // UTF-8 should always be supported return encodingToBytes(str, "UTF8"); }
/** * Convert a String to a byte array using UTF-8 encoding. * * @return the encoded byte array or null if str is null */ public static byte[] utf8ToBytes(final String str) { // UTF-8 should always be supported return encodingToBytes(str, "UTF8"); }
/** * Convert a String to a byte array using UTF-8 encoding. * * @return the encoded byte array or null if str is null */ public static byte[] utf8ToBytes(final String str) { // UTF-8 should always be supported return encodingToBytes(str, "UTF8"); }
/** * Convert a String to a byte array using Latin-1 (aka ISO-8859-1) encoding. * If any character in the String is not Latin-1 (meaning it's high 8 bits * are not all zero), then the returned byte array will contain garbage. * Therefore, only use this if you know all your characters are within * Latin-1. * * Note: something is probably wrong if you're using this method. Either * you're dealing with legacy code that doesn't support i18n or you're * using a third-party library that only deals with Latin-1. New code * should (almost) always uses UTF-8 encoding. * * @return the encoded byte array or null if str is null */ public static byte[] latin1ToBytes(final String str) { // ISO-8859-1 should always be supported return encodingToBytes(str, "ISO-8859-1"); }
/** * Convert a String to a byte array using Latin-1 (aka ISO-8859-1) encoding. * If any character in the String is not Latin-1 (meaning it's high 8 bits * are not all zero), then the returned byte array will contain garbage. * Therefore, only use this if you know all your characters are within * Latin-1. * * Note: something is probably wrong if you're using this method. Either * you're dealing with legacy code that doesn't support i18n or you're * using a third-party library that only deals with Latin-1. New code * should (almost) always uses UTF-8 encoding. * * @return the encoded byte array or null if str is null */ public static byte[] latin1ToBytes(final String str) { // ISO-8859-1 should always be supported return encodingToBytes(str, "ISO-8859-1"); }
/** * Convert a String to a byte array using Latin-1 (aka ISO-8859-1) encoding. * If any character in the String is not Latin-1 (meaning it's high 8 bits * are not all zero), then the returned byte array will contain garbage. * Therefore, only use this if you know all your characters are within * Latin-1. * * Note: something is probably wrong if you're using this method. Either * you're dealing with legacy code that doesn't support i18n or you're * using a third-party library that only deals with Latin-1. New code * should (almost) always uses UTF-8 encoding. * * @return the encoded byte array or null if str is null */ public static byte[] latin1ToBytes(final String str) { // ISO-8859-1 should always be supported return encodingToBytes(str, "ISO-8859-1"); }