From cbc270480fafa27acf01cf6ee9d0455fff9c69ce Mon Sep 17 00:00:00 2001 From: Christian Pesch Date: Thu, 25 Jan 2024 12:57:19 +0100 Subject: [PATCH] use Java HTTP Client --- .../base/NavigationFormatParser.java | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/navigation-formats/src/main/java/slash/navigation/base/NavigationFormatParser.java b/navigation-formats/src/main/java/slash/navigation/base/NavigationFormatParser.java index b842275b3..d9a2fdbdc 100644 --- a/navigation-formats/src/main/java/slash/navigation/base/NavigationFormatParser.java +++ b/navigation-formats/src/main/java/slash/navigation/base/NavigationFormatParser.java @@ -31,7 +31,6 @@ import slash.navigation.kml.Kml22Format; import slash.navigation.nmn.NmnFormat; import slash.navigation.photo.PhotoFormat; -import slash.navigation.rest.Get; import slash.navigation.tcx.TcxFormat; import java.io.*; @@ -218,22 +217,16 @@ public void parse(String urlString) throws IOException { URL url = new URL(urlString); int readBufferSize = getSize(url); log.info("Reading '" + url + "' with a buffer of " + readBufferSize + " bytes"); - - Get request = new Get(url); - request.execute(response -> { - InputStream inputStream = response.getEntity().getContent(); - NotClosingUnderlyingInputStream buffer = new NotClosingUnderlyingInputStream(new BufferedInputStream(inputStream, CHUNK_BUFFER_SIZE)); - // make sure not to read a byte after the limit - buffer.mark(readBufferSize + CHUNK_BUFFER_SIZE * 2); - try { - CompactCalendar startDate = extractStartDate(url); - internalSetStartDate(startDate); - internalRead(buffer, getNavigationFormatRegistry().getReadFormats(), this); - } finally { - buffer.closeUnderlyingInputStream(); - } - return null; - }); + NotClosingUnderlyingInputStream buffer = new NotClosingUnderlyingInputStream(new BufferedInputStream(url.openStream(), CHUNK_BUFFER_SIZE)); + // make sure not to read a byte after the limit + buffer.mark(readBufferSize + CHUNK_BUFFER_SIZE * 2); + try { + CompactCalendar startDate = extractStartDate(url); + internalSetStartDate(startDate); + internalRead(buffer, getNavigationFormatRegistry().getReadFormats(), this); + } finally { + buffer.closeUnderlyingInputStream(); + } } } @@ -325,11 +318,7 @@ public ParserResult read(URL url, List formats) throws IOExcep int readBufferSize = getSize(url); log.info("Reading '" + url + "' with a buffer of " + readBufferSize + " bytes"); - - final URL finalUrl = url; - final List finalFormats = formats; - Get request = new Get(finalUrl); - return request.execute(response -> read(response.getEntity().getContent(), readBufferSize, extractStartDate(finalUrl), extractFile(finalUrl), finalFormats)); + return read(url.openStream(), readBufferSize, extractStartDate(url), extractFile(url), formats); } public ParserResult read(URL url) throws IOException {