mirror of
https://github.com/Maschell/JNUSLib.git
synced 2024-11-22 07:59:19 +01:00
Check for execptions when reading an inputstream
This commit is contained in:
parent
ef878f7e41
commit
dbad684549
@ -48,6 +48,7 @@ public final class StreamUtils {
|
||||
curReadChunk = toRead;
|
||||
}
|
||||
int read = in.read(buffer, 0, curReadChunk);
|
||||
StreamUtils.checkForException(in);
|
||||
if (read < 0) break;
|
||||
System.arraycopy(buffer, 0, result, size - toRead, read);
|
||||
toRead -= read;
|
||||
@ -65,6 +66,7 @@ public final class StreamUtils {
|
||||
do {
|
||||
try {
|
||||
bytesRead = inputStream.read(overflowbuf, overflowbuffer.getLengthOfDataInBuffer(), overflowbuffer.getSpaceLeft());
|
||||
StreamUtils.checkForException(inputStream);
|
||||
} catch (IOException e) {
|
||||
log.info(e.getMessage());
|
||||
if (!e.getMessage().equals("Write end dead")) {
|
||||
@ -141,6 +143,7 @@ public final class StreamUtils {
|
||||
long written = 0;
|
||||
do {
|
||||
read = inputStream.read(buffer);
|
||||
StreamUtils.checkForException(inputStream);
|
||||
if (read < 0) {
|
||||
break;
|
||||
}
|
||||
@ -192,4 +195,15 @@ public final class StreamUtils {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkForException(InputStream inputStream) throws IOException {
|
||||
if (inputStream instanceof PipedInputStreamWithException) {
|
||||
try {
|
||||
((PipedInputStreamWithException) inputStream).checkForException();
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import de.mas.wiiu.jnus.entities.content.Content;
|
||||
import de.mas.wiiu.jnus.utils.ByteArrayBuffer;
|
||||
import de.mas.wiiu.jnus.utils.CheckSumWrongException;
|
||||
import de.mas.wiiu.jnus.utils.HashUtil;
|
||||
import de.mas.wiiu.jnus.utils.PipedInputStreamWithException;
|
||||
import de.mas.wiiu.jnus.utils.StreamUtils;
|
||||
import de.mas.wiiu.jnus.utils.Utils;
|
||||
import lombok.extern.java.Log;
|
||||
@ -101,7 +102,9 @@ public class NUSDecryption extends AESDecryption {
|
||||
int readTotal = 0;
|
||||
while (readTotal < toRead) {
|
||||
int res = inputStream.read(data, readTotal, toRead - readTotal);
|
||||
StreamUtils.checkForException(inputStream);
|
||||
if (res < 0) {
|
||||
// This should NEVER happen.
|
||||
throw new IOException();
|
||||
}
|
||||
readTotal += res;
|
||||
|
Loading…
Reference in New Issue
Block a user