code: @SuppressWarnings("unchecked")
      public static <D extends Number> D valueOf(Class < D > clazz,
              ByteBuffer bb, int fractionDigits) {
          if (clazz.equals(Short.class)) {
              return (D) Short.valueOf(bb.getShort());
          } else if (clazz.equals(Integer.class)) {
              return (D) Integer.valueOf(bb.getInt());
          } else if (clazz.equals(Long.class)) {
              return (D) Long.valueOf(bb.getLong());
          } else if (clazz.equals(BigDecimal.class)) {
              if (bb.capacity() <= 8) {
                  return (D) BigDecimal.valueOf(bb.getLong(), fractionDigits);
              } else {
                  return (D) new BigDecimal(new BigInteger(bb.array()),
                          fractionDigits);
              }
          }
          if (clazz.equals(BigInteger.class)) {
              return (D) new BigInteger(bb.array());
          } else {
              throw new IllegalArgumentException("Unsupported java type " + clazz);
          }
  
      }
docs: Given a byte buffer containing the 2's complement representation of an
  unscaled numeric, convert that to the target java Number type.
  <p/>
  Note that there is an assumption that the byte buffer contains at least 8
  
  @param clazz the java Number type
  @param bb byte buffer containing the 2's complement representation of an
  unscaled numeric
  @param fractionDigits the number of fraction digits in the COBOL type
  @return java Number type corresponding to byte content