From 8a086d64b784a7720ea9a1783fceb9cfd48a0722 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Mon, 18 Sep 2006 16:38:46 +0000 Subject: [PATCH] honor endianness when reading currency values git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@112 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../com/healthmarketscience/jackcess/Column.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index baa48c3..7ed8d35 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -310,7 +310,7 @@ public class Column implements Comparable { } else if (_type == DataType.TEXT) { return decodeTextValue(data); } else if (_type == DataType.MONEY) { - return readCurrencyValue(data); + return readCurrencyValue(buffer); } else if (_type == DataType.OLE) { if (data.length > 0) { return readLongBinaryValue(data); @@ -449,20 +449,18 @@ public class Column implements Comparable { /** * Decodes "Currency" values. * - * @param lvalDefinition Column value that points to an LVAL record + * @param valueBytes Column value that points to currency data * @return BigDecimal representing the monetary value * @throws IOException if the value cannot be parsed */ - private BigDecimal readCurrencyValue(byte[] lvalDefinition) + private BigDecimal readCurrencyValue(ByteBuffer buffer) throws IOException { - if(lvalDefinition.length != 8) { + if(buffer.remaining() != 8) { throw new IOException("Invalid money value."); } - ByteBuffer def = ByteBuffer.wrap(lvalDefinition); - def.order(ByteOrder.LITTLE_ENDIAN); - return new BigDecimal(BigInteger.valueOf(def.getLong(0)), 4); + return new BigDecimal(BigInteger.valueOf(buffer.getLong(0)), 4); } /** -- 2.39.5