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();
}
}
Aggregations