Android : How to compressed Large String with gzip in android

on Saturday, August 16, 2014


I try to compressed large string in android Like this:



try {
String str = "MyLarge String";
ByteArrayOutputStream rstBao = new ByteArrayOutputStream(str.length());
GZIPOutputStream zos = new GZIPOutputStream(rstBao);
zos.write(str.getBytes());
IOUtils.closeQuietly(zos);

byte[] bytes = rstBao.toByteArray();

String compressedString = Base64.encodeToString(bytes, true);
Log.i("Compressed", compressedString);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




but this code return outofmemory error.

outofmemory return in "Base64.encodeToString(bytes, true);" line

please help me if anyone know that.

Thank You.


0 comments:

Post a Comment