From 3e300bb8f6ddd735236103527d8d78b9dc87e0fd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 11 Aug 2024 15:40:49 -0700 Subject: [PATCH] altoslib: Ignore content-length when fetching map tiles Apache has been "fixed" to no longer respect any content-length provided by a CGI script. This means we don't get the length of the image from the server anymore. Ignore it and just keep fetching until we hit the end. Signed-off-by: Keith Packard --- altoslib/AltosMapStore.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/altoslib/AltosMapStore.java b/altoslib/AltosMapStore.java index f852f560..a2221ac4 100644 --- a/altoslib/AltosMapStore.java +++ b/altoslib/AltosMapStore.java @@ -131,20 +131,15 @@ public class AltosMapStore { } InputStream in = new BufferedInputStream(uc.getInputStream()); int bytesRead = 0; - int offset = 0; - data = new byte[contentLength]; - while (offset < contentLength) { - bytesRead = in.read(data, offset, data.length - offset); - if (bytesRead == -1) - break; - offset += bytesRead; + byte[] buffer = new byte[4096]; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + while ((bytesRead = in.read(buffer)) != -1) { + baos.write(buffer, 0, bytesRead); } in.close(); + data = baos.toByteArray(); - if (offset == contentLength) - status = AltosMapTile.fetched; - else - status = AltosMapTile.failed; + status = AltosMapTile.fetched; } catch (IOException e) { status = AltosMapTile.failed; -- 2.47.2