Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Created November 18, 2010 01:51
Show Gist options
  • Save jfarcand/704516 to your computer and use it in GitHub Desktop.
Save jfarcand/704516 to your computer and use it in GitHub Desktop.
private void fireOnEnd(){
// There is a probability that the asynchronous listener never gets called, so we fake it at the end once
// we are 100% sure the response has been received.
long count = bytesTransferred.getAndSet(-1);
if (count != totalBytesToTransfer.get()) {
if (transferAdapter != null) {
int leftBytes = (int) (totalBytesToTransfer.get() - count);
while (leftBytes > 0) {
int length = 8192;
if (leftBytes > 8192) {
leftBytes -= 8192;
} else {
length = leftBytes;
}
byte[] bytes = new byte[length];
transferAdapter.getBytes(bytes);
fireOnBytesSent(bytes);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment