Created
November 18, 2010 01:51
-
-
Save jfarcand/704516 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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