use of java.io.FilterOutputStream in project javaee7-samples by javaee-samples.
the class MyServerWriterInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext wic) throws IOException, WebApplicationException {
System.out.println("MyServerWriterInterceptor");
wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@Override
public void write(int b) throws IOException {
baos.write(b);
super.write(b);
}
@Override
public void close() throws IOException {
System.out.println("MyServerWriterInterceptor --> " + baos.toString());
super.close();
}
});
wic.proceed();
}
use of java.io.FilterOutputStream in project javaee7-samples by javaee-samples.
the class MyClientWriterInterceptor method aroundWriteTo.
@Override
public void aroundWriteTo(WriterInterceptorContext wic) throws IOException, WebApplicationException {
System.out.println("MyClientWriterInterceptor");
wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@Override
public void write(int b) throws IOException {
baos.write(b);
super.write(b);
}
@Override
public void close() throws IOException {
System.out.println("MyClientWriterInterceptor --> " + baos.toString());
super.close();
}
});
// wic.setOutputStream(new FilterOutputStream(wic.getOutputStream()) {
//
// @Override
// public void write(int b) throws IOException {
// System.out.println("**** " + (char)b);
// super.write(b);
// }
//
// });
wic.proceed();
}
use of java.io.FilterOutputStream in project voldemort by voldemort.
the class AdminCommandStream method writeBinary.
private static void writeBinary(File outputFile, Printable printable) throws IOException {
OutputStream outputStream = null;
if (outputFile == null) {
outputStream = new FilterOutputStream(System.out) {
@Override
public void close() throws IOException {
flush();
}
};
} else {
outputStream = new FileOutputStream(outputFile);
}
DataOutputStream dataOutputStream = new DataOutputStream(new BufferedOutputStream(outputStream));
try {
printable.printTo(dataOutputStream);
} finally {
dataOutputStream.close();
}
}
use of java.io.FilterOutputStream in project gerrit by GerritCodeReview.
the class RestApiServlet method stackBase64.
private static BinaryResult stackBase64(HttpServletResponse res, final BinaryResult src) throws IOException {
BinaryResult b64;
long len = src.getContentLength();
if (0 <= len && len <= (7 << 20)) {
b64 = base64(src);
} else {
b64 = new BinaryResult() {
@Override
public void writeTo(OutputStream out) throws IOException {
try (OutputStreamWriter w = new OutputStreamWriter(new FilterOutputStream(out) {
@Override
public void close() {
// Do not close out, but only w and e.
}
}, ISO_8859_1);
OutputStream e = BaseEncoding.base64().encodingStream(w)) {
src.writeTo(e);
}
}
};
}
res.setHeader("X-FYI-Content-Encoding", "base64");
res.setHeader("X-FYI-Content-Type", src.getContentType());
return b64.setContentType("text/plain").setCharacterEncoding(ISO_8859_1);
}
use of java.io.FilterOutputStream in project poi by apache.
the class AesZipFileZipEntrySource method copyToFile.
private static void copyToFile(InputStream is, File tmpFile, CipherAlgorithm cipherAlgorithm, byte[] keyBytes, byte[] ivBytes) throws IOException, GeneralSecurityException {
SecretKeySpec skeySpec = new SecretKeySpec(keyBytes, cipherAlgorithm.jceId);
Cipher ciEnc = CryptoFunctions.getCipher(skeySpec, cipherAlgorithm, ChainingMode.cbc, ivBytes, Cipher.ENCRYPT_MODE, "PKCS5Padding");
ZipInputStream zis = new ZipInputStream(is);
FileOutputStream fos = new FileOutputStream(tmpFile);
ZipOutputStream zos = new ZipOutputStream(fos);
ZipEntry ze;
while ((ze = zis.getNextEntry()) != null) {
// the cipher output stream pads the data, therefore we can't reuse the ZipEntry with set sizes
// as those will be validated upon close()
ZipEntry zeNew = new ZipEntry(ze.getName());
zeNew.setComment(ze.getComment());
zeNew.setExtra(ze.getExtra());
zeNew.setTime(ze.getTime());
// zeNew.setMethod(ze.getMethod());
zos.putNextEntry(zeNew);
FilterOutputStream fos2 = new FilterOutputStream(zos) {
// don't close underlying ZipOutputStream
@Override
public void close() {
}
};
CipherOutputStream cos = new CipherOutputStream(fos2, ciEnc);
IOUtils.copy(zis, cos);
cos.close();
fos2.close();
zos.closeEntry();
zis.closeEntry();
}
zos.close();
fos.close();
zis.close();
}
Aggregations