use of javax.activation.MimetypesFileTypeMap in project clearth by exactpro.
the class AutomationReportsBean method getLogsBySelectedRun.
public StreamedContent getLogsBySelectedRun() {
try {
File shortLog = extractLogsBySelectedRun();
if (shortLog == null) {
String errMsg = "Could not make short log file by selected run";
MessageUtils.addErrorMessage(errMsg, "These logs were lost");
getLogger().debug(errMsg);
return null;
}
return new DefaultStreamedContent(new FileInputStream(shortLog), new MimetypesFileTypeMap().getContentType(shortLog), shortLog.getName());
} catch (IOException e) {
String errMsg = "Could not download logs by run";
MessageUtils.addErrorMessage(errMsg, ExceptionUtils.getDetailedMessage(e));
getLogger().debug(errMsg, e);
return null;
}
}
use of javax.activation.MimetypesFileTypeMap in project gameserver by jiayaoguang.
the class HttpStaticFileServerHandler method setContentTypeHeader.
/**
* Sets the content type header for the HTTP Response
*
* @param response
* HTTP response
* @param file
* file to extract content type
*/
private static void setContentTypeHeader(HttpResponse response, File file) {
MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
String fileName = file.getName();
int pointIndex = fileName.lastIndexOf('.');
if (pointIndex > 0 && pointIndex < fileName.length()) {
String fileSuffix = fileName.substring(pointIndex + 1);
if ("jpg".equals(fileSuffix) || "jpeg".equals(fileSuffix)) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "image/jpeg");
return;
} else if ("png".equals(fileSuffix)) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "image/png");
return;
} else if ("xml".equals(fileSuffix)) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/xml");
return;
} else if ("json".equals(fileSuffix)) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/json");
return;
} else if ("docx".equals(fileSuffix)) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/msword");
return;
} else if ("pdf".equals(fileSuffix)) {
response.headers().set(HttpHeaderNames.CONTENT_TYPE, "application/pdf");
return;
}
}
response.headers().set(HttpHeaderNames.CONTENT_TYPE, mimeTypesMap.getContentType(file.getPath()));
}
use of javax.activation.MimetypesFileTypeMap in project nzyme by lennartkoopmann.
the class NzymeLeaderInjectionBinder method configure.
@Override
protected void configure() {
bind(nzyme).to(NzymeLeader.class);
bind(new MimetypesFileTypeMap()).to(MimetypesFileTypeMap.class);
bind(nzyme.getObjectMapper()).to(ObjectMapper.class);
try {
bind(new IndexHtmlGenerator(nzyme.getConfiguration(), new AssetManifest())).to(IndexHtmlGenerator.class);
} catch (IOException e) {
throw new RuntimeException("Could not bind IndexHtmlGenerator.", e);
}
}
Aggregations