From 9bf512d9219c13a0f1a541eeae773144a06aa18a Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Sun, 25 Apr 2010 19:51:11 +0000 Subject: [PATCH] add: NativeData.getNativeByteOrder() SVN: 15627 --- base/source/c/compile_windows_i386.mak | 2 +- base/source/c/compile_windows_x64.mak | 4 ++-- base/source/c/copyCommon.c | 11 +++++++++++ .../ch/systemsx/cisd/base/convert/NativeData.java | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/base/source/c/compile_windows_i386.mak b/base/source/c/compile_windows_i386.mak index 43a64307748..358d8889872 100644 --- a/base/source/c/compile_windows_i386.mak +++ b/base/source/c/compile_windows_i386.mak @@ -9,7 +9,7 @@ VCPPDIR=C:\Program Files\Microsoft Visual Studio 8\VC # Directory where JDK is installed (We require JDK 1.5 or above), for example -JAVADIR=C:\Program Files\Java\jdk1.5.0_15 +JAVADIR=C:\Program Files\Java\jdk1.5.0_22 # Common parent directory PARENTDIR=C:\nativeData diff --git a/base/source/c/compile_windows_x64.mak b/base/source/c/compile_windows_x64.mak index aebd972d566..111b06c1493 100644 --- a/base/source/c/compile_windows_x64.mak +++ b/base/source/c/compile_windows_x64.mak @@ -6,10 +6,10 @@ #============================================================================ # Visual C++ directory, for example -VCPPDIR=C:\Program Files\Microsoft Visual Studio 8\VC +VCPPDIR=C:\Program Files (x86)\Microsoft Visual Studio 8\VC # Directory where JDK is installed (We require JDK 1.5 or above), for example -JAVADIR=C:\Program Files\Java\jdk1.5.0_15 +JAVADIR=C:\Program Files\Java\jdk1.5.0_22 # Common parent directory PARENTDIR=C:\nativeData diff --git a/base/source/c/copyCommon.c b/base/source/c/copyCommon.c index 64fa05a76ee..2c628232e17 100755 --- a/base/source/c/copyCommon.c +++ b/base/source/c/copyCommon.c @@ -20,6 +20,17 @@ extern "C" { #include <stdio.h> #include "jni.h" +/* + * public static native boolean isLittleEndian(); + */ +JNIEXPORT jboolean JNICALL Java_ch_systemsx_cisd_base_convert_NativeData_isLittleEndian +(JNIEnv *env, + jclass clss + ) +{ + return MACHINE_BYTE_ORDER == 1; +} + /* * A fatal error in a JNI call * Create and throw an 'InternalError' diff --git a/base/source/java/ch/systemsx/cisd/base/convert/NativeData.java b/base/source/java/ch/systemsx/cisd/base/convert/NativeData.java index bfe67feffb8..751f7f025c2 100644 --- a/base/source/java/ch/systemsx/cisd/base/convert/NativeData.java +++ b/base/source/java/ch/systemsx/cisd/base/convert/NativeData.java @@ -66,6 +66,12 @@ public class NativeData BIG_ENDIAN, } + /** + * Returns <code>true</code> if this platform is a little-endian platform and <code>false</code> + * , if it is a big-endian platform. + */ + static native boolean isLittleEndian(); + /** * Copies a range from an array of <code>int</code> into an array of <code>byte</code>. * @@ -234,6 +240,14 @@ public class NativeData public static void ensureNativeLibIsLoaded() { } + + /** + * Returns the native byte order of the host running this JRE. + */ + public static ByteOrder getNativeByteOrder() + { + return isLittleEndian() ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN; + } /** * Converts a <code>byte[]</code> array into a <code>short[]</code> array. -- GitLab