From e4b14a9503a535a56898afd81a8fa266884dfbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olov=20Ylinenp=C3=A4=C3=A4?= Date: Wed, 27 Nov 2024 14:24:52 +0100 Subject: [PATCH] chore(emm): Clean up gz dump --- emm/src/main/java/whelk/Dump.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/emm/src/main/java/whelk/Dump.java b/emm/src/main/java/whelk/Dump.java index 63ed9ace49..e023b253e7 100644 --- a/emm/src/main/java/whelk/Dump.java +++ b/emm/src/main/java/whelk/Dump.java @@ -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); @@ -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"); @@ -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); @@ -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; } @@ -344,14 +344,14 @@ private static void writeJsonLdLines(Whelk whelk, Collection 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));