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.mbrlabs.mundus.utils.TerrainIO.java

/**
 * Binary gziped format./*  w  w w  . j a v a 2s . c o  m*/
 *
 * @param terrain
 */
public static void exportTerrain(ProjectContext projectContext, Terrain terrain) {
    float[] data = terrain.heightData;
    long start = System.currentTimeMillis();

    // create file
    File file = new File(FilenameUtils.concat(projectContext.path, terrain.terraPath));
    try {
        FileUtils.touch(file);
    } catch (IOException e) {
        e.printStackTrace();
    }

    // write .terra
    try (DataOutputStream outputStream = new DataOutputStream(
            new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))))) {

        for (float f : data) {
            outputStream.writeFloat(f);
        }
        outputStream.flush();
    } catch (IOException e) {
        e.printStackTrace();
        return;
    }

    // write splatmap
    SplatMap splatmap = terrain.getTerrainTexture().getSplatmap();
    if (splatmap != null) {
        splatmap.savePNG(Gdx.files.absolute(FilenameUtils.concat(projectContext.path, splatmap.getPath())));
    }

    //Log.debug("Terrain export execution time (" + data.length + " floats): "
    //        + (System.currentTimeMillis() - start) + " ms");
}

From source file:com.dbmojo.Util.java

/** GZIP encode a String */
public static String gzipString(String inStr) throws Exception {
    byte[] strBytes = inStr.getBytes();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    GZIPOutputStream gout = new GZIPOutputStream(bout);

    try {//from www. ja  va 2  s  .co m
        gout.write(strBytes, 0, strBytes.length);
    } finally {
        gout.close();
    }
    return bout.toString();
}

From source file:com.zimbra.cs.service.util.ItemDataFile.java

public static void create(String path, Set<MailItem.Type> types, String cset, OutputStream os)
        throws IOException {
    File f = new File(path);
    TarOutputStream tos = new TarOutputStream(new GZIPOutputStream(os), cset == null ? "UTF-8" : cset);

    tos.setLongFileMode(TarOutputStream.LONGFILE_GNU);
    try {//www  . jav  a2 s.  co  m
        if (f.isDirectory())
            addDir(f, f.getPath(), types, tos);
        else
            addFile(f, f.getParent(), types, tos);
    } finally {
        tos.close();
    }
}

From source file:com.eviware.soapui.impl.wsdl.support.CompressedStringSupport.java

public static void setString(CompressedStringConfig compressedStringConfig, String value) {
    synchronized (compressedStringConfig) {
        long limit = SoapUI.getSettings().getLong(WsdlSettings.COMPRESSION_LIMIT, 0);
        if (limit > 0 && value.length() >= limit) {
            try {
                ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
                GZIPOutputStream out = new GZIPOutputStream(byteOut);
                out.write(value.getBytes());
                out.finish();// w w  w  . ja v  a 2  s .  c o  m
                value = new String(Base64.encodeBase64(byteOut.toByteArray()));
                compressedStringConfig.setCompression("gzip");
            } catch (IOException e) {
                SoapUI.logError(e);
                compressedStringConfig.unsetCompression();
            }
        } else if (compressedStringConfig.isSetCompression()) {
            compressedStringConfig.unsetCompression();
        }

        compressedStringConfig.setStringValue(value);
    }
}

From source file:com.netflix.dyno.connectionpool.impl.utils.ZipUtils.java

/**
 * Encodes the given byte array and then GZIP compresses it.
 *
 * @param value byte array input//from   www. j  ava2  s  .  c o m
 * @return compressed byte array output
 * @throws IOException
 */
public static byte[] compressBytesNonBase64(byte[] value) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(value.length);
    GZIPOutputStream gos = new GZIPOutputStream(baos);
    gos.write(value);
    gos.close();
    byte[] compressed = baos.toByteArray();
    baos.close();
    return compressed;
}

From source file:com.github.helenusdriver.commons.lang3.SerializationUtils.java

/**
 * Serializes and compresses a given object to the specified stream.
 * <p>/* ww  w . j av  a 2 s  .c  o  m*/
 * The stream will be closed once the object is written.
 * This avoids the need for a finally clause, and maybe also exception
 * handling, in the application code.
 * <p>
 * The stream passed in is not buffered internally within this method.
 * This is the responsibility of your application if desired.
 *
 * @author paouelle
 *
 * @param  obj the object to serialize and compress
 * @param  outputStream the stream to write to
 * @throws SerializationException (runtime) if the serialization fails
 * @throws NullPointerException if <code>outputStream</code> is <code>null</code>
 */
public static void serializeAndCompress(Serializable obj, OutputStream outputStream) {
    org.apache.commons.lang3.Validate.notNull(outputStream, "invalid null outputStream");
    try {
        final GZIPOutputStream os = new GZIPOutputStream(outputStream);

        org.apache.commons.lang3.SerializationUtils.serialize(obj, os);
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}

From source file:com.simiacryptus.mindseye.test.unit.SerializationTest.java

/**
 * Compress gz byte [ ].//from   www  . j a  va2  s.c o  m
 *
 * @param bytes the bytes
 * @return the byte [ ]
 */
public static byte[] compressGZ(byte[] bytes) {
    @Nonnull
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try {
        try (@Nonnull
        GZIPOutputStream out = new GZIPOutputStream(byteArrayOutputStream)) {
            IOUtils.write(bytes, out);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return byteArrayOutputStream.toByteArray();
}

From source file:org.exist.xquery.modules.jfreechart.render.SVGZrenderer.java

@Override
public void render(JFreeChart chart, Configuration config, OutputStream os) throws IOException {
    super.render(chart, config, new GZIPOutputStream(os));
}

From source file:cn.sharesdk.analysis.net.NetworkHelper.java

public static String Base64Gzip(String str) {
    ByteArrayInputStream bais = new ByteArrayInputStream(str.getBytes());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    String result = null;//from   w w  w  . j  a  v  a2 s.  c o  m
    // gzip
    GZIPOutputStream gos;
    try {
        gos = new GZIPOutputStream(baos);
        int count;
        byte data[] = new byte[1024];
        while ((count = bais.read(data, 0, 1024)) != -1) {
            gos.write(data, 0, count);
        }
        gos.finish();
        gos.close();

        byte[] output = baos.toByteArray();
        baos.flush();
        baos.close();
        bais.close();

        result = Base64.encodeToString(output, Base64.NO_WRAP);

    } catch (IOException e) {
        e.printStackTrace();
        Ln.e("NetworkHelper", "Base64Gzip == >>", e);
    }

    //Ln.i("after base64gizp", result);
    return result;
}

From source file:com.hs.mail.util.FileUtils.java

public static void compress(File srcFile, File destFile) throws IOException {
    InputStream input = null;// ww w .  j a va2  s.c  o  m
    OutputStream output = null;
    try {
        input = new BufferedInputStream(new FileInputStream(srcFile));
        output = new GZIPOutputStream(new FileOutputStream(destFile));
        IOUtils.copyLarge(input, output);
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
}