Example usage for java.util.zip GZIPOutputStream close

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

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Writes remaining compressed data to the output stream and closes the underlying stream.

Usage

From source file:uk.ac.bbsrc.tgac.miso.integration.util.IntegrationUtils.java

public static byte[] compress(byte[] content) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Base64OutputStream b64os = new Base64OutputStream(baos);
    GZIPOutputStream gzip = new GZIPOutputStream(b64os);
    gzip.write(content);/*from   w ww  .ja  v  a 2  s.  c om*/
    gzip.close();
    return baos.toByteArray();
}

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 {//  w w w  .j a  v a2s  .co m
        gout.write(strBytes, 0, strBytes.length);
    } finally {
        gout.close();
    }
    return bout.toString();
}

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

public static byte[] compressString(String value) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(value.length());
    GZIPOutputStream gos = new GZIPOutputStream(baos);
    gos.write(Base64.encode(value.getBytes(StandardCharsets.UTF_8)));
    gos.close();
    byte[] compressed = baos.toByteArray();
    baos.close();//w w w  .  j  a v a  2  s.c om
    return compressed;
}

From source file:NettyServerHandler.java

public static String compress(String str) throws IOException {
    if (str == null || str.length() == 0) {
        return str;
    }/*from  www  .  j  a  va  2s. c  om*/
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    gzip.write(str.getBytes());
    gzip.close();
    String outStr = out.toString("ISO-8859-1");
    return outStr;
}

From source file:org.pentaho.di.cluster.HttpUtil.java

public static String encodeBase64ZippedString(String in) throws IOException {
    Charset charset = Charset.forName(Const.XML_ENCODING);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    GZIPOutputStream gzos = new GZIPOutputStream(baos);
    gzos.write(in.getBytes(charset));/*from  ww w  . j  a  va2 s  .  c om*/
    gzos.close();

    return new String(Base64.encodeBase64(baos.toByteArray()));
}

From source file:edu.harvard.i2b2.fhir.Utils.java

public static byte[] compress(final String data, final String encoding) throws IOException {
    if (data == null || data.length() == 0) {
        return null;
    } else {/*from   w  ww. j ava  2 s  . com*/
        byte[] bytes = data.getBytes(encoding);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream os = new GZIPOutputStream(baos);
        os.write(bytes, 0, bytes.length);
        os.close();
        byte[] result = baos.toByteArray();
        return result;
    }
}

From source file:ee.ria.xroad.opmonitordaemon.QueryRequestHandler.java

static byte[] compress(String data) throws IOException {
    byte[] dataBytes = data.getBytes(StandardCharsets.UTF_8);

    try (ByteArrayOutputStream bos = new ByteArrayOutputStream(dataBytes.length)) {
        GZIPOutputStream gzip = new GZIPOutputStream(bos);
        gzip.write(dataBytes);/*from w w w  .ja v a  2s.c  o  m*/
        gzip.close();

        return bos.toByteArray();
    }
}

From source file:it.acubelab.smaph.SmaphUtils.java

/**
 * Compress a string with GZip.//w w w.ja v a  2  s  .com
 * 
 * @param str
 *            the string.
 * @return the compressed string.
 * @throws IOException
 *             if something went wrong during compression.
 */
public static byte[] compress(String str) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    gzip.write(str.getBytes());
    gzip.close();
    return out.toByteArray();
}

From source file:rapture.util.StringUtil.java

/**
 * Compress the passed in string and base64 encode it
 * @param content//from   ww  w  .  j a  v  a 2 s. c o m
 * @return
 */
public static String base64Compress(String content) {
    if (content == null || content.isEmpty()) {
        return content;
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip;
    try {
        gzip = new GZIPOutputStream(out);
        gzip.write(content.getBytes("UTF-8"));
        gzip.close();
    } catch (IOException e) {
        throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error compressing content",
                e);
    }

    // Now with out, base64
    byte[] encoding = Base64.encodeBase64(out.toByteArray());
    return new String(encoding);
}

From source file:co.cask.hydrator.transforms.Compressor.java

public static byte[] compressGZIP(byte[] input) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip = new GZIPOutputStream(out);
    gzip.write(input, 0, input.length);// w w  w  .  j  ava2 s.  c o  m
    gzip.close();
    return out.toByteArray();
}