Skip to content

Commit

Permalink
Uses Sticky in RqOnce in place of inner anonymous class #1080
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier B. OURA committed Mar 1, 2021
1 parent 7866dcc commit 15ba8d6
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/main/java/org/takes/rq/RqOnce.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
*/
package org.takes.rq;

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

/**
Expand All @@ -37,9 +35,6 @@
* <p>The class is immutable and thread-safe.
*
* @since 0.36
* @todo #999:30min Please use {@link org.cactoos.text.Sticky} decorator
* class instead of inner anonymous class below, which prevents input
* from being read twice by caching results of first call internally.
*/
@EqualsAndHashCode(callSuper = true)
public final class RqOnce extends RqWrap {
Expand All @@ -52,16 +47,10 @@ public RqOnce(final Request req) {
super(
new RequestOf(
new Sticky<>(req::head),
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());
}
}
new Mapped<>(
InputStreamOf::new,
new Sticky<>(new RqPrint(req)::asString)
)
)
);
}
Expand Down

0 comments on commit 15ba8d6

Please sign in to comment.