Example usage for java.util.zip GZIPInputStream close

List of usage examples for java.util.zip GZIPInputStream close

Introduction

In this page you can find the example usage for java.util.zip GZIPInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:Main.java

static byte[] decompress(byte[] compressed) throws IOException {
    int nRead;//from   w w w . ja v a2s  . c  om
    byte[] data = new byte[2048];
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    GZIPInputStream gzip = new GZIPInputStream(bis);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    while ((nRead = gzip.read(data, 0, data.length)) != -1) {
        buffer.write(data, 0, nRead);
    }

    gzip.close();
    bis.close();
    return buffer.toByteArray();
}

From source file:CompressTransfer.java

/**
 * ?/*  w w w  .ja v  a2  s. com*/
 *
 * @param is
 * @param os
 * @throws Exception
 */
public static void decompress(InputStream is, OutputStream os) throws Exception {

    GZIPInputStream gis = new GZIPInputStream(is);
    int count;
    byte data[] = new byte[BUFFER];
    while ((count = gis.read(data, 0, BUFFER)) != -1) {
        os.write(data, 0, count);
    }

    gis.close();
}

From source file:fr.dutra.confluence2wordpress.util.CodecUtils.java

public static String decodeAndExpand(String encoded) throws IOException {
    GZIPInputStream gzis = new GZIPInputStream(
            new Base64InputStream(new ByteArrayInputStream(encoded.getBytes(UTF_8))));
    try {// w  ww  .  j av a2s.  co  m
        return IOUtils.toString(gzis, UTF_8);
    } finally {
        gzis.close();
    }
}

From source file:Main.java

static byte[] decompress(byte[] compressed) throws IOException {
    int nRead;/*w w  w  .j  a  va  2  s  .co  m*/
    byte[] data = new byte[2048];
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    GZIPInputStream gzip = new GZIPInputStream(bis);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();

    while ((nRead = gzip.read(data, 0, data.length)) != -1) {
        buffer.write(data, 0, nRead);
    }

    bis.close();
    gzip.close();
    return buffer.toByteArray();
}

From source file:com.streamsets.datacollector.util.UntarUtility.java

/**
 * Ungzip an input file into an output file.
 * <p>//from  w w w . ja  v  a  2 s  . c o m
 * The output file is created in the output folder, having the same name as the input file, minus the '.gz' extension.
 * @param inputFile the input .gz file
 * @param outputDir the output directory file.
 * @throws IOException
 * @throws FileNotFoundException
 * @return The {@File} with the ungzipped content.
 * @throws ArchiveException
 */
public static List<File> unGzip(final File inputFile, final File outputDir)
        throws FileNotFoundException, IOException, ArchiveException {
    LOG.info(String.format("Ungzipping %s to dir %s.", inputFile.getAbsolutePath(),
            outputDir.getAbsolutePath()));

    final File outputFile = new File(outputDir,
            inputFile.getName().substring(0, inputFile.getName().length() - 3));

    final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile));
    final FileOutputStream out = new FileOutputStream(outputFile);

    IOUtils.copy(in, out);

    in.close();
    out.close();

    return unTar(outputFile, outputDir);
}

From source file:Main.java

public static byte[] decompressGzip(byte[] compressed) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    GZIPInputStream gis = new GZIPInputStream(bis);
    try {/*  w w  w .ja  v a  2  s.co m*/
        byte[] buffer = new byte[READ_BUFFER_SIZE];
        int read = 0;
        while ((read = gis.read(buffer)) != -1) {
            bos.write(buffer, 0, read);
        }
    } finally {
        gis.close();
    }

    return bos.toByteArray();
}

From source file:com.pinterest.terrapin.zookeeper.ViewInfo.java

public static ViewInfo fromCompressedJson(byte[] compressedJson) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(compressedJson);
    GZIPInputStream zipIs = new GZIPInputStream(in);
    ViewInfo viewInfo = fromJson(IOUtils.toByteArray(zipIs));
    in.close();//  w  w  w.ja  v  a2 s  .  co  m
    zipIs.close();
    return viewInfo;
}

From source file:deodex.tools.TarGzUtils.java

/**
 * Ungzip an input file into an output file.
 * <p>/*from   w  w w.  ja va  2  s.  c  om*/
 * The output file is created in the output folder, having the same name
 * as the input file, minus the '.gz' extension. 
 * 
 * @param inputFile     the input .gz file
 * @param outputDir     the output directory file. 
 * @throws IOException 
 * @throws FileNotFoundException
 *  
 * @return  The {@File} with the ungzipped content.
 */
public static File unGzip(final File inputFile, final File outputDir)
        throws FileNotFoundException, IOException {

    final File outputFile = new File(outputDir,
            inputFile.getName().substring(0, inputFile.getName().length() - 3));

    final GZIPInputStream in = new GZIPInputStream(new FileInputStream(inputFile));
    final FileOutputStream out = new FileOutputStream(outputFile);

    IOUtils.copy(in, out);

    in.close();
    out.close();

    return outputFile;
}

From source file:Main.java

public static byte[] decompressInGzip(byte[] compressData, int offset, int length) throws Exception {

    ByteArrayInputStream bis = new ByteArrayInputStream(compressData, offset, length);
    GZIPInputStream gzipInStream = new GZIPInputStream(bis);

    ByteArrayOutputStream bos = new ByteArrayOutputStream();

    int count;/*  ww  w .j a  va2  s. co  m*/
    byte[] buf = new byte[1024];
    while ((count = gzipInStream.read(buf)) > 0) {
        bos.write(buf, 0, count);
    }
    gzipInStream.close();

    byte[] originalData = bos.toByteArray();
    bos.close();

    return originalData;
}

From source file:Main.java

public static final byte[] uncompress(final byte[] bytes) {
    if (bytes == null) {
        throw new NullPointerException("byte[] is NULL !");
    }//  w w w .  j av a 2 s  .c  o m
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
    byte[] buffer = new byte[bytes.length];
    int length;
    try {
        GZIPInputStream gis = new GZIPInputStream(bais);
        while ((length = gis.read(buffer)) != -1) {
            bos.write(buffer, 0, length);
        }
        byte[] moreBytes = bos.toByteArray();
        bos.close();
        bais.close();
        gis.close();
        bos = null;
        bais = null;
        gis = null;
        return moreBytes;
    } catch (IOException e) {
        return null;
    }
}