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));
}
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;
}
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);
}
}
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);
}
}
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();
}
Aggregations