Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
(cherry picked from commit a3fd77e)
  • Loading branch information
EugenDueck committed May 24, 2024
1 parent cc15ac7 commit e85eb50
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/main/java/org/takes/rq/RqLive.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static Request parse(final InputStream input) throws IOException {
final Collection<String> head = new LinkedList<>();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
Opt<Integer> data = new Opt.Empty<>();
data = RqLive.data(input, data, false);
data = RqLive.data(input, data);
while (data.get() > 0) {
eof = false;
if (data.get() == '\r') {
Expand All @@ -80,11 +80,11 @@ private static Request parse(final InputStream input) throws IOException {
if (header.has()) {
head.add(header.get());
}
data = RqLive.data(input, data, false);
data = RqLive.data(input, data);
continue;
}
baos.write(RqLive.legalCharacter(data, baos, head.size() + 1));
data = RqLive.data(input, new Opt.Empty<>(), true);
data = RqLive.data(input, new Opt.Empty<>());
}
if (eof) {
throw new IOException("empty request");
Expand Down Expand Up @@ -165,18 +165,14 @@ private static Integer legalCharacter(final Opt<Integer> data,
* Obtains new byte if hasn't.
* @param input Stream
* @param data Empty or current data
* @param available Indicates whether or not it should check first if there
* are available bytes
* @return Next or current data
* @throws IOException if input.read() fails
*/
private static Opt<Integer> data(final InputStream input,
final Opt<Integer> data, final boolean available) throws IOException {
final Opt<Integer> data) throws IOException {
final Opt<Integer> ret;
if (data.has()) {
ret = data;
} else if (available && input.available() <= 0) {
ret = new Opt.Single<>(-1);
} else {
ret = new Opt.Single<>(input.read());
}
Expand Down

0 comments on commit e85eb50

Please sign in to comment.