public byte[] hexStringToByteArray(String s) { return HexUtil.toByteArray(s); }
/** * Converts from a hex string like "FF" to a byte[]. * @param string0 The string containing the hex-encoded data. * @return * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence) */ @Deprecated public static byte[] fromHexString(String hexString) { return HexUtil.toByteArray(hexString); }
/** * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence, int, int) */ @Deprecated public static byte[] toHexByte(String hexString, int offset, int length) { return HexUtil.toByteArray(hexString, offset, length); }
/** * Convert a hexidecimal string generated by toHexString() back into a byte array. * @param s String to convert * @param offset starting character (zero based) to convert. * @param length number of characters to convert. * @return the converted byte array. Returns null if the length is not a multiple of 2. * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence, int, int) */ @Deprecated public static byte[] fromHexString(String hexString, int offset, int length) { return HexUtil.toByteArray(hexString, offset, length); }
/** * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence, int, int) */ @Deprecated public static byte[] toHexByte(String hexString, int offset, int length) { return HexUtil.toByteArray(hexString, offset, length); }
/** * Convert a hexidecimal string generated by toHexString() back into a byte array. * @param s String to convert * @param offset starting character (zero based) to convert. * @param length number of characters to convert. * @return the converted byte array. Returns null if the length is not a multiple of 2. * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence, int, int) */ @Deprecated public static byte[] fromHexString(String hexString, int offset, int length) { return HexUtil.toByteArray(hexString, offset, length); }
/** * Converts from a hex string like "FF" to a byte[]. * @param string0 The string containing the hex-encoded data. * @return * @deprecated Please use new utility class HexUtil * @see HexUtil#toByteArray(java.lang.CharSequence) */ @Deprecated public static byte[] fromHexString(String hexString) { return HexUtil.toByteArray(hexString); }
/** * Creates a byte array from a CharSequence (String, StringBuilder, etc.) * containing only valid hexidecimal formatted characters. * Each grouping of 2 characters represent a byte in "Big Endian" format. * The hex CharSequence must be an even length of characters. For example, a String * of "1234" would return the byte array { 0x12, 0x34 }. * @param hexString The String, StringBuilder, etc. that contains the * sequence of hexidecimal character values. * @return A new byte array representing the sequence of bytes created from * the sequence of hexidecimal characters. If the hexString is null, * then this method will return null. */ public static byte[] toByteArray(CharSequence hexString) { if (hexString == null) { return null; } return toByteArray(hexString, 0, hexString.length()); }
/** * Creates a byte array from a CharSequence (String, StringBuilder, etc.) * containing only valid hexidecimal formatted characters. * Each grouping of 2 characters represent a byte in "Big Endian" format. * The hex CharSequence must be an even length of characters. For example, a String * of "1234" would return the byte array { 0x12, 0x34 }. * @param hexString The String, StringBuilder, etc. that contains the * sequence of hexidecimal character values. * @return A new byte array representing the sequence of bytes created from * the sequence of hexidecimal characters. If the hexString is null, * then this method will return null. */ public static byte[] toByteArray(CharSequence hexString) { if (hexString == null) { return null; } return toByteArray(hexString, 0, hexString.length()); }
/** * Decodes the string data (in hex) into a byte array. * @param width The width of the hex encoding (2 or 4) * @deprecated Please see class HexUtil */ @Deprecated public static byte[] decodeHex(String hexString, int width) { return HexUtil.toByteArray(hexString); /** // the resulting string StringBuffer result = new StringBuffer(); // just cycle through the whole string two chars at a time for (int i = 0; i < data.length(); i += width) { result.append((char) Integer.parseInt(data.substring(i, i + width), 16)); } // return whats rightfully the user's try { return result.toString().getBytes("ISO-8859-1"); } catch (Exception e) { // should never happen } return null; */ }
/** * Decodes the string data (in hex) into a byte array. * @param width The width of the hex encoding (2 or 4) * @deprecated Please see class HexUtil */ @Deprecated public static byte[] decodeHex(String hexString, int width) { return HexUtil.toByteArray(hexString); /** // the resulting string StringBuffer result = new StringBuffer(); // just cycle through the whole string two chars at a time for (int i = 0; i < data.length(); i += width) { result.append((char) Integer.parseInt(data.substring(i, i + width), 16)); } // return whats rightfully the user's try { return result.toString().getBytes("ISO-8859-1"); } catch (Exception e) { // should never happen } return null; */ }
private static HexString createHexString(String hex) { // though method is private, leaving checks in place to show intent if (hex == null) { throw new IllegalArgumentException("hex string argument cannot be null; use HexString.NULL instead"); } else if (hex.equals("")) { throw new IllegalArgumentException("hex string argument cannot be empty; use HexString.NULL instead"); } byte[] bytes = toByteArray(hex); return new HexString(bytes, hex.toUpperCase()); }
private static HexString createHexString(String hex) { // though method is private, leaving checks in place to show intent if (hex == null) { throw new IllegalArgumentException("hex string argument cannot be null; use HexString.NULL instead"); } else if (hex.equals("")) { throw new IllegalArgumentException("hex string argument cannot be empty; use HexString.NULL instead"); } byte[] bytes = toByteArray(hex); return new HexString(bytes, hex.toUpperCase()); }
byte[] bytes = HexUtil.toByteArray(chunk.toString());
byte[] bytes = HexUtil.toByteArray(chunk.toString());
@Override public Object convert(String value) throws ConversionException { NumberRadixResult result = NumberRadixUtil.parseNumberRadix(value); try { if (result.getRadix() == 16) { String hex = NumberRadixUtil.normalizeLeadingHexZeroes(result.getNumber(), 8); byte[] bytes = HexUtil.toByteArray(hex); return ByteArrayUtil.toInt(bytes); } else { return Integer.parseInt(result.getNumber()); } } catch (NumberFormatException e) { throw new ConversionException(e.getMessage()); } }
@Override public Object convert(String value) throws ConversionException { NumberRadixResult result = NumberRadixUtil.parseNumberRadix(value); try { if (result.getRadix() == 16) { String hex = NumberRadixUtil.normalizeLeadingHexZeroes(result.getNumber(), 4); byte[] bytes = HexUtil.toByteArray(hex); return ByteArrayUtil.toShort(bytes); } else { return Short.parseShort(result.getNumber()); } } catch (NumberFormatException e) { throw new ConversionException(e.getMessage()); } }
@Override public Object convert(String value) throws ConversionException { NumberRadixResult result = NumberRadixUtil.parseNumberRadix(value); try { if (result.getRadix() == 16) { String hex = NumberRadixUtil.normalizeLeadingHexZeroes(result.getNumber(), 2); byte[] bytes = HexUtil.toByteArray(hex); return ByteArrayUtil.toByte(bytes); } else { return Byte.parseByte(result.getNumber()); } } catch (NumberFormatException e) { throw new ConversionException(e.getMessage()); } }
@Override public Object convert(String value) throws ConversionException { NumberRadixResult result = NumberRadixUtil.parseNumberRadix(value); try { if (result.getRadix() == 16) { String hex = NumberRadixUtil.normalizeLeadingHexZeroes(result.getNumber(), 16); byte[] bytes = HexUtil.toByteArray(hex); return ByteArrayUtil.toLong(bytes); } else { // special handling of longs with a TimeUnit ending TimeUnitUtil.Result timeResult = TimeUnitUtil.parse(result.getNumber()); if (timeResult != null) { long l = Long.parseLong(timeResult.getNumber()); long ms = TimeUnit.MILLISECONDS.convert(l, timeResult.getTimeUnit()); return ms; } else { return Long.parseLong(result.getNumber()); } } } catch (NumberFormatException e) { throw new ConversionException(e.getMessage()); } }