Skip to content

Commit

Permalink
chore(emm): Clean up gz dump
Browse files Browse the repository at this point in the history
  • Loading branch information
olovy committed Nov 27, 2024
1 parent 36a080a commit e4b14a9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions emm/src/main/java/whelk/Dump.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static void sendDumpResponse(Whelk whelk, String apiBaseUrl, HttpServletR
}

if (isDownload) {
sendDumpDownloadResponse(whelk, apiBaseUrl, selection, dumpFilePath, res);
sendDumpDownloadResponse(whelk, dumpFilePath, res);
} else {
long offsetNumeric = Long.parseLong(offset);
sendDumpPageResponse(whelk, apiBaseUrl, selection, dumpFilePath, offsetNumeric, res);
Expand Down Expand Up @@ -284,7 +284,7 @@ private static void sendFormattedResponse(Whelk whelk, String apiBaseUrl, String
HttpTools.sendResponse(res, responseObject, JSON_CONTENT_TYPE);
}

private static void sendDumpDownloadResponse(Whelk whelk, String apiBaseUrl, String dump, Path dumpFilePath, HttpServletResponse res) {
private static void sendDumpDownloadResponse(Whelk whelk, Path dumpFilePath, HttpServletResponse res) {
String filename = Unicode.stripSuffix(dumpFilePath.getFileName().toString(), ".dump") + ND_JSON_LD_GZ_EXT;
res.setHeader("Content-Disposition", "attachment; filename=" + filename);
res.setHeader("Content-Type", "application/octet-stream");
Expand All @@ -294,7 +294,7 @@ private static void sendDumpDownloadResponse(Whelk whelk, String apiBaseUrl, Str
res.flushBuffer();

var contextDoc = contextDoc(whelk);
writeJsonLdLines(wrapContextDoc(contextDoc), os);
writeJsonLdLine(wrapContextDoc(contextDoc), os);

// Has the dump not begun being written yet ?
var t = new Timeout(60 * 1000);
Expand All @@ -313,11 +313,11 @@ private static void sendDumpDownloadResponse(Whelk whelk, String apiBaseUrl, Str
do {
t.sleep();
line = r.readLine();
} while(line == null);
} while (line == null);
}

// Reached end of dump
if(DUMP_END_MARKER_NO_NEWLINE.equals(line)) {
if (DUMP_END_MARKER_NO_NEWLINE.equals(line)) {
break;
}

Expand All @@ -344,14 +344,14 @@ private static void writeJsonLdLines(Whelk whelk, Collection<String> ids, Docume
continue;
}

writeJsonLdLines(wrapDoc(doc, contextDoc), os);
writeJsonLdLine(wrapDoc(doc, contextDoc), os);
}
os.flush();
}

// TODO jackson2 can do json lines natively - upgrade?
// https://fasterxml.github.io/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/SequenceWriter.html
private static void writeJsonLdLines(Object object, OutputStream os) throws IOException {
private static void writeJsonLdLine(Object object, OutputStream os) throws IOException {
String json = mapper.writeValueAsString(object).replaceAll("\n", "");
os.write(json.getBytes(StandardCharsets.UTF_8));
os.write("\n".getBytes(StandardCharsets.UTF_8));
Expand Down

0 comments on commit e4b14a9

Please sign in to comment.