Dim bytearray() As Byte = "some string to zip".GetBytes("UTF-8")
Log(bytearray.Length)
Dim compress() As Byte = jo.RunMethod("compress", Array(bytearray, False))
Log(compress.Length)
Log(bc.HexFromBytes(compress))
Log("now trying to decompress...")
Dim uncompressed() As Byte = jo.RunMethod("decompress", Array( compress,False ))
Log(bc.StringFromBytes(uncompressed,"UTF8"))
#if Java
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public static byte[] compress(byte[] input, boolean GZIPFormat) throws IOException {
Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, GZIPFormat);
compressor.setInput(input);
compressor.finish();
ByteArrayOutputStream bao = new ByteArrayOutputStream();
byte[] readBuffer = new byte[1024];
int readCount = 0;
while (!compressor.finished()) {
readCount = compressor.deflate(readBuffer);
if (readCount > 0) {
bao.write(readBuffer, 0, readCount);
}
}
compressor.end();
return bao.toByteArray();
}
public static byte[] decompress(byte[] input, boolean GZIPFormat)
throws IOException, DataFormatException {
Inflater decompressor = new Inflater(GZIPFormat);
decompressor.setInput(input);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
byte[] readBuffer = new byte[1024];
int readCount = 0;
while (!decompressor.finished()) {
readCount = decompressor.inflate(readBuffer);
if (readCount > 0) {
bao.write(readBuffer, 0, readCount);
}
}
decompressor.end();
return bao.toByteArray();
}
#End If