public static int toInt(byte[] bytes) { checkBytesNotNull(bytes); return toInt(bytes, 0, bytes.length); }
public static int toInt(byte[] bytes) { checkBytesNotNull(bytes); return toInt(bytes, 0, bytes.length); }
/** * Attempts to get the underlying value as an int. If the underlying byte * array cannot be converted, then an exception is thrown. For example, * if the underlying byte array isn't a length of 4, then it cannot be * converted to an int. * @return The byte array value as an int * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an int. */ public int getValueAsInt() throws TlvConvertException { try { return ByteArrayUtil.toInt(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("int", e.getMessage()); } }
/** * Attempts to get the underlying value as an int. If the underlying byte * array cannot be converted, then an exception is thrown. For example, * if the underlying byte array isn't a length of 4, then it cannot be * converted to an int. * @return The byte array value as an int * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an int. */ public int getValueAsInt() throws TlvConvertException { try { return ByteArrayUtil.toInt(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("int", e.getMessage()); } }
/** * Attempts to get the underlying value as an int. If the underlying byte * array cannot be converted, then an exception is thrown. For example, * if the underlying byte array isn't a length of 4, then it cannot be * converted to an int. * @return The byte array value as an int * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an int. */ public int getValueAsInt() throws TlvConvertException { try { return ByteArrayUtil.toInt(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("int", e.getMessage()); } }
/** * Attempts to get the underlying value as an int. If the underlying byte * array cannot be converted, then an exception is thrown. For example, * if the underlying byte array isn't a length of 4, then it cannot be * converted to an int. * @return The byte array value as an int * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an int. */ public int getValueAsInt() throws TlvConvertException { try { return ByteArrayUtil.toInt(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("int", 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(), 8); byte[] bytes = HexUtil.toByteArray(hex); return ByteArrayUtil.toInt(bytes); } else { return Integer.parseInt(result.getNumber()); } } catch (NumberFormatException e) { throw new ConversionException(e.getMessage()); } }