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

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 ( ) ; } }
receives data from the device . returns after the given timeout even if no data has been received .
