Search in sources :

Example 6 with IntOut

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

the class IDeviceConnection method receive.

/**
     * Receives data from the device. Returns after the given timeout even if no 
     * data has been received.
     *
     * @param buffer the byte array in which to store the received data.
     * @param offset the initial position in {@code buffer} to store the 
     *               received bytes.
     * @param count the maximum number of bytes to store in {@code buffer}.
     * @param timeout timeout in milliseconds after which this method will
     *                return even if no data has been received.
     * @return the number of bytes received.
     */
public int receive(byte[] buffer, int offset, int count, int timeout) {
    checkArrayBounds(buffer, offset, count);
    if (count == 0) {
        return 0;
    }
    byte[] data = buffer;
    if (offset > 0) {
        data = new byte[count];
    }
    IntOut bytesReceivedOut = new IntOut();
    try {
        IDevice.checkResult(LibIMobileDevice.idevice_connection_receive_timeout(getRef(), data, count, bytesReceivedOut, timeout));
        int bytesRead = bytesReceivedOut.getValue();
        if (bytesRead > 0 && data != buffer) {
            System.arraycopy(data, 0, buffer, offset, bytesRead);
        }
        return bytesRead;
    } finally {
        bytesReceivedOut.delete();
    }
}
Also used : 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