From 6b500b7dbf54df647fad11bf640785e914e9e5c5 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 14 Oct 2010 02:22:49 +0000 Subject: minor refactor git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@485 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/java/com/healthmarketscience/jackcess/Column.java | 11 ++++++----- src/java/com/healthmarketscience/jackcess/Index.java | 16 +++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/java/com/healthmarketscience/jackcess/Column.java b/src/java/com/healthmarketscience/jackcess/Column.java index 71fb379..a0391e7 100644 --- a/src/java/com/healthmarketscience/jackcess/Column.java +++ b/src/java/com/healthmarketscience/jackcess/Column.java @@ -454,7 +454,7 @@ public class Column implements Comparable { * @return The deserialized Object */ public Object read(byte[] data) throws IOException { - return read(data, ByteOrder.LITTLE_ENDIAN); + return read(data, PageChannel.DEFAULT_BYTE_ORDER); } /** @@ -516,8 +516,8 @@ public class Column implements Comparable { private byte[] readLongValue(byte[] lvalDefinition) throws IOException { - ByteBuffer def = ByteBuffer.wrap(lvalDefinition); - def.order(ByteOrder.LITTLE_ENDIAN); + ByteBuffer def = ByteBuffer.wrap(lvalDefinition) + .order(PageChannel.DEFAULT_BYTE_ORDER); int length = ByteUtil.get3ByteInt(def); // bail out gracefully here as we don't understand the format if (length < 0) @@ -1047,14 +1047,15 @@ public class Column implements Comparable { } /** - * Serialize an Object into a raw byte value for this column in little endian order + * Serialize an Object into a raw byte value for this column in little + * endian order * @param obj Object to serialize * @return A buffer containing the bytes */ public ByteBuffer write(Object obj, int remainingRowLength) throws IOException { - return write(obj, remainingRowLength, ByteOrder.LITTLE_ENDIAN); + return write(obj, remainingRowLength, PageChannel.DEFAULT_BYTE_ORDER); } /** diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 32e1b42..2c0645c 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -82,6 +82,8 @@ public abstract class Index implements Comparable { private static final int MAX_TEXT_INDEX_CHAR_LENGTH = (JetFormat.TEXT_FIELD_MAX_LENGTH / JetFormat.TEXT_FIELD_UNIT_SIZE); + + private static final ByteOrder ENTRY_BYTE_ORDER = ByteOrder.BIG_ENDIAN; /** type attributes for Entries which simplify comparisons */ public enum EntryType { @@ -815,7 +817,7 @@ public abstract class Index implements Comparable { List entries = new ArrayList(); TempBufferHolder tmpEntryBufferH = TempBufferHolder.newHolder(TempBufferHolder.Type.HARD, true, - ByteOrder.BIG_ENDIAN); + ENTRY_BYTE_ORDER); Entry prevEntry = FIRST_ENTRY; for (int i = 0; i < entryMaskLength; i++) { @@ -1027,7 +1029,7 @@ public abstract class Index implements Comparable { throws IOException { // always write in big endian order - return column.write(value, 0, ByteOrder.BIG_ENDIAN).array(); + return column.write(value, 0, ENTRY_BYTE_ORDER).array(); } /** @@ -1759,7 +1761,7 @@ public abstract class Index implements Comparable { buffer.get(_entryBytes); // read the rowId - int page = ByteUtil.get3ByteInt(buffer, ByteOrder.BIG_ENDIAN); + int page = ByteUtil.get3ByteInt(buffer, ENTRY_BYTE_ORDER); int row = ByteUtil.getUnsignedByte(buffer); _rowId = new RowId(page, row); @@ -1811,7 +1813,7 @@ public abstract class Index implements Comparable { buffer.put(_entryBytes, prefix.length, (_entryBytes.length - prefix.length)); ByteUtil.put3ByteInt(buffer, getRowId().getPageNumber(), - ByteOrder.BIG_ENDIAN); + ENTRY_BYTE_ORDER); } else if(prefix.length <= (_entryBytes.length + 3)) { @@ -1819,7 +1821,7 @@ public abstract class Index implements Comparable { // and copy last bytes to output buffer ByteBuffer tmp = ByteBuffer.allocate(3); ByteUtil.put3ByteInt(tmp, getRowId().getPageNumber(), - ByteOrder.BIG_ENDIAN); + ENTRY_BYTE_ORDER); tmp.flip(); tmp.position(prefix.length - _entryBytes.length); buffer.put(tmp); @@ -1935,7 +1937,7 @@ public abstract class Index implements Comparable { // we need 4 trailing bytes for the sub-page number super(buffer, entryLen, 4); - _subPageNumber = ByteUtil.getInt(buffer, ByteOrder.BIG_ENDIAN); + _subPageNumber = ByteUtil.getInt(buffer, ENTRY_BYTE_ORDER); } @Override @@ -1957,7 +1959,7 @@ public abstract class Index implements Comparable { @Override protected void write(ByteBuffer buffer, byte[] prefix) throws IOException { super.write(buffer, prefix); - ByteUtil.putInt(buffer, _subPageNumber, ByteOrder.BIG_ENDIAN); + ByteUtil.putInt(buffer, _subPageNumber, ENTRY_BYTE_ORDER); } @Override -- cgit v1.2.3