From 00a9ee70054872712017b5a14b19aa92068c8420 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 29 Sep 2014 03:57:30 +0200 Subject: Bug 1080 - Refine MappedByteBuffer*Stream impl. and API [doc], adding stream to stream copy as well as direct memory mapped ByteBuffer access --- src/java/com/jogamp/common/nio/ByteBufferInputStream.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/java/com/jogamp/common/nio/ByteBufferInputStream.java') diff --git a/src/java/com/jogamp/common/nio/ByteBufferInputStream.java b/src/java/com/jogamp/common/nio/ByteBufferInputStream.java index 5b6f121..b74360f 100644 --- a/src/java/com/jogamp/common/nio/ByteBufferInputStream.java +++ b/src/java/com/jogamp/common/nio/ByteBufferInputStream.java @@ -126,10 +126,14 @@ public class ByteBufferInputStream extends InputStream { public final int read(final byte[] b, final int off, final int len) { if (b == null) { throw new NullPointerException(); - } else if (off < 0 || len < 0 || len > b.length - off) { + } else if( off < 0 || + len < 0 || + off > b.length || + off + len > b.length || + off + len < 0 + ) { throw new IndexOutOfBoundsException("offset "+off+", length "+len+", b.length "+b.length); - } - if ( 0 == len ) { + } else if ( 0 == len ) { return 0; } final int totalRem = buf.remaining(); @@ -152,8 +156,7 @@ public class ByteBufferInputStream extends InputStream { throw new NullPointerException(); } else if (len < 0 || len > b.remaining()) { throw new IndexOutOfBoundsException("length "+len+", b "+b); - } - if ( 0 == len ) { + } else if ( 0 == len ) { return 0; } final int remaining = buf.remaining(); -- cgit v1.2.3