diff --git a/server/eclipse-project/src/main/java/us/freeandfair/corla/query/ExportQueries.java b/server/eclipse-project/src/main/java/us/freeandfair/corla/query/ExportQueries.java index 4d2ad2d3..48c9b325 100644 --- a/server/eclipse-project/src/main/java/us/freeandfair/corla/query/ExportQueries.java +++ b/server/eclipse-project/src/main/java/us/freeandfair/corla/query/ExportQueries.java @@ -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 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)); - 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) {