Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

176 fix json report download #177

Closed
wants to merge 14 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,21 @@ public static void jsonOut(final String query, final OutputStream os) {
// interleave an object separator (the comma and line break) into the stream
// of json objects to create valid json thx!
// https://stackoverflow.com/a/25624818
// call .skip() to remove the first separator
final Stream<Object[]> results =
q.stream().flatMap(i -> Stream.of(new String[] {",\n"}, i)).skip(1); // remove
// the
// first
// separator
q.stream().flatMap(i -> Stream.of(",\n", i)).skip(1);

// write json by hand to preserve streaming writes in case of big data
try {
os.write("[".getBytes(StandardCharsets.UTF_8));
Copy link
Member

Choose a reason for hiding this comment

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

Can resultsArr be final, and the for loop changes to iterate over final Object ...? Could push the results.toArray() into the for loop parens I suppose, but it doesn't make a lot of difference.

results.forEach(line -> {
Object[] resultsArr = results.toArray();

for(Object line : resultsArr) {
try {
// the object array is the columns, but in this case there is only
// one, so we take it at index 0
os.write(line[0].toString().getBytes(StandardCharsets.UTF_8));
os.write(line.toString().getBytes(StandardCharsets.UTF_8));
} catch (java.io.IOException e) {
LOGGER.error(e.getMessage());
}
});
}

os.write("]".getBytes(StandardCharsets.UTF_8));
} catch (java.io.IOException e) {
Expand Down
Loading