Java Unzip File uncompress(String compressedValue)

Here you can find the source of uncompress(String compressedValue)

Description

Uncompress a string value that was compressed using GZIP.

License

Apache License

Declaration

public static String uncompress(String compressedValue) throws IOException 

Method Source Code


//package com.java2s;
/*/*from  w  w  w .  j  a  va2  s.c  o m*/
 * Copyright (C) 2017 CenturyLink, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

import java.util.zip.GZIPInputStream;

public class Main {
    /**
     * Uncompress a string value that was compressed using GZIP.
     */
    public static String uncompress(String compressedValue) throws IOException {
        if (compressedValue == null)
            return null;

        ByteArrayInputStream in = new ByteArrayInputStream(compressedValue.getBytes("ISO-8859-1"));
        GZIPInputStream gzip = null;
        Reader reader = null;
        try {
            String value = "";
            gzip = new GZIPInputStream(in);
            reader = new InputStreamReader(gzip, "ISO-8859-1");
            int i;
            while ((i = reader.read()) != -1)
                value += (char) i;
            return value;
        } finally {
            if (gzip != null)
                gzip.close();
            if (reader != null)
                reader.close();
        }
    }
}

Related

  1. uncompress(ByteArrayInputStream bais)
  2. uncompress(File zipFile, File folder)
  3. uncompress(final InputStream inputStream)
  4. uncompress(final String zipFileName, final String directory)
  5. uncompress(String chemin, String tempPrefix)
  6. uncompress(String inputCompressedFile, File outputFile)
  7. uncompress(String inputFile, String toDir)
  8. uncompress(String str)
  9. uncompress(ZipInputStream zipIn)