Search in sources :

Example 1 with IntOut

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

the class AfcClient method fileRead.

/**
     * Attempts to the read the given number of bytes from the given file.
     * 
     * @param handle file handle of a previously opened file
     * @param buffer the byte array in which to store the bytes read.
     * @param offset the initial position in {@code buffer} to store the bytes
     *               read from the file.
     * @param count the maximum number of bytes to store in {@code buffer}.
     * @return the number of bytes actually read or -1 if the end of the stream
     *         has been reached.
     */
public int fileRead(long handle, byte[] buffer, int offset, int count) {
    if ((offset | count) < 0 || offset > buffer.length || buffer.length - offset < count) {
        throw new ArrayIndexOutOfBoundsException("length=" + buffer.length + "; regionStart=" + offset + "; regionLength=" + count);
    }
    if (count == 0) {
        return 0;
    }
    byte[] data = buffer;
    if (offset > 0) {
        data = new byte[count];
    }
    IntOut bytesReadOut = new IntOut();
    try {
        checkResult(LibIMobileDevice.afc_file_read(getRef(), handle, data, count, bytesReadOut));
        int bytesRead = bytesReadOut.getValue();
        if (bytesRead == 0) {
            // Assume EOF reached.
            return -1;
        }
        if (data != buffer) {
            System.arraycopy(data, 0, buffer, offset, bytesRead);
        }
        return bytesRead;
    } finally {
        bytesReadOut.delete();
    }
}
Also used : IntOut(org.robovm.libimobiledevice.binding.IntOut)

Example 2 with IntOut

use of org.robovm.libimobiledevice.binding.IntOut 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)

Example 3 with IntOut

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

the class IDeviceConnection method send.

/**
     * Sends data to the device on this connection.
     *
     * @param buffer the buffer to be sent.
     * @param offset the start position in {@code buffer} from where to get bytes.
     * @param count the number of bytes from {@code buffer} to send.
     * @return the number of bytes actually sent.
     */
public int send(byte[] buffer, int offset, int count) {
    checkArrayBounds(buffer, offset, count);
    if (count == 0) {
        return 0;
    }
    byte[] data = buffer;
    if (offset > 0) {
        data = new byte[count];
        System.arraycopy(buffer, offset, data, 0, count);
    }
    IntOut bytesSentOut = new IntOut();
    try {
        IDevice.checkResult(LibIMobileDevice.idevice_connection_send(getRef(), data, count, bytesSentOut));
        return bytesSentOut.getValue();
    } finally {
        bytesSentOut.delete();
    }
}
Also used : IntOut(org.robovm.libimobiledevice.binding.IntOut)

Example 4 with IntOut

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

the class AfcClient method fileWrite.

/**
     * Writes a given number of bytes to a file.
     * 
     * @param handle file handle of previously opened file. 
     * @param buffer the buffer to be written.
     * @param offset the start position in {@code buffer} from where to get bytes.
     * @param count the number of bytes from {@code buffer} to write to the file.
     * @return the number of bytes actually written to the file.
     */
public int fileWrite(long handle, byte[] buffer, int offset, int count) {
    if ((offset | count) < 0 || offset > buffer.length || buffer.length - offset < count) {
        throw new ArrayIndexOutOfBoundsException("length=" + buffer.length + "; regionStart=" + offset + "; regionLength=" + count);
    }
    if (count == 0) {
        return 0;
    }
    byte[] data = buffer;
    if (offset > 0) {
        data = new byte[count];
        System.arraycopy(buffer, offset, data, 0, count);
    }
    IntOut bytesWrittenOut = new IntOut();
    try {
        checkResult(LibIMobileDevice.afc_file_write(getRef(), handle, data, count, bytesWrittenOut));
        int bytesWritten = bytesWrittenOut.getValue();
        return bytesWritten;
    } finally {
        bytesWrittenOut.delete();
    }
}
Also used : IntOut(org.robovm.libimobiledevice.binding.IntOut)

Example 5 with IntOut

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

the class IDevice method listUdids.

/**
     * Lists UDIDs of currently available devices.
     * 
     * @return the UDIDs of the currently available devices.
     */
public static String[] listUdids() {
    StringArrayOut devicesOut = new StringArrayOut();
    IntOut countOut = new IntOut();
    try {
        checkResult(LibIMobileDevice.idevice_get_device_list(devicesOut, countOut));
        StringArray devices = devicesOut.getValue();
        int count = countOut.getValue();
        String[] udids = new String[count];
        for (int i = 0; i < count; i++) {
            udids[i] = devices.get(i);
        }
        return udids;
    } catch (LibIMobileDeviceException e) {
        if (e.getErrorCode() == IDeviceError.IDEVICE_E_NO_DEVICE.swigValue()) {
            // This happens when usbmuxd isn't running
            return new String[0];
        }
        throw e;
    } finally {
        devicesOut.delete();
        countOut.delete();
    }
}
Also used : StringArray(org.robovm.libimobiledevice.binding.StringArray) StringArrayOut(org.robovm.libimobiledevice.binding.StringArrayOut) IntOut(org.robovm.libimobiledevice.binding.IntOut)

Aggregations

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