Skip to content

Commit fc342a0

Browse files
committed
Also fix read()
1 parent d0b6502 commit fc342a0

File tree

1 file changed

+11
-25
lines changed
  • connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/internal

1 file changed

+11
-25
lines changed

connectors/netty-connector/src/main/java/org/glassfish/jersey/netty/connector/internal/NettyInputStream.java

+11-25
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ public NettyInputStream(LinkedBlockingDeque<InputStream> isList) {
6868
this.isList = isList;
6969
}
7070

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

75+
private int readInternal(ISReader takeRead) throws IOException {
7476
if (end) {
7577
return -1;
7678
}
@@ -83,7 +85,7 @@ public int read(byte[] b, int off, int len) throws IOException {
8385
return -1;
8486
}
8587

86-
int read = take.read(b, off, len);
88+
int read = takeRead.readFrom(take);
8789

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

100102
@Override
101-
public int read() throws IOException {
102-
103-
if (end) {
104-
return -1;
105-
}
106-
107-
try {
108-
InputStream take = isList.take();
109-
110-
if (checkEndOfInput(take)) {
111-
return -1;
112-
}
113-
114-
int read = take.read();
115-
116-
if (take.available() > 0) {
117-
isList.addFirst(take);
118-
}
103+
public int read(byte[] b, int off, int len) throws IOException {
104+
return readInternal(take -> take.read(b, off, len));
105+
}
119106

120-
return read;
121-
} catch (InterruptedException e) {
122-
throw new IOException("Interrupted.", e);
123-
}
107+
@Override
108+
public int read() throws IOException {
109+
return readInternal(InputStream::read);
124110
}
125111

126112
@Override

0 commit comments

Comments
 (0)