boolean negative = (decVal.compareTo(BigDecimal.ZERO) < 0); if(negative) { decVal = decVal.negate();
boolean negative = (decVal.compareTo(BigDecimal.ZERO) < 0); if(negative) { decVal = decVal.negate(); }   buffer.put(negative ? (byte)1 : (byte)0);    decVal = decVal.setScale(getScale());   if(decVal.precision() > getPrecision()) { throw new IOException("Numeric value is too big for specified precision " + getPrecision() + ": " + decVal); }   byte[] intValBytes = decVal.unscaledValue().toByteArray(); if(intValBytes.length > 16) { throw new IOException("Too many bytes for valid BigInteger?"); } if(intValBytes.length < 16) { byte[] tmpBytes = new byte[16]; System.arraycopy(intValBytes, 0, tmpBytes, (16 - intValBytes.length), intValBytes.length); intValBytes = tmpBytes; } if(buffer.order() != ByteOrder.BIG_ENDIAN) { fixNumericByteOrder(intValBytes); } buffer.put(intValBytes); } catch(ArithmeticException e) { throw (IOException) new IOException("Numeric value out of range").initCause(e);
  private void writeNumericValue(ByteBuffer buffer, Object value)    throws IOException  {    BigDecimal decVal = toBigDecimal(value);    boolean negative = (decVal.compareTo(BigDecimal.ZERO) < 0);    if(negative) {      decVal = decVal.negate();    }    // write sign byte    buffer.put(negative ? (byte)1 : (byte)0);    // adjust scale according to this column type (this will throw if number    // has too many decimal places)    decVal = decVal.setScale(getScale());    // check precision    if(decVal.precision() > getPrecision()) {      throw new IOException("Numeric value is too big for specified precision "                            + getPrecision() + ": " + decVal);    }        // convert to unscaled BigInteger, big-endian bytes    byte[] intValBytes = decVal.unscaledValue().toByteArray();    if(intValBytes.length > 16) {      throw new IOException("Too many bytes for valid BigInteger?");    }    if(intValBytes.length < 16) {      byte[] tmpBytes = new byte[16];      System.arraycopy(intValBytes, 0, tmpBytes, (16 - intValBytes.length),                       intValBytes.length);      intValBytes = tmpBytes;    }    if(buffer.order() != ByteOrder.BIG_ENDIAN) {      fixNumericByteOrder(intValBytes);    }    buffer.put(intValBytes);  }