You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/04/15 07:57:37 UTC

svn commit: r1092593 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/NioByteBuffer.java native/shared/nbb.c

Author: mturk
Date: Fri Apr 15 05:57:37 2011
New Revision: 1092593

URL: http://svn.apache.org/viewvc?rev=1092593&view=rev
Log:
Typecheck if ByteBuffer isDirect

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
    commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java?rev=1092593&r1=1092592&r2=1092593&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/NioByteBuffer.java Fri Apr 15 05:57:37 2011
@@ -46,6 +46,8 @@ public final class NioByteBuffer
         throws OutOfMemoryError, IllegalArgumentException;
     private static native ByteBuffer    attach0(long ptr, int len)
         throws OutOfMemoryError;
+    private static native void          free0(ByteBuffer buf)
+        throws NullPointerException;
 
     private static native long addr0(ByteBuffer buf);
     private static native void copy0(ByteBuffer src, int srcPos, ByteBuffer dst,
@@ -107,7 +109,7 @@ public final class NioByteBuffer
         return attach0(ptr.POINTER, (int)ptr.PLENGTH);
     }
 
-    public static native void set0(ByteBuffer buf, int c, int count)
+    private static native void set0(ByteBuffer buf, int c, int count)
         throws NullPointerException;
     /**
      * Set ByteBuffer to specified character.
@@ -124,8 +126,8 @@ public final class NioByteBuffer
         throws NullPointerException, IllegalArgumentException,
         IndexOutOfBoundsException
     {
-        if (buf == null)
-            throw new NullPointerException();
+        if (!buf.isDirect())
+            throw new IllegalArgumentException();
         int ss = buf.capacity();
         if (ss < 1)
             throw new IllegalArgumentException();
@@ -149,8 +151,10 @@ public final class NioByteBuffer
         throws NullPointerException, IllegalArgumentException,
         IndexOutOfBoundsException
     {
-        if (src == null || dst == null)
-            throw new NullPointerException();
+        if (!src.isDirect())
+            throw new IllegalArgumentException();
+        if (!dst.isDirect())
+            throw new IllegalArgumentException();
         int ss = src.capacity();
         int ds = dst.capacity();
         if (ss < 1 || ds < 1)
@@ -180,8 +184,10 @@ public final class NioByteBuffer
         throws NullPointerException, IllegalArgumentException,
         IndexOutOfBoundsException
     {
-        if (src == null || dst == null)
-            throw new NullPointerException();
+        if (!src.isDirect())
+            throw new IllegalArgumentException();
+        if (!dst.isDirect())
+            throw new IllegalArgumentException();
         int ss = src.capacity();
         int ds = dst.capacity();
         if (ss < 1 || ds < 1)
@@ -240,8 +246,8 @@ public final class NioByteBuffer
     public static ByteBuffer allocate(ByteBuffer buf, int offset, int size)
         throws NullPointerException, IllegalArgumentException
     {
-        if (buf == null)
-            throw new NullPointerException();
+        if (!buf.isDirect())
+            throw new IllegalArgumentException();
         long mem = addr0(buf);
         if (mem == 0L)
             throw new NullPointerException();
@@ -272,7 +278,11 @@ public final class NioByteBuffer
      *
      * @throws NullPointerException if {@code buf} is null
      */
-    public static native void free(ByteBuffer buf)
-        throws NullPointerException;
-
+    public static void free(ByteBuffer buf)
+        throws NullPointerException, IllegalArgumentException
+    {
+        if (!buf.isDirect())
+            throw new IllegalArgumentException();
+        free0(buf);
+    }    
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c?rev=1092593&r1=1092592&r2=1092593&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/nbb.c Fri Apr 15 05:57:37 2011
@@ -71,7 +71,7 @@ ACR_JNI_EXPORT(jobject, NioByteBuffer, a
     return (*env)->NewDirectByteBuffer(env, J2P(src, char *), len);
 }
 
-ACR_JNI_EXPORT(void, NioByteBuffer, free)(JNI_STDARGS, jobject bb)
+ACR_JNI_EXPORT(void, NioByteBuffer, free0)(JNI_STDARGS, jobject bb)
 {
     void *mem;