Add method for converting gzip to string to Algorithms

This commit is contained in:
Alexander Sytnyk 2018-03-28 10:58:19 +03:00
parent 9d4ebfadcf
commit 69f891c82f

View file

@ -6,6 +6,7 @@ import net.osmand.PlatformUtil;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.Closeable; import java.io.Closeable;
import java.io.EOFException; import java.io.EOFException;
import java.io.File; import java.io.File;
@ -26,6 +27,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.zip.GZIPInputStream;
/** /**
@ -452,6 +454,18 @@ public class Algorithms {
return responseBody; 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) { public static boolean removeAllFiles(File f) {
if (f == null) { if (f == null) {
return false; return false;