Search in sources :

Example 11 with FilterOutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 12 with FilterOutputStream

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();
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream)

Example 13 with FilterOutputStream

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();
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) DataOutputStream(java.io.DataOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FilterOutputStream(java.io.FilterOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 14 with FilterOutputStream

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);
}
Also used : FilterOutputStream(java.io.FilterOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) CountingOutputStream(com.google.common.io.CountingOutputStream) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) FilterOutputStream(java.io.FilterOutputStream) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult)

Example 15 with FilterOutputStream

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();
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) CipherOutputStream(javax.crypto.CipherOutputStream) SecretKeySpec(javax.crypto.spec.SecretKeySpec) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) Cipher(javax.crypto.Cipher) FilterOutputStream(java.io.FilterOutputStream)

Aggregations

FilterOutputStream (java.io.FilterOutputStream)36 IOException (java.io.IOException)27 Support_OutputStream (tests.support.Support_OutputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ByteArrayInputStream (java.io.ByteArrayInputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 File (java.io.File)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 BufferedOutputStream (java.io.BufferedOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 FileInputStream (java.io.FileInputStream)3 FilterInputStream (java.io.FilterInputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ByteSink (com.google.common.io.ByteSink)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 Writer (java.io.Writer)2