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.epam.wilma.gepard.testclient.compression.gzip.GzipCompressor.java

/**
 * Compress the input stream with GZIP./*from   w w  w  .  j  ava  2s .  co m*/
 *
 * @param inputStream is the input
 * @return with compressed format
 * @throws IOException if problem occurs during the compression
 */
public InputStream compress(final InputStream inputStream) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gout = new GZIPOutputStream(baos);
    //... Code to read from your original uncompressed data and write to gout.
    IOUtils.copy(inputStream, gout);
    gout.finish();
    //Convert to InputStream.
    return new ByteArrayInputStream(baos.toByteArray());
}

From source file:com.serphacker.serposcope.db.base.ExportDB.java

public boolean export(String path) throws Exception {
    OutputStream os = new FileOutputStream(path, false);
    if (path.endsWith(".gz")) {
        os = new GZIPOutputStream(os);
    }/*from  ww  w  .j  ava 2 s  .c  om*/
    try (OutputStreamWriter osw = new OutputStreamWriter(os, Charset.forName("UTF-8"));
            PrintWriter writer = new PrintWriter(osw);) {
        return export(writer);
    }
}

From source file:io.digibyte.tools.util.BRCompressor.java

public static byte[] gZipCompress(byte[] data) {
    if (data == null)
        return null;
    byte[] compressedData = null;
    try {/*from   w w w  . ja  v a 2 s.c  o  m*/
        ByteArrayOutputStream byteStream = new ByteArrayOutputStream(data.length);
        try {
            GZIPOutputStream zipStream = new GZIPOutputStream(byteStream);
            try {
                zipStream.write(data);
            } finally {
                try {
                    zipStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } finally {
            try {
                byteStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        compressedData = byteStream.toByteArray();
    } catch (Exception e) {
        BRReportsManager.reportBug(e);
        e.printStackTrace();
    }
    return compressedData;
}

From source file:net.acesinc.data.json.generator.log.JsonFileLogger.java

private void flushToJsonGzip(String event) throws IOException {
    try (FileOutputStream output = new FileOutputStream(outputDirectory)) {
        try (Writer writer = new OutputStreamWriter(new GZIPOutputStream(output), "UTF-8")) {
            writer.append(event).append("\n");
        }//from   w  w w.j  av a  2s  .co m
    }
}

From source file:com.fizzed.stork.assembly.AssemblyUtils.java

static public TarArchiveOutputStream createTGZStream(File tgzFile) throws IOException {
    TarArchiveOutputStream tgzout = new TarArchiveOutputStream(
            new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(tgzFile))));
    tgzout.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
    tgzout.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    return tgzout;
}

From source file:co.runrightfast.vertx.core.hazelcast.serializers.CompressedJsonObjectSerializer.java

@Override
public byte[] write(final JsonObject json) throws IOException {
    final byte[] bytes = json.toString().getBytes(UTF_8);
    final ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);
    try (final GZIPOutputStream gzip = new GZIPOutputStream(bos)) {
        gzip.write(bytes);//w w  w.  ja  v  a 2 s.  c om
    }
    return bos.toByteArray();
}

From source file:de.blizzy.backup.Compression.java

public OutputStream getOutputStream(OutputStream out) throws IOException {
    if (this == GZIP) {
        return new GZIPOutputStream(out);
    }/*from  w w  w  .  j a va 2  s .c  o  m*/
    if (this == BZIP2) {
        return new BZip2CompressorOutputStream(out);
    }
    throw new RuntimeException();
}

From source file:com.adaptris.core.services.GzipService.java

/**
 *  @see com.adaptris.core.Service#doService(AdaptrisMessage)
 *//*w  w w .  j a  v  a  2 s.  c om*/
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
    InputStream in = null;
    GZIPOutputStream out = null;
    try {
        in = msg.getInputStream();
        out = new GZIPOutputStream(msg.getOutputStream());
        IOUtils.copy(in, out);
    } catch (Exception e) {
        throw new ServiceException(e);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}

From source file:com.lily.dap.web.util.WebUtils.java

/**
 * Gzip HeaderGZIPOutputStream.//  w  w  w  .  java2 s .co  m
 */
public static OutputStream buildGzipOutputStream(HttpServletResponse response) throws IOException {
    response.setHeader("Content-Encoding", "gzip");
    return new GZIPOutputStream(response.getOutputStream());
}

From source file:org.apache.juneau.rest.test.GzipTest.java

private static InputStream compress(String contents) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(contents.length() >> 1);
    GZIPOutputStream gos = new GZIPOutputStream(baos);
    gos.write(contents.getBytes());/*from   w ww .  ja va2s. c  om*/
    gos.finish();
    gos.close();
    return new ByteArrayInputStream(baos.toByteArray());
}