Skip to content

Commit

Permalink
Extract io exception checking in a method
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed May 29, 2018
1 parent 5bb4939 commit 24b5660
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ private int wait(ByteBuffer buffer, long timeout) throws IOException {
notifyAll();
try {
wait(timeout);
if (ioException != null) {
throw ioException;
}
checkIoException();
} catch (InterruptedException e) {
if (ioException != null) {
throw ioException;
}
checkIoException();
throw new InterruptedIOException();
}
if (!isInfinite) {
Expand Down Expand Up @@ -100,9 +96,7 @@ public synchronized int available() {

@Override
public synchronized int read(long timeout, boolean isPeek) throws IOException {
if (ioException != null) {
throw ioException;
}
checkIoException();
// Blocks until more input is available or the reader is closed.
int res = wait(readBuffer, timeout);
if (res >= 0) {
Expand All @@ -117,6 +111,12 @@ public synchronized void setIoException(IOException exception) {
notifyAll();
}

protected synchronized void checkIoException() throws IOException {
if (ioException != null) {
throw ioException;
}
}

synchronized void write(byte[] cbuf, int off, int len) throws IOException {
while (len > 0) {
// Blocks until there is new space available for buffering or the
Expand Down

0 comments on commit 24b5660

Please sign in to comment.