Search in sources :

Example 6 with Base64OutputStream

use of org.apache.commons.codec.binary.Base64OutputStream in project commons by twitter.

the class Base64ZlibCodecTest method testDecodeGzip.

public void testDecodeGzip() throws Exception {
    final byte[] input = createRandomBytes(10240);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    final OutputStream os = new GZIPOutputStream(new Base64OutputStream(out));
    os.write(input);
    os.close();
    final String encoded = new String(out.toByteArray(), "8859_1");
    assertTrue(encoded.startsWith("H4sIAAAAAAAAA"));
    Assert.assertArrayEquals(input, Base64ZlibCodec.decode(encoded));
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream)

Example 7 with Base64OutputStream

use of org.apache.commons.codec.binary.Base64OutputStream in project hudson-2.x by hudson.

the class ConsoleNote method encodeToBytes.

private ByteArrayOutputStream encodeToBytes() throws IOException {
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(buf));
    oos.writeObject(this);
    oos.close();
    ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(new Base64OutputStream(buf2, true, -1, null));
    buf2.write(PREAMBLE);
    dos.writeInt(buf.size());
    buf.writeTo(dos);
    dos.close();
    buf2.write(POSTAMBLE);
    return buf2;
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream)

Example 8 with Base64OutputStream

use of org.apache.commons.codec.binary.Base64OutputStream in project camel by apache.

the class Base64DataFormat method marshalStreaming.

private void marshalStreaming(Exchange exchange, Object graph, OutputStream stream) throws Exception {
    InputStream decoded = ExchangeHelper.convertToMandatoryType(exchange, InputStream.class, graph);
    Base64OutputStream base64Output = new Base64OutputStream(stream, true, lineLength, lineSeparator);
    try {
        IOHelper.copy(decoded, base64Output);
    } finally {
        IOHelper.close(decoded, base64Output);
    }
}
Also used : Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) InputStream(java.io.InputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream)

Example 9 with Base64OutputStream

use of org.apache.commons.codec.binary.Base64OutputStream in project ignite by apache.

the class AbstractListener method call.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public final void call(Object... args) {
    final Ack cb = safeCallback(args);
    args = removeCallback(args);
    try {
        final Map<String, Object> params;
        if (args == null || args.length == 0)
            params = Collections.emptyMap();
        else if (args.length == 1)
            params = fromJSON(args[0], Map.class);
        else
            throw new IllegalArgumentException("Wrong arguments count, must be <= 1: " + Arrays.toString(args));
        if (pool == null)
            pool = newThreadPool();
        pool.submit(new Runnable() {

            @Override
            public void run() {
                try {
                    Object res = execute(params);
                    // We can GZip manually for now.
                    if (res instanceof RestResult) {
                        RestResult restRes = (RestResult) res;
                        if (restRes.getData() != null) {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
                            Base64OutputStream b64os = new Base64OutputStream(baos, true, 0, null);
                            GZIPOutputStream gzip = new GZIPOutputStream(b64os);
                            gzip.write(restRes.getData().getBytes(UTF8));
                            gzip.close();
                            restRes.zipData(baos.toString());
                        }
                    }
                    cb.call(null, toJSON(res));
                } catch (Exception e) {
                    cb.call(e, null);
                }
            }
        });
    } catch (Exception e) {
        cb.call(e, null);
    }
}
Also used : RestResult(org.apache.ignite.console.agent.rest.RestResult) Ack(io.socket.client.Ack) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) Map(java.util.Map)

Example 10 with Base64OutputStream

use of org.apache.commons.codec.binary.Base64OutputStream in project pentaho-kettle by pentaho.

the class HttpUtil method encodeBase64ZippedString.

public static String encodeBase64ZippedString(String in) throws IOException {
    Charset charset = Charset.forName(Const.XML_ENCODING);
    ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
    try (Base64OutputStream base64OutputStream = new Base64OutputStream(baos);
        GZIPOutputStream gzos = new GZIPOutputStream(base64OutputStream)) {
        gzos.write(in.getBytes(charset));
    }
    return baos.toString();
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) Charset(java.nio.charset.Charset) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream)

Aggregations

Base64OutputStream (org.apache.commons.codec.binary.Base64OutputStream)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 GZIPOutputStream (java.util.zip.GZIPOutputStream)4 Base64InputStream (org.apache.commons.codec.binary.Base64InputStream)4 CloseShieldOutputStream (org.apache.commons.io.output.CloseShieldOutputStream)2 LivyCluster (com.microsoft.azure.hdinsight.sdk.cluster.LivyCluster)1 HDIException (com.microsoft.azure.hdinsight.sdk.common.HDIException)1 SparkSession (com.microsoft.azure.hdinsight.sdk.common.livy.interactive.SparkSession)1 ClusterFileBase64BufferedOutputStream (com.microsoft.azure.hdinsight.sdk.io.spark.ClusterFileBase64BufferedOutputStream)1 Ack (io.socket.client.Ack)1 BufferedOutputStream (java.io.BufferedOutputStream)1 Closeable (java.io.Closeable)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 FilterOutputStream (java.io.FilterOutputStream)1 IOException (java.io.IOException)1