Example usage for java.util.zip GZIPOutputStream GZIPOutputStream

List of usage examples for java.util.zip GZIPOutputStream GZIPOutputStream

Introduction

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

Prototype

public GZIPOutputStream(OutputStream out) throws IOException 

Source Link

Document

Creates a new output stream with a default buffer size.

Usage

From source file:com.pinterest.deployservice.common.TarUtils.java

/**
 * Bundle the given map as a list of files, with key as file name and value as content.
 *///  w  w w.j av  a  2 s . co  m
public static byte[] tar(Map<String, String> data) throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    TarArchiveOutputStream taos = new TarArchiveOutputStream(new GZIPOutputStream(os));
    // TAR originally didn't support long file names, so enable the support for it
    taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);

    // Get to putting all the files in the compressed output file
    for (Map.Entry<String, String> entry : data.entrySet()) {
        byte[] bytes = entry.getValue().getBytes("UTF8");
        InputStream is = new ByteArrayInputStream(bytes);
        addInputStreamToTar(taos, is, entry.getKey(), bytes.length, TarArchiveEntry.DEFAULT_FILE_MODE);
    }

    taos.close();
    return os.toByteArray();
}

From source file:de.ocarthon.core.utility.GzipCompression.java

public static void compress(String input, OutputStream os) throws IOException {
    GZIPOutputStream gos = null;/*  w ww.ja  va2 s.  c  o m*/
    PrintWriter pw = null;

    try {
        gos = new GZIPOutputStream(os);
        pw = new PrintWriter(gos);
        pw.write(input);
    } finally {
        IOUtils.closeQuietly(pw);
        IOUtils.closeQuietly(gos);
    }
}

From source file:com.mirth.connect.connectors.http.HttpUtil.java

public static byte[] compressGzip(String content, String charset) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = new GZIPOutputStream(baos);
    gzos.write(content.getBytes(charset));
    gzos.close();/* ww  w  . j  a  va  2 s  .  c om*/
    return baos.toByteArray();
}

From source file:com.oprisnik.semdroid.utils.FileUtils.java

public static void writeObjectToZipStream(Object object, OutputStream output) throws IOException {
    writeObjectToStream(object, new GZIPOutputStream(output));
}

From source file:net.es.nsi.common.util.ContentType.java

public static OutputStream encode(String contentType, OutputStream os) throws IOException {
    if (XGZIP.equalsIgnoreCase(contentType)) {
        return new GZIPOutputStream(os);
    } else {//from  w ww .  j a v a  2s .c o  m
        return os;
    }
}

From source file:de.qaware.chronix.converter.common.Compression.java

/**
 * Compresses the given byte[]/*  w w  w.  j a v  a 2 s .  com*/
 *
 * @param decompressed - the byte[] to compress
 * @return the byte[] compressed
 */
public static byte[] compress(byte[] decompressed) {
    if (decompressed == null) {
        return new byte[] {};
    }
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(decompressed.length);
    OutputStream gzipOutputStream = null;
    try {
        gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
        gzipOutputStream.write(decompressed);
        gzipOutputStream.flush();
        byteArrayOutputStream.flush();
    } catch (IOException e) {
        LOGGER.error("Exception occurred while compressing gzip stream.", e);
        return null;
    } finally {
        IOUtils.closeQuietly(gzipOutputStream);
        IOUtils.closeQuietly(byteArrayOutputStream);
    }

    return byteArrayOutputStream.toByteArray();
}

From source file:com.basistech.rosette.api.AbstractTest.java

protected static byte[] gzip(String text) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (GZIPOutputStream out = new GZIPOutputStream(baos)) {
        out.write(text.getBytes(StandardCharsets.UTF_8));
    }//from  www . j  a v  a 2  s . co m
    return baos.toByteArray();
}

From source file:com.qwazr.utils.SerializationUtils.java

/**
 * Write an object to a file using a buffered stream and GZIP compression.
 *
 * @param obj  the object to write//from  ww w . jav a2s . c o  m
 * @param file the destination file
 * @throws IOException
 */
public static void serialize(Serializable obj, File file) throws IOException {
    FileOutputStream os = new FileOutputStream(file);
    BufferedOutputStream bos = new BufferedOutputStream(os);
    GZIPOutputStream zos = new GZIPOutputStream(bos);
    try {
        SerializationUtils.serialize(obj, zos);
    } finally {
        IOUtils.close(zos, bos, os);
    }
}

From source file:com.streamsets.datacollector.cluster.TarFileCreator.java

public static void createLibsTarGz(List<URL> apiCl, List<URL> containerCL,
        Map<String, List<URL>> streamsetsLibsCl, Map<String, List<URL>> userLibsCL, File staticWebDir,
        File outputFile) throws IOException {
    long now = System.currentTimeMillis() / 1000L;
    FileOutputStream dest = new FileOutputStream(outputFile);
    TarOutputStream out = new TarOutputStream(new BufferedOutputStream(new GZIPOutputStream(dest), 65536));
    // api-lib/*from   ww w .j  ava 2  s.c om*/
    String prefix = ClusterModeConstants.API_LIB;
    out.putNextEntry(new TarEntry(TarHeader.createHeader(prefix, 0L, now, true)));
    addClasspath(prefix, out, apiCl);
    prefix = ClusterModeConstants.CONTAINER_LIB;
    out.putNextEntry(new TarEntry(TarHeader.createHeader(prefix, 0L, now, true)));
    addClasspath(prefix, out, containerCL);
    addLibrary(ClusterModeConstants.STREAMSETS_LIBS, now, out, streamsetsLibsCl);
    addLibrary(ClusterModeConstants.USER_LIBS, now, out, userLibsCL);
    tarFolder(null, staticWebDir.getAbsolutePath(), out);
    out.putNextEntry(new TarEntry(TarHeader.createHeader("libs-common-lib", 0L, now, true)));
    out.flush();
    out.close();
}

From source file:io.kahu.hawaii.util.call.http.util.HttpResponseToGZipConverter.java

public void toFile(HttpResponse response, File file) throws ServerException {
    FileOutputStream outputStream = null;
    GZIPOutputStream gzipOS = null;
    try {/* w  w w .ja va  2s.  c o m*/
        outputStream = new FileOutputStream(file);
        gzipOS = new GZIPOutputStream(outputStream);
        response.getEntity().writeTo(gzipOS);
    } catch (IOException e) {
        throw new ServerException(ServerError.IO, e);
    } finally {
        IOUtils.closeQuietly(gzipOS);
        IOUtils.closeQuietly(outputStream);
    }
}