qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1442057 - in /qpid/proton/trunk/proton-c/bindings/java: java.i src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
Date Mon, 04 Feb 2013 09:42:13 GMT
Author: rgodfrey
Date: Mon Feb  4 09:42:13 2013
New Revision: 1442057

URL: http://svn.apache.org/viewvc?rev=1442057&view=rev
Log:
PROTON-192: Update JNI Binding to handle byte[] containing nulls

Modified:
    qpid/proton/trunk/proton-c/bindings/java/java.i
    qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java

Modified: qpid/proton/trunk/proton-c/bindings/java/java.i
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/java.i?rev=1442057&r1=1442056&r2=1442057&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/java.i (original)
+++ qpid/proton/trunk/proton-c/bindings/java/java.i Mon Feb  4 09:42:13 2013
@@ -349,6 +349,22 @@ JNIEXPORT jbyteArray JNICALL Java_org_ap
 }
 %}
 
+%native (pn_bytes_from_array) void pn_bytes_from_array(pn_bytes_t, jbyteArray);
+%{
+JNIEXPORT void JNICALL Java_org_apache_qpid_proton_jni_ProtonJNI_pn_1bytes_1from_1array(JNIEnv
*jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray byteArr)
+{
+    pn_bytes_t* b = *(pn_bytes_t **)&jarg1;
+    size_t sz = (*jenv)->GetArrayLength(jenv, byteArr);
+    if(b->start) free(b->start);
+    
+    jbyte* barr = (*jenv)->GetByteArrayElements(jenv, byteArr, NULL);
+    b->size = sz;
+    b->start = malloc(sz);
+    memcpy(b->start, barr, sz);
+    (*jenv)->ReleaseByteArrayElements(jenv, byteArr, barr, 0);
+}
+%}
+
 
 
 ssize_t  pn_transport_input(pn_transport_t *transport, char *DATA, size_t SIZE);

Modified: qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java?rev=1442057&r1=1442056&r2=1442057&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
(original)
+++ qpid/proton/trunk/proton-c/bindings/java/src/main/java/org/apache/qpid/proton/codec/jni/JNIData.java
Mon Feb  4 09:42:13 2013
@@ -462,10 +462,10 @@ public class JNIData implements Data
     public void putBinary(final Binary bytes)
     {
         pn_bytes_t bytes_t = new pn_bytes_t();
-        bytes_t.setSize(bytes.getLength());
         byte[] data = new byte[bytes.getLength()];
         System.arraycopy(bytes.getArray(),bytes.getArrayOffset(),data,0,bytes.getLength());
-        bytes_t.setStart(data);
+        Proton.pn_bytes_from_array(bytes_t, data);
+
         Proton.pn_data_put_binary(_impl, bytes_t);
         //TODO
     }
@@ -476,8 +476,7 @@ public class JNIData implements Data
     {
         byte[] data = string.getBytes(UTF8_CHARSET);
         pn_bytes_t bytes_t = new pn_bytes_t();
-        bytes_t.setStart(data);
-        bytes_t.setSize(data.length);
+        Proton.pn_bytes_from_array(bytes_t, data);
         Proton.pn_data_put_string(_impl, bytes_t);
 
         //TODO
@@ -489,8 +488,7 @@ public class JNIData implements Data
     {
         byte[] data = symbol.toString().getBytes(ASCII_CHARSET);
         pn_bytes_t bytes_t = new pn_bytes_t();
-        bytes_t.setStart(data);
-        bytes_t.setSize(data.length);
+        Proton.pn_bytes_from_array(bytes_t, data);
         Proton.pn_data_put_symbol(_impl, bytes_t);
         //TODO
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message