Search in sources :

Example 1 with ByteArray

use of org.robovm.libimobiledevice.binding.ByteArray in project robovm by robovm.

the class PlistUtil method toJavaPlist.

public static NSObject toJavaPlist(PlistRef plist) throws IOException {
    PlistRefOut plistOut = new PlistRefOut();
    ByteArrayOut plistBinOut = new ByteArrayOut();
    IntOut lengthOut = new IntOut();
    try {
        LibIMobileDevice.plist_to_bin(plist, plistBinOut, lengthOut);
        LibIMobileDevice.plist_free(plist);
        int length = lengthOut.getValue();
        ByteArray plistBin = plistBinOut.getValue();
        if (length == 0 || plistBin == null) {
            return null;
        }
        byte[] data = new byte[length];
        for (int i = 0; i < length; i++) {
            data[i] = plistBin.get(i);
        }
        return PropertyListParser.parse(data);
    } catch (IOException e) {
        throw e;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        plistOut.delete();
        LibIMobileDevice.delete_ByteArrayOut_value(plistBinOut);
        plistBinOut.delete();
        lengthOut.delete();
    }
}
Also used : PlistRefOut(org.robovm.libimobiledevice.binding.PlistRefOut) ByteArray(org.robovm.libimobiledevice.binding.ByteArray) IntOut(org.robovm.libimobiledevice.binding.IntOut) ByteArrayOut(org.robovm.libimobiledevice.binding.ByteArrayOut) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 ByteArray (org.robovm.libimobiledevice.binding.ByteArray)1 ByteArrayOut (org.robovm.libimobiledevice.binding.ByteArrayOut)1 IntOut (org.robovm.libimobiledevice.binding.IntOut)1 PlistRefOut (org.robovm.libimobiledevice.binding.PlistRefOut)1