GZip.java 1.73 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.adobe.livecycle.formsservice.sharedutils;

import com.adobe.livecycle.formsservice.logging.FormsLogger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;

public class GZip {
    public static byte[] ungzip(byte[] input) throws IOException {
        long startTime = FormsLogger.logPerformance(false, 0, "<GZip-ungzip>");
        ByteArrayInputStream is = new ByteArrayInputStream(input);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        GZIPInputStream gis = new GZIPInputStream(is);
        byte[] chrs = new byte[512];
        try {
            int nRead;
            while ((nRead = gis.read(chrs, 0, 512)) != -1) {
                os.write(chrs, 0, nRead);
            }
        }
        catch (EOFException oEOF) {
            // empty catch block
        }
        gis.close();
        is.close();
        byte[] outputbytes = os.toByteArray();
        os.close();
        FormsLogger.logPerformance(true, startTime, "</GZip-ungzip>");
        return outputbytes;
    }

    public static byte[] gzip(byte[] input) throws IOException {
        long startTime = FormsLogger.logPerformance(false, 0, "<GZip-gzip>");
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        GZIPOutputStream gos = new GZIPOutputStream(os);
        gos.write(input, 0, input.length);
        gos.close();
        byte[] outputbytes = os.toByteArray();
        os.close();
        FormsLogger.logPerformance(true, startTime, "</GZip-gzip>");
        return outputbytes;
    }
}