Skip to content

Commit

Permalink
InputStreamToXInputStreamAdapter.readBytes() should read until the bu…
Browse files Browse the repository at this point in the history
…ffer is full,

or the file ends. It shouldn't care about available().

Patch by: me
  • Loading branch information
Damjan Jovanovic committed Oct 16, 2022
1 parent 6cb0614 commit f049104
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,24 @@ public int readBytes(byte[][] b, int len) throws
int count = 0;
try {
long bytesRead=0;
int totalBytesRead = 0;
if (b[0] == null || b[0].length < len) {
b[0] = new byte[len];
}
if (len >iIn.available()) {
bytesRead = iIn.read(b[0], 0, iIn.available());
}
else{
bytesRead = iIn.read(b[0], 0, len);
}
// Casting bytesRead to an int is okay, since the user can
// only pass in an integer length to read, so the bytesRead
// must <= len.
//
if (bytesRead < b[0].length) {
int outSize = bytesRead > 0 ? (int)bytesRead : 0;
byte[] out = new byte[outSize];
System.arraycopy(b[0], 0, out, 0, outSize);
while ((len > 0) && ((bytesRead = iIn.read(b[0], totalBytesRead, len)) > 0)) {
totalBytesRead += (int)bytesRead;
len -= (int)bytesRead;
}
if (totalBytesRead < b[0].length) {
byte[] out = new byte[totalBytesRead];
System.arraycopy(b[0], 0, out, 0, totalBytesRead);
b[0] = out;
}
if (bytesRead <= 0) {
return(0);
}
return ((int)bytesRead);
return totalBytesRead;


} catch (IOException e) {
Expand Down

0 comments on commit f049104

Please sign in to comment.