From 15ba8d63aa7b1079e81ff6d31abbd52d464cf445 Mon Sep 17 00:00:00 2001 From: "Olivier B. OURA" Date: Sun, 28 Feb 2021 21:16:52 +0000 Subject: [PATCH] Uses Sticky in RqOnce in place of inner anonymous class #1080 --- src/main/java/org/takes/rq/RqOnce.java | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/takes/rq/RqOnce.java b/src/main/java/org/takes/rq/RqOnce.java index 3917f5321..59c3bd0ff 100644 --- a/src/main/java/org/takes/rq/RqOnce.java +++ b/src/main/java/org/takes/rq/RqOnce.java @@ -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; /** @@ -37,9 +35,6 @@ *

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 { @@ -52,16 +47,10 @@ public RqOnce(final Request req) { super( new RequestOf( new Sticky<>(req::head), - new Scalar() { - private final Scalar 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) + ) ) ); }