ICU-7057 InputStream.read() does not always read all .available() bytes
X-SVN-Rev: 35790
This commit is contained in:
parent
e91fd1e88e
commit
eee3938658
@ -218,14 +218,12 @@ public final class ICUBinary
|
|||||||
try {
|
try {
|
||||||
int avail = is.available();
|
int avail = is.available();
|
||||||
byte[] bytes = new byte[avail];
|
byte[] bytes = new byte[avail];
|
||||||
int numRead = is.read(bytes);
|
readFully(is, bytes, 0, avail);
|
||||||
assert numRead == avail;
|
|
||||||
while((avail = is.available()) != 0) {
|
while((avail = is.available()) != 0) {
|
||||||
// TODO Java 6 replace new byte[] and arraycopy(): byte[] newBytes = Arrays.copyOf(bytes, bytes.length + avail);
|
// TODO Java 6 replace new byte[] and arraycopy(): byte[] newBytes = Arrays.copyOf(bytes, bytes.length + avail);
|
||||||
byte[] newBytes = new byte[bytes.length + avail];
|
byte[] newBytes = new byte[bytes.length + avail];
|
||||||
System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
|
System.arraycopy(bytes, 0, newBytes, 0, bytes.length);
|
||||||
numRead = is.read(newBytes, bytes.length, avail);
|
readFully(is, newBytes, bytes.length, avail);
|
||||||
assert numRead == avail;
|
|
||||||
bytes = newBytes;
|
bytes = newBytes;
|
||||||
}
|
}
|
||||||
return ByteBuffer.wrap(bytes);
|
return ByteBuffer.wrap(bytes);
|
||||||
@ -234,6 +232,16 @@ public final class ICUBinary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final void readFully(InputStream is, byte[] bytes, int offset, int avail)
|
||||||
|
throws IOException {
|
||||||
|
while (avail > 0) {
|
||||||
|
int numRead = is.read(bytes, offset, avail);
|
||||||
|
assert numRead > 0;
|
||||||
|
offset += numRead;
|
||||||
|
avail -= numRead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// private variables -------------------------------------------------
|
// private variables -------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user