public static byte toByte(byte[] bytes) { checkBytesNotNull(bytes); return toByte(bytes, 0, bytes.length); }
public static int toInt(byte[] bytes) { checkBytesNotNull(bytes); return toInt(bytes, 0, bytes.length); }
public static long toLong(byte[] bytes) { checkBytesNotNull(bytes); return toLong(bytes, 0, bytes.length); }
public static short toShort(byte[] bytes) { checkBytesNotNull(bytes); return toShort(bytes, 0, bytes.length); }
/** * Attempts to get the underlying value as a byte. 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 1, then it cannot be * converted to a byte. * @return The byte array value as a byte * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a byte. */ public byte getValueAsByte() throws TlvConvertException { try { return ByteArrayUtil.toByte(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("byte", e.getMessage()); } }
/** * Attempts to get the underlying value as a short. 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 2, then it cannot be * converted to a short. * @return The byte array value as a short * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a short. */ public short getValueAsShort() throws TlvConvertException { try { return ByteArrayUtil.toShort(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("short", 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 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 an unsigned short. 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 2, then it cannot be * converted to an unsigned short. * @return The byte array value as an unsigned short * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an unsigned short. */ public int getValueAsUnsignedShort() throws TlvConvertException { try { return ByteArrayUtil.toUnsignedShort(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("unsigned short", e.getMessage()); } }
/** * Attempts to get the underlying value as an unsigned 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 unsigned int. * @return The byte array value as an unsigned int * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an unsigned int. */ public long getValueAsUnsignedInt() throws TlvConvertException { try { return ByteArrayUtil.toUnsignedInt(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("unsigned int", e.getMessage()); } }
/** * Attempts to get the underlying value as an unsigned byte. 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 1, then it cannot be * converted to an unsigned byte. * @return The byte array value as an unsigned byte * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to an unsigned byte. */ public short getValueAsUnsignedByte() throws TlvConvertException { try { return ByteArrayUtil.toUnsignedByte(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("unsigned byte", e.getMessage()); } }
public static short toUnsignedByte(byte[] bytes) { checkBytesNotNull(bytes); return toUnsignedByte(bytes, 0, bytes.length); }
public static int toUnsignedShort(byte[] bytes) { checkBytesNotNull(bytes); return toUnsignedShort(bytes, 0, bytes.length); }
public static long toUnsignedInt(byte[] bytes) { checkBytesNotNull(bytes); return toUnsignedInt(bytes, 0, bytes.length); }
public static short toUnsignedByte(byte[] bytes, int offset, int length) { checkBytes(bytes, offset, length, 1); short v = 0; v |= bytes[offset] & 0xFF; return v; }
protected static void checkBytes(byte[] bytes, int offset, int length, int expectedLength) { checkBytesNotNull(bytes); ByteBuffer.checkOffsetLength(bytes.length, offset, length); if (length != expectedLength) { throw new IllegalArgumentException("Unexpected length of byte array [expected=" + expectedLength + ", actual=" + length + "]"); } }
/** * Attempts to get the underlying value as a byte. 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 1, then it cannot be * converted to a byte. * @return The byte array value as a byte * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a byte. */ public byte getValueAsByte() throws TlvConvertException { try { return ByteArrayUtil.toByte(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("byte", e.getMessage()); } }
/** * Attempts to get the underlying value as a short. 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 2, then it cannot be * converted to a short. * @return The byte array value as a short * @throws TlvConvertException Thrown if the underlying byte array cannot * be converted to a short. */ public short getValueAsShort() throws TlvConvertException { try { return ByteArrayUtil.toShort(this.value); } catch (IllegalArgumentException e) { throw new TlvConvertException("short", 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 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()); } }