From: James Ahlborn Date: Mon, 25 Sep 2006 12:49:41 +0000 (+0000) Subject: add support for get/put int of different byteorder X-Git-Tag: rel_1_1_7~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c68aa36c48da14ec6db83945d23ee7a4a2803a51;p=jackcess.git 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 --- 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