Code example for BufferUnderflowException

0
		int len = b[offset + 1];
		if (len != 6)
			throw new IllegalArgumentException("invalid length (should be 6): " + len);
 
		if (len > length)
			throw new BufferUnderflowException();
 
		ByteBuffer bb = ByteBuffer.wrap(b);
		bb.position(offset + 2);
		return bb.getInt();
	} 
 
	public static InetAddress decodeIp(byte[] b, int offset, int length) throws UnknownHostException {
		int len = b[offset + 1];
		if (len != 6)
			throw new IllegalArgumentException("invalid length (should be 6): " + len);
 
		if (len > length)
			throw new BufferUnderflowException();