public static long toLong(byte[] bytes) { checkBytesNotNull(bytes); return toLong(bytes, 0, bytes.length); }
public static long toLong(byte[] bytes) { checkBytesNotNull(bytes); return toLong(bytes, 0, bytes.length); }
/** * Attempts to get the underlying value as a long. 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 8, then it cannot be * converted to a long. * @return The byte array value as a long * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a long. */ public long getValueAsLong() throws TlvConvertException { try { return ByteArrayUtil.toLong(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("long", e.getMessage()); } }
/** * Attempts to get the underlying value as a long. 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 8, then it cannot be * converted to a long. * @return The byte array value as a long * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a long. */ public long getValueAsLong() throws TlvConvertException { try { return ByteArrayUtil.toLong(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("long", e.getMessage()); } }
/** * Attempts to get the underlying value as a long. 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 8, then it cannot be * converted to a long. * @return The byte array value as a long * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a long. */ public long getValueAsLong() throws TlvConvertException { try { return ByteArrayUtil.toLong(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("long", e.getMessage()); } }
/** * Attempts to get the underlying value as a long. 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 8, then it cannot be * converted to a long. * @return The byte array value as a long * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a long. */ public long getValueAsLong() throws TlvConvertException { try { return ByteArrayUtil.toLong(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("long", 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()); } }