Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Created November 29, 2010 16:32
Show Gist options
  • Save jfarcand/720159 to your computer and use it in GitHub Desktop.
Save jfarcand/720159 to your computer and use it in GitHub Desktop.
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