mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-16 13:09:20 +01:00
Optimize the getBytesFromStream function StreamUtils
This commit is contained in:
parent
536c28a3b1
commit
95c6c085f6
@ -41,13 +41,17 @@ public final class StreamUtils {
|
|||||||
} else {
|
} else {
|
||||||
buffer = new byte[0x8000];
|
buffer = new byte[0x8000];
|
||||||
}
|
}
|
||||||
int totalRead = 0;
|
int toRead = size;
|
||||||
|
int curReadChunk = buffer.length;
|
||||||
do {
|
do {
|
||||||
int read = in.read(buffer);
|
if (toRead < curReadChunk) {
|
||||||
|
curReadChunk = toRead;
|
||||||
|
}
|
||||||
|
int read = in.read(buffer, 0, curReadChunk);
|
||||||
if (read < 0) break;
|
if (read < 0) break;
|
||||||
System.arraycopy(buffer, 0, result, totalRead, read);
|
System.arraycopy(buffer, 0, result, size - toRead, read);
|
||||||
totalRead += read;
|
toRead -= read;
|
||||||
} while (totalRead < size);
|
} while (toRead > 0);
|
||||||
in.close();
|
in.close();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -61,7 +65,6 @@ public final class StreamUtils {
|
|||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
bytesRead = inputStream.read(overflowbuf, overflowbuffer.getLengthOfDataInBuffer(), overflowbuffer.getSpaceLeft());
|
bytesRead = inputStream.read(overflowbuf, overflowbuffer.getLengthOfDataInBuffer(), overflowbuffer.getSpaceLeft());
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.info(e.getMessage());
|
log.info(e.getMessage());
|
||||||
if (!e.getMessage().equals("Write end dead")) {
|
if (!e.getMessage().equals("Write end dead")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user