Java Decompress Byte Array decompressString(byte[] compressedData)

Here you can find the source of decompressString(byte[] compressedData)

Description

decompress String

License

Open Source License

Declaration

public static String decompressString(byte[] compressedData) 

Method Source Code


//package com.java2s;
/*// w w  w  . j av a  2  s .com
 * @(#) StringUtils.java Jul 20, 2005
 * Copyright 2005 Frequency Marketing, Inc. All rights reserved.
 * Frequency Marketing, Inc. PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import java.util.zip.DataFormatException;

import java.util.zip.Inflater;

public class Main {
    public static String decompressString(byte[] compressedData) {
        //      Create the decompressor and give it the data to compress
        Inflater decompressor = new Inflater();
        decompressor.setInput(compressedData);

        // Create an expandable byte array to hold the decompressed data
        ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.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) {
            }
        }
        try {
            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

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

Related

  1. decompressGzip(byte[] compressed)
  2. decompressGZIP(byte[] data)
  3. decompressGzipByteArray(byte[] compressedByteArray)
  4. decompressObject(byte[] bytes)
  5. decompressString(byte[] compressed)
  6. decompressString(byte[] compressedString)
  7. decompressStringFromByteArray(byte[] compressedString)