Skip to content

Commit 249c882

Browse files
committed
Old fortune handler.
Signed-off-by: Santiago Pericas-Geertsen <[email protected]>
1 parent dab117a commit 249c882

File tree

1 file changed

+5
-24
lines changed
  • frameworks/Java/helidon/nima/src/main/java/io/helidon/benchmark/nima/services

1 file changed

+5
-24
lines changed
Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11

22
package io.helidon.benchmark.nima.services;
33

4-
import java.io.IOException;
5-
import java.util.Collections;
4+
import java.util.Comparator;
65
import java.util.List;
76

87
import com.fizzed.rocker.runtime.ArrayOfByteArraysOutput;
@@ -15,7 +14,6 @@
1514

1615
import static io.helidon.benchmark.nima.Main.CONTENT_TYPE_HTML;
1716
import static io.helidon.benchmark.nima.Main.SERVER;
18-
import static io.helidon.http.HeaderNames.CONTENT_LENGTH;
1917

2018
public class FortuneHandler implements Handler {
2119

@@ -32,28 +30,11 @@ public FortuneHandler(DbRepository repository) {
3230
public void handle(ServerRequest req, ServerResponse res) {
3331
res.header(SERVER);
3432
res.header(CONTENT_TYPE_HTML);
35-
36-
// render using template and get list of buffers
3733
List<Fortune> fortuneList = repository.getFortunes();
3834
fortuneList.add(ADDITIONAL_FORTUNE);
39-
Collections.sort(fortuneList);
40-
ArrayOfByteArraysOutput output = fortunes.template(fortuneList).render(ArrayOfByteArraysOutput.FACTORY);
41-
List<byte[]> entity = output.getArrays();
42-
43-
// compute entity length and set header
44-
int length = 0;
45-
for (byte[] bytes : entity) {
46-
length += bytes.length;
47-
}
48-
res.header(CONTENT_LENGTH, String.valueOf(length));
49-
50-
// write entity to output
51-
try (var out = res.outputStream()) {
52-
for (byte[] bytes : entity) {
53-
out.write(bytes);
54-
}
55-
} catch (IOException e) {
56-
throw new RuntimeException(e);
57-
}
35+
fortuneList.sort(Comparator.comparing(Fortune::getMessage));
36+
res.send(fortunes.template(fortuneList)
37+
.render(ArrayOfByteArraysOutput.FACTORY)
38+
.toByteArray());
5839
}
5940
}

0 commit comments

Comments
 (0)