Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.ByteArrayOutputStream;

import java.io.IOException;
import java.util.zip.DataFormatException;

import java.util.zip.Inflater;

public class Main {
    public static byte[] decompressZLIB(byte[] input) throws IOException {
        Inflater decompressor = new Inflater();
        decompressor.setInput(input);
        // Create an expandable byte array to hold the decompressed data
        ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);

        // Decompress the data
        byte[] buf = new byte[1024];
        while (!decompressor.finished()) {
            try {
                int count = decompressor.inflate(buf);
                bos.write(buf, 0, count);
            } catch (DataFormatException e) {
                throw new IOException(e.toString());
            }
        }
        bos.close();

        // Get the decompressed data
        byte[] decompressedData = bos.toByteArray();
        return decompressedData;
    }
}