Created
November 29, 2010 16:32
-
-
Save jfarcand/720159 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
if (byteToRead > 0) { | |
int minBytes = Math.min(8192, byteToRead); | |
byte[] bytes = new byte[minBytes]; | |
int leftBytes = minBytes < 8192 ? 0 : byteToRead - 8192; | |
int read = 0; | |
while (leftBytes > -1) { | |
read = stream.read(bytes); | |
if (read == -1) { | |
break; | |
} | |
future.touch(); | |
asyncHandler.onBodyPartReceived(new ResponseBodyPart(uri, bytes, JDKAsyncHttpProvider.this)); | |
if (leftBytes > 8192) { | |
leftBytes -= read; | |
bytes = new byte[minBytes]; | |
} else if (leftBytes <= 8192 && leftBytes > 0) { | |
bytes = new byte[leftBytes]; | |
leftBytes = 0; | |
} else { | |
leftBytes = -1; | |
} | |
System.out.println("===> " + leftBytes); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment