Skip to content

Commit

Permalink
Resolve conflicts with master yegor256#1080
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Mar 25, 2021
2 parents 15ba8d6 + 925e1a2 commit 5b415fb
Show file tree
Hide file tree
Showing 25 changed files with 410 additions and 529 deletions.
29 changes: 20 additions & 9 deletions src/main/java/org/takes/http/BkBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import lombok.EqualsAndHashCode;
import org.cactoos.io.BytesOf;
import org.cactoos.io.InputStreamOf;
import org.cactoos.io.UncheckedBytes;
import org.takes.HttpException;
import org.takes.Request;
import org.takes.Response;
Expand Down Expand Up @@ -122,17 +123,27 @@ public void accept(final Socket socket) throws IOException {
private void print(final Request req, final OutputStream output)
throws IOException {
try {
new RsPrint(this.take.act(req)).print(output);
output.write(
new RsPrint(this.take.act(req)).asBytes()
);
} catch (final HttpException ex) {
new RsPrint(BkBasic.failure(ex, ex.code())).print(output);
// @checkstyle IllegalCatchCheck (7 lines)
output.write(
new UncheckedBytes(
new RsPrint(BkBasic.failure(ex, ex.code()))
).asBytes()
);
// @checkstyle IllegalCatchCheck (10 lines)
} catch (final Throwable ex) {
new RsPrint(
BkBasic.failure(
ex,
HttpURLConnection.HTTP_INTERNAL_ERROR
)
).print(output);
output.write(
new UncheckedBytes(
new RsPrint(
BkBasic.failure(
ex,
HttpURLConnection.HTTP_INTERNAL_ERROR
)
)
).asBytes()
);
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/main/java/org/takes/rq/RequestOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,30 @@
import org.cactoos.scalar.And;
import org.cactoos.scalar.Equality;
import org.cactoos.scalar.HashCode;
import org.cactoos.scalar.IoChecked;
import org.cactoos.scalar.Or;
import org.cactoos.scalar.Unchecked;
import org.takes.Body;
import org.takes.Head;
import org.takes.Request;

/**
* This {@link Request} implementation provides a way to build a request
* with custom {@link Scalar} head and body values.
* This {@link Request} implementation provides a way to build a request with
* custom {@link Scalar} head and body values.
*
* <p>The class is immutable and thread-safe.
* <p>
* The class is immutable and thread-safe.
* @since 2.0
*/
public final class RequestOf implements Request {
/**
* Original head scalar.
*/
private final IoChecked<Iterable<String>> shead;
private final Head shead;

/**
* Original body scalar.
*/
private final IoChecked<InputStream> sbody;
private final Body sbody;

/**
* Ctor.
Expand All @@ -66,23 +68,22 @@ public RequestOf(final Iterable<String> head, final InputStream body) {

/**
* Ctor.
* @param head Scalar to provide head value
* @param body Scalar to provide body value
* @param head Head value
* @param body Body value
*/
public RequestOf(
final Scalar<Iterable<String>> head, final Scalar<InputStream> body) {
this.shead = new IoChecked<>(head);
this.sbody = new IoChecked<>(body);
public RequestOf(final Head head, final Body body) {
this.shead = head;
this.sbody = body;
}

@Override
public Iterable<String> head() throws IOException {
return this.shead.value();
return this.shead.head();
}

@Override
public InputStream body() throws IOException {
return this.sbody.value();
return this.sbody.body();
}

@Override
Expand Down Expand Up @@ -118,6 +119,6 @@ public boolean equals(final Object that) {

@Override
public int hashCode() {
return new HashCode(new Unchecked<>(this.shead::value).value()).value();
return new HashCode(new Unchecked<>(this.shead::head).value()).value();
}
}
25 changes: 19 additions & 6 deletions src/main/java/org/takes/rq/RqOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
package org.takes.rq;

import lombok.EqualsAndHashCode;
import java.io.InputStream;
import org.cactoos.Scalar;
import org.cactoos.io.InputStreamOf;
import org.cactoos.scalar.Mapped;
import org.cactoos.scalar.IoChecked;
import org.cactoos.scalar.Sticky;
import org.cactoos.text.TextOf;
import org.takes.Request;

/**
Expand All @@ -35,6 +38,8 @@
* <p>The class is immutable and thread-safe.
*
* @since 0.36
* @todo #1080:30min Please make two decorators (HeadOnce and BodyOnce)
* that prevent multiple reads of their contents.
*/
@EqualsAndHashCode(callSuper = true)
public final class RqOnce extends RqWrap {
Expand All @@ -46,11 +51,19 @@ public final class RqOnce extends RqWrap {
public RqOnce(final Request req) {
super(
new RequestOf(
new Sticky<>(req::head),
new Mapped<>(
InputStreamOf::new,
new Sticky<>(new RqPrint(req)::asString)
)
new IoChecked<>(new Sticky<>(req::head))::value,
new IoChecked<>(
new Scalar<InputStream>() {
private final Scalar<String> text = new Sticky<>(
new TextOf(req::body)::asString
);

@Override
public InputStream value() throws Exception {
return new InputStreamOf(this.text.value());
}
}
)::value
)
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/takes/rq/multipart/RqMtBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ public final class RqMtBase implements RqMultipart {
* Ctor.
* @param req Original request
* @throws IOException If fails
* @todo #950:30m Remove code from this ctor, leaving only
* initialization. Currently this constructor access body
* of the request and triggers its evaluation. This breaks
* composition of multiple request, as it can be seen in
* {@link RqMtFake}. When this task is done, remove
* explicit lazy evaluation for RqMtFake.
* @checkstyle ExecutableStatementCountCheck (2 lines)
*/
public RqMtBase(final Request req) throws IOException {
Expand Down
Loading

0 comments on commit 5b415fb

Please sign in to comment.