summaryrefslogtreecommitdiffstats
path: root/src/java/com/healthmarketscience/jackcess/ByteUtil.java
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2006-09-25 12:49:41 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2006-09-25 12:49:41 +0000
commitc68aa36c48da14ec6db83945d23ee7a4a2803a51 (patch)
treed5189b4ff9291630fb40e871dc59d00f65f87db2 /src/java/com/healthmarketscience/jackcess/ByteUtil.java
parent439d158a9700ccd94b4c0bdfc34b2eefc0fc6688 (diff)
downloadjackcess-c68aa36c48da14ec6db83945d23ee7a4a2803a51.tar.gz
jackcess-c68aa36c48da14ec6db83945d23ee7a4a2803a51.zip
add support for get/put int of different byteorder
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@123 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/ByteUtil.java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/ByteUtil.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/ByteUtil.java b/src/java/com/healthmarketscience/jackcess/ByteUtil.java
index d6a7f67..fdfa9db 100644
--- a/src/java/com/healthmarketscience/jackcess/ByteUtil.java
+++ b/src/java/com/healthmarketscience/jackcess/ByteUtil.java
@@ -132,6 +132,55 @@ public final class ByteUtil {
rtn &= 0xFFFFFF;
return rtn;
}
+
+ /**
+ * @return an int from the current position in the given buffer, read using
+ * the given ByteOrder
+ */
+ public static int getInt(ByteBuffer buffer, ByteOrder order) {
+ int offset = buffer.position();
+ int rtn = getInt(buffer, offset, order);
+ buffer.position(offset + 4);
+ return rtn;
+ }
+
+ /**
+ * @return an int from the given position in the given buffer, read using
+ * the given ByteOrder
+ */
+ public static int getInt(ByteBuffer buffer, int offset, ByteOrder order) {
+ ByteOrder origOrder = buffer.order();
+ try {
+ return buffer.order(order).getInt(offset);
+ } finally {
+ buffer.order(origOrder);
+ }
+ }
+
+ /**
+ * Writes an int at the current position in the given buffer, using the
+ * given ByteOrder
+ */
+ public static void putInt(ByteBuffer buffer, int val, ByteOrder order) {
+ int offset = buffer.position();
+ putInt(buffer, val, offset, order);
+ buffer.position(offset + 4);
+ }
+
+ /**
+ * Writes an int at the given position in the given buffer, using the
+ * given ByteOrder
+ */
+ public static void putInt(ByteBuffer buffer, int val, int offset,
+ ByteOrder order)
+ {
+ ByteOrder origOrder = buffer.order();
+ try {
+ buffer.order(order).putInt(offset, val);
+ } finally {
+ buffer.order(origOrder);
+ }
+ }
/**
* Convert a byte buffer to a hexadecimal string for display