Search in sources :

Example 1 with CloseShieldOutputStream

use of org.apache.commons.io.output.CloseShieldOutputStream in project lucene-solr by apache.

the class HttpSolrCall method writeResponse.

private void writeResponse(SolrQueryResponse solrRsp, QueryResponseWriter responseWriter, Method reqMethod) throws IOException {
    try {
        Object invalidStates = solrReq.getContext().get(CloudSolrClient.STATE_VERSION);
        // the response for each request
        if (invalidStates != null)
            solrRsp.add(CloudSolrClient.STATE_VERSION, invalidStates);
        // Now write it out
        final String ct = responseWriter.getContentType(solrReq, solrRsp);
        // don't call setContentType on null
        if (null != ct)
            response.setContentType(ct);
        if (solrRsp.getException() != null) {
            NamedList info = new SimpleOrderedMap();
            int code = ResponseUtils.getErrorInfo(solrRsp.getException(), info, log);
            solrRsp.add("error", info);
            response.setStatus(code);
        }
        if (Method.HEAD != reqMethod) {
            // Prevent close of container streams, see SOLR-8933
            OutputStream out = new CloseShieldOutputStream(response.getOutputStream());
            QueryResponseWriterUtil.writeQueryResponse(out, responseWriter, solrReq, solrRsp, ct);
        }
    //else http HEAD request, nothing to write out, waited this long just to get ContentType
    } catch (EOFException e) {
        log.info("Unable to write response, client closed connection or we are shutting down", e);
    }
}
Also used : NamedList(org.apache.solr.common.util.NamedList) OutputStream(java.io.OutputStream) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream) EOFException(java.io.EOFException) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Example 2 with CloseShieldOutputStream

use of org.apache.commons.io.output.CloseShieldOutputStream in project jena by apache.

the class RdfStats method main.

/**
     * Entry point method
     * 
     * @param args
     *            Arguments
     */
public static void main(String[] args) {
    try (ColorizedOutputStream<BasicColor> error = new AnsiBasicColorizedOutputStream(new CloseShieldOutputStream(System.err))) {
        try {
            // Run and exit with result code if no errors bubble up
            // Note that the exit code may still be a error code
            int res = ToolRunner.run(new Configuration(true), new RdfStats(), args);
            System.exit(res);
        } catch (Throwable e) {
            // This will only happen if Hadoop option parsing errors
            // The run() method will handle its error itself
            error.setForegroundColor(BasicColor.RED);
            error.println(e.getMessage());
            e.printStackTrace(error);
        }
    }
    // If any errors bubble up exit with non-zero code
    System.exit(1);
}
Also used : BasicColor(com.github.rvesse.airline.io.colors.BasicColor) AnsiBasicColorizedOutputStream(com.github.rvesse.airline.io.output.AnsiBasicColorizedOutputStream) Configuration(org.apache.hadoop.conf.Configuration) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Example 3 with CloseShieldOutputStream

use of org.apache.commons.io.output.CloseShieldOutputStream in project xwiki-platform by xwiki.

the class XMLWriter method writeBase64.

/**
 * Writes the <code>{@link Element}</code>, including its <code>{@link
 * org.dom4j.Attribute}</code>s, using the <code>{@link InputStream}</code> encoded in Base64 for its content.
 *
 * @param element <code>{@link Element}</code> to output.
 * @param is <code>{@link InputStream}</code> that will be fully read and encoded in Base64 into the element
 *            content.
 * @throws IOException a problem occurs during reading or writing.
 */
public void writeBase64(Element element, InputStream is) throws IOException {
    writeOpen(element);
    flush();
    try (Base64OutputStream base64 = new Base64OutputStream(new CloseShieldOutputStream(this.out))) {
        IOUtils.copy(is, base64);
    }
    writeClose(element);
}
Also used : Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Example 4 with CloseShieldOutputStream

use of org.apache.commons.io.output.CloseShieldOutputStream in project coprhd-controller by CoprHD.

the class SupportPackageCreator method nextEntry.

private OutputStream nextEntry(ZipOutputStream zip, String path) throws IOException {
    Logger.debug("Adding entry: %s", path);
    ZipEntry entry = new ZipEntry(path);
    zip.putNextEntry(entry);
    return new CloseShieldOutputStream(zip);
}
Also used : ZipEntry(java.util.zip.ZipEntry) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Example 5 with CloseShieldOutputStream

use of org.apache.commons.io.output.CloseShieldOutputStream in project coprhd-controller by CoprHD.

the class SupportAuditPackageCreator method nextEntry.

private OutputStream nextEntry(ZipOutputStream zip, String path) throws IOException {
    Logger.debug("Adding entry: %s", path);
    ZipEntry entry = new ZipEntry(path);
    zip.putNextEntry(entry);
    return new CloseShieldOutputStream(zip);
}
Also used : ZipEntry(java.util.zip.ZipEntry) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Aggregations

CloseShieldOutputStream (org.apache.commons.io.output.CloseShieldOutputStream)12 ZipEntry (java.util.zip.ZipEntry)4 BasicColor (com.github.rvesse.airline.io.colors.BasicColor)2 AnsiBasicColorizedOutputStream (com.github.rvesse.airline.io.output.AnsiBasicColorizedOutputStream)2 Base64OutputStream (org.apache.commons.codec.binary.Base64OutputStream)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 ParseException (com.github.rvesse.airline.parser.errors.ParseException)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 VDJCLibrary (io.repseq.core.VDJCLibrary)1 GClone (io.repseq.gen.GClone)1 GGene (io.repseq.gen.GGene)1 GCloneGenerator (io.repseq.gen.dist.GCloneGenerator)1 GCloneModel (io.repseq.gen.dist.GCloneModel)1 BufferedOutputStream (java.io.BufferedOutputStream)1 EOFException (java.io.EOFException)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1