Search in sources :

Example 61 with MimetypesFileTypeMap

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;
    }
}
Also used : DefaultStreamedContent(org.primefaces.model.DefaultStreamedContent) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 62 with MimetypesFileTypeMap

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()));
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap)

Example 63 with MimetypesFileTypeMap

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);
    }
}
Also used : MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) AssetManifest(horse.wtf.nzyme.rest.web.AssetManifest) IOException(java.io.IOException) IndexHtmlGenerator(horse.wtf.nzyme.rest.web.IndexHtmlGenerator)

Aggregations

MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)63 File (java.io.File)19 IOException (java.io.IOException)15 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)6 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 FileNameMap (java.net.FileNameMap)3 HttpURLConnection (java.net.HttpURLConnection)3 MimeType (javax.activation.MimeType)3 MimeTypeParseException (javax.activation.MimeTypeParseException)3 Response (javax.ws.rs.core.Response)3 Before (org.junit.Before)3 Test (org.junit.Test)3 Failure (org.junit.runner.notification.Failure)3 InvalidKeyException (java.security.InvalidKeyException)2