(Java) Ungzip Base64 String
Suppose you have a gzip in base64 representation that contains a text file, such as XML. This example shows how to decompress and access the string.
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkGzip gzip = new CkGzip();
String gzipBase64 = "H4sIAAAAAAAE ... X6aZjXO3EwAA";
CkBinData bd = new CkBinData();
boolean success = bd.AppendEncoded(gzipBase64,"base64");
success = gzip.UncompressBd(bd);
if (success != true) {
System.out.println(gzip.lastErrorText());
return;
}
String strXml = bd.getString("utf-8");
System.out.println("XML:");
System.out.println(strXml);
}
}
|