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