Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Encapsulate out-param munging
Browse files Browse the repository at this point in the history
  • Loading branch information
samstokes committed May 24, 2012
1 parent 70fc2b3 commit daf1d59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/main/java/com/rapportive/jawbone/WbxmlToXml.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rapportive.jawbone;

import com.sun.jna.Native;
import com.sun.jna.Pointer;

import com.sun.jna.ptr.LongByReference;
Expand Down Expand Up @@ -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
Expand Down
12 changes: 2 additions & 10 deletions src/test/java/com/rapportive/jawbone/JawboneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit daf1d59

Please sign in to comment.