]> git.gag.com Git - fw/altos/commitdiff
altoslib: Ignore content-length when fetching map tiles
authorKeith Packard <keithp@keithp.com>
Sun, 11 Aug 2024 22:40:49 +0000 (15:40 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 11 Aug 2024 22:40:49 +0000 (15:40 -0700)
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 <keithp@keithp.com>
altoslib/AltosMapStore.java

index f852f5604993be0f974d77dd17e2f954132b541d..a2221ac4a2945d88d7ad395d005e2a422b6da494 100644 (file)
@@ -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;