From 69f891c82f59c99839389f9c906f994785fbd4fe Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 28 Mar 2018 10:58:19 +0300 Subject: [PATCH] Add method for converting gzip to string to Algorithms --- OsmAnd-java/src/net/osmand/util/Algorithms.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index 8f1bae7cbf..2f556113be 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -6,6 +6,7 @@ import net.osmand.PlatformUtil; import org.apache.commons.logging.Log; import java.io.BufferedReader; +import java.io.ByteArrayInputStream; import java.io.Closeable; import java.io.EOFException; import java.io.File; @@ -26,6 +27,7 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.zip.GZIPInputStream; /** @@ -452,6 +454,18 @@ public class Algorithms { return responseBody; } + public static String gzipToString(byte[] gzip) throws IOException { + GZIPInputStream gzipIs = new GZIPInputStream(new ByteArrayInputStream(gzip)); + BufferedReader br = new BufferedReader(new InputStreamReader(gzipIs, "UTF-8")); + StringBuilder sb = new StringBuilder(); + String s; + while ((s = br.readLine()) != null) { + sb.append(s); + } + br.close(); + return sb.toString(); + } + public static boolean removeAllFiles(File f) { if (f == null) { return false;