Skip to content

Commit

Permalink
Also fix read()
Browse files Browse the repository at this point in the history
  • Loading branch information
Gbillou committed Aug 12, 2019
1 parent d0b6502 commit fc342a0
Showing 1 changed file with 11 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ public NettyInputStream(LinkedBlockingDeque<InputStream> isList) {
this.isList = isList;
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
private interface ISReader {
int readFrom(InputStream take) throws IOException;
}

private int readInternal(ISReader takeRead) throws IOException {
if (end) {
return -1;
}
Expand All @@ -83,7 +85,7 @@ public int read(byte[] b, int off, int len) throws IOException {
return -1;
}

int read = take.read(b, off, len);
int read = takeRead.readFrom(take);

if (take.available() > 0) {
isList.addFirst(take);
Expand All @@ -98,29 +100,13 @@ public int read(byte[] b, int off, int len) throws IOException {
}

@Override
public int read() throws IOException {

if (end) {
return -1;
}

try {
InputStream take = isList.take();

if (checkEndOfInput(take)) {
return -1;
}

int read = take.read();

if (take.available() > 0) {
isList.addFirst(take);
}
public int read(byte[] b, int off, int len) throws IOException {
return readInternal(take -> take.read(b, off, len));
}

return read;
} catch (InterruptedException e) {
throw new IOException("Interrupted.", e);
}
@Override
public int read() throws IOException {
return readInternal(InputStream::read);
}

@Override
Expand Down

0 comments on commit fc342a0

Please sign in to comment.