Skip to content

Added an example for streaming#3

Open
parj wants to merge 3 commits into
3redronin:masterfrom
parj:master
Open

Added an example for streaming#3
parj wants to merge 3 commits into
3redronin:masterfrom
parj:master

Conversation

@parj

@parj parj commented Dec 27, 2023

Copy link
Copy Markdown

No description provided.

@danielflower danielflower left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request. I just had a couple of minor comments.

Comment thread src/main/java/io/muserver/docs/samples/StreamingExample.java
if (count > 0) {
writer.write(",\n");
}
String jsonR = new StringBuilder()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to just to the writer directly. It is already buffered so no need to create a string builder.

I'm not a big fan of creating JSON this way as you need to json-encode everything properly... could use a org.json.JSONWriter but perhaps that is overcomplicated for this example, and just using strings is more straightforward for demo purposes. So okay.

Comment thread src/main/resources/views/jaxrs.html Outdated

<p>Streaming can be done by implementing <code>StreamingOutput</code>. One use-case for this is to stream large data sets
back, without having to read the entre data set into memory. To reduce memory consumption even further,
<code>StringBuffer</code> is used to build the JSON.</p>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this bit about string buffer.

@parj

parj commented Jan 6, 2024

Copy link
Copy Markdown
Author

Changes completed - let me know if they look good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants