From 8022ae51a072f5198409d3c81d9979456676d0cf Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 20 Feb 2014 17:43:34 +0100 Subject: Bug 980: Use Bitsream class for jogamp.common.os.elf.** --- src/java/jogamp/common/os/elf/IOUtils.java | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/java/jogamp/common/os/elf/IOUtils.java') diff --git a/src/java/jogamp/common/os/elf/IOUtils.java b/src/java/jogamp/common/os/elf/IOUtils.java index 8c7bfd1..08bbaa1 100644 --- a/src/java/jogamp/common/os/elf/IOUtils.java +++ b/src/java/jogamp/common/os/elf/IOUtils.java @@ -29,18 +29,19 @@ package jogamp.common.os.elf; import java.io.IOException; import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; + +import com.jogamp.common.os.Platform; +import com.jogamp.common.util.Bitstream; class IOUtils { - static final long MAX_INT_VALUE = ( (long) Integer.MAX_VALUE & 0xffffffffL ) ; + static final long MAX_INT_VALUE = ( Integer.MAX_VALUE & 0xffffffffL ) ; static String toHexString(int i) { return "0x"+Integer.toHexString(i); } static String toHexString(long i) { return "0x"+Long.toHexString(i); } static int shortToInt(short s) { - return (int)s & 0x0000ffff; + return s & 0x0000ffff; } static int long2Int(final long v) { @@ -50,12 +51,6 @@ class IOUtils { return (int)v; } - static void checkBounds(final byte[] sb, final int offset, final int remaining) { - if( offset + remaining > sb.length ) { - throw new IndexOutOfBoundsException("Buffer of size "+sb.length+" cannot hold offset "+offset+" + remaining "+remaining); - } - } - static void readBytes(final RandomAccessFile in, final byte[] out, final int offset, final int len) throws IOException, IllegalArgumentException { @@ -80,9 +75,7 @@ class IOUtils { } static int readInt32(final byte[] in, final int offset) { - checkBounds(in, offset, 4); - final ByteBuffer b = ByteBuffer.wrap(in, offset, 4).order(ByteOrder.nativeOrder()); - return b.asIntBuffer().get(0); + return Bitstream.readInt32(!Platform.isLittleEndian(), in, offset); } /** @@ -95,7 +88,7 @@ class IOUtils { * @throws IndexOutOfBoundsException if offset + remaining > sb.length. */ static String getString(final byte[] sb, final int offset, final int remaining, int[] offset_post) throws IndexOutOfBoundsException { - checkBounds(sb, offset, remaining); + Bitstream.checkBounds(sb, offset, remaining); int strlen = 0; for(; strlen < remaining && sb[strlen + offset] != 0; strlen++) { } final String s = 0 < strlen ? new String(sb, offset, strlen) : "" ; @@ -114,7 +107,7 @@ class IOUtils { * @throws IndexOutOfBoundsException if offset + remaining > sb.length. */ static int getStringCount(final byte[] sb, int offset, final int remaining) throws IndexOutOfBoundsException { - checkBounds(sb, offset, remaining); + Bitstream.checkBounds(sb, offset, remaining); int strnum=0; for(int i=0; i < remaining; i++) { for(; i < remaining && sb[i + offset] != 0; i++) { } -- cgit v1.2.3