Browse Source

Write fortunes output with an output stream using byte[].

Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
Santiago Pericas-Geertsen 10 tháng trước cách đây
mục cha
commit
c4a735d849

+ 9 - 4
frameworks/Java/helidon/nima/src/main/java/io/helidon/benchmark/nima/services/FortuneHandler.java

@@ -8,7 +8,6 @@ import java.util.List;
 import com.fizzed.rocker.runtime.ArrayOfByteArraysOutput;
 import io.helidon.benchmark.nima.models.DbRepository;
 import io.helidon.benchmark.nima.models.Fortune;
-import io.helidon.common.buffers.BufferData;
 import io.helidon.webserver.http.Handler;
 import io.helidon.webserver.http.ServerRequest;
 import io.helidon.webserver.http.ServerResponse;
@@ -39,11 +38,17 @@ public class FortuneHandler implements Handler {
         Collections.sort(fortuneList);
         ArrayOfByteArraysOutput output = fortunes.template(fortuneList).render(ArrayOfByteArraysOutput.FACTORY);
         List<byte[]> entity = output.getArrays();
-        BufferData bufferData = BufferData.create(entity.stream().map(BufferData::create).toList());
-        int length = bufferData.available();
+
+        int length = 0;
+        for (byte[] bytes : entity) {
+            length += bytes.length;
+        }
         res.header(CONTENT_LENGTH, String.valueOf(length));
+
         try (var out = res.outputStream()) {
-            bufferData.writeTo(out);
+            for (byte[] bytes : entity) {
+                out.write(bytes);
+            }
         } catch (IOException e) {
             throw new RuntimeException(e);
         }