Browse files

Encapsulate out-param munging

  • Loading branch information...
1 parent 70fc2b3 commit daf1d59a374a988cf098e3994587349bfff80379 @samstokes samstokes committed May 23, 2012
View
10 src/main/java/com/rapportive/jawbone/WbxmlToXml.java
@@ -1,5 +1,6 @@
package com.rapportive.jawbone;
+import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.LongByReference;
@@ -34,8 +35,15 @@ public void enablePreserveWhitespaces() {
jawbone.wbxml_conv_wbxml2xml_enable_preserve_whitespaces(conv);
}
- public void run(byte[] wbxml, PointerByReference xmlPtr, LongByReference xmlLength) {
+ public byte[] run(byte[] wbxml) {
+ PointerByReference xmlPtr = new PointerByReference();
+ LongByReference xmlLength = new LongByReference();
+
jawbone.check(jawbone.wbxml_conv_wbxml2xml_run(conv, wbxml, wbxml.length, xmlPtr, xmlLength));
+
+ byte[] xmlBytes = xmlPtr.getValue().getByteArray(0L, (int) xmlLength.getValue());
+ Native.free(Pointer.nativeValue(xmlPtr.getValue()));
+ return xmlBytes;
}
@Override
View
12 src/test/java/com/rapportive/jawbone/JawboneTest.java
@@ -41,16 +41,8 @@ public void testWbxmlToXml() throws Exception {
conv.setIndent(4); /* 4-space indent */
conv.enablePreserveWhitespaces();
- PointerByReference xmlPtr = new PointerByReference();
- LongByReference xmlLength = new LongByReference();
- conv.run(wbxml, xmlPtr, xmlLength);
-
- assertTrue("returned no XML", xmlLength.getValue() > 0);
-
- byte[] xmlBytes = xmlPtr.getValue().getByteArray(0L, (int) xmlLength.getValue());
- Native.free(Pointer.nativeValue(xmlPtr.getValue()));
-
- assertEquals("returned b0rked bytes", xmlLength.getValue(), xmlBytes.length);
+ byte[] xmlBytes = conv.run(wbxml);
+ assertTrue("returned no XML", xmlBytes.length > 0);
}
@Test

0 comments on commit daf1d59

Please sign in to comment.