Example usage for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap

List of usage examples for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap

Introduction

In this page you can find the example usage for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap.

Prototype

public MimetypesFileTypeMap() 

Source Link

Document

The default constructor.

Usage

From source file:org.nuxeo.ecm.platform.groups.audit.seam.ExportGroupManagementActions.java

public String downloadExcelListedGroupsExport() throws ClientException {
    FacesContext context = FacesContext.getCurrentInstance();
    ExternalContext econtext = context.getExternalContext();
    HttpServletResponse response = (HttpServletResponse) econtext.getResponse();
    File excelReport = excelExportListedGroupsDefinition();

    response.setContentType(new MimetypesFileTypeMap().getContentType(excelReport));
    response.setHeader("Content-disposition", "attachment; filename=\"" + excelReport.getName() + "\"");
    response.setHeader("Content-Length", String.valueOf(excelReport.length()));
    try {/*  ww w  .j  ava 2  s  .  c  om*/
        ServletOutputStream os = response.getOutputStream();
        InputStream in = new FileInputStream(excelReport);
        FileUtils.copy(in, os);
        os.flush();
        in.close();
        os.close();
        context.responseComplete();
    } catch (Exception e) {
        log.error("Failure : " + e.getMessage());
    }
    return null;
}

From source file:org.apache.tajo.storage.http.ExampleHttpServerHandler.java

/**
 * Sets the content type header for the HTTP Response
 * @param response HTTP response//from ww w  . j  a va  2s  . c om
 * @param file file to extract content type
 */
private static void setContentTypeHeader(HttpResponse response, File file) {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    response.headers().set(CONTENT_TYPE, mimeTypesMap.getContentType(file.getPath()));
}

From source file:com.emc.ecs.sync.filter.LocalCacheFilter.java

@Override
public void filter(SyncObject obj) {

    // write to local cache
    log.info("writing " + obj + " to local cache");
    cacheTarget.filter(obj);//from w ww. j a v a2  s . c  om

    // re-create source
    File cacheFile = new File(obj.getTargetIdentifier());
    FileSyncObject cacheObj = new FileSyncObject(cacheSource, new MimetypesFileTypeMap(), cacheFile,
            obj.getRelativePath(), true);

    try {
        // send cached object to real target
        log.info("writing cache of " + obj + " to target");
        getNext().filter(cacheObj);

        // apply downstream changes to original object
        obj.setTargetIdentifier(cacheObj.getTargetIdentifier());
        obj.setMetadata(cacheObj.getMetadata());
    } finally {
        // try to clean up cache to limit disk usage
        // leave directories for post-sync cleanup since they will likely cause contention
        try {
            if (!cacheObj.isDirectory()) {
                log.debug("deleting local cache of " + obj);
                cacheSource.delete(cacheObj);
            }
        } catch (Throwable t) {
            log.warn("could not clean up cache object " + cacheObj);
        }
    }
}

From source file:de.iai.ilcd.services.SourceResource.java

/**
 * Get an external file from the source//from www .j  a v  a  2  s.c  om
 * 
 * @param uuid
 *            UUID of the source
 * @param fileName
 *            name of the file to get
 * @return response for client
 */
@GET
@Path("{uuid}/{fileName}")
@Produces({ "image/*", "application/*" })
public Response getExternalFile(@PathParam("uuid") String uuid, @PathParam("fileName") String fileName) {

    DataSetDao<Source, ?, ?> daoObject = this.getFreshDaoInstance();

    // fix uuid, if not in the right format
    GlobalRefUriAnalyzer analyzer = new GlobalRefUriAnalyzer(uuid);
    uuid = analyzer.getUuidAsString();

    Source source = daoObject.getByUuid(uuid);

    if (source == null) {
        throw new WebApplicationException(404);
    }

    DigitalFile requestedFile = null;
    for (DigitalFile file : source.getFiles()) {
        if (file.getFileName().equals(fileName)) {
            requestedFile = file;
            break;
        }

    }

    if (requestedFile == null) {
        throw new WebApplicationException(404);
    }

    File file = new File(requestedFile.getAbsoluteFileName());
    if (!file.exists()) {
        throw new WebApplicationException(404);
    }

    String mt = new MimetypesFileTypeMap().getContentType(file);
    // if it's a PDF document, set MIME type to application/pdf
    if (file.getName().toLowerCase().endsWith(".pdf"))
        mt = "application/pdf";

    return Response.ok(file, mt).build();
}

From source file:dk.dma.msiproxy.common.repo.FileTypes.java

/**
 * Returns the content type of the file, or null if unknown
 * @param path the file to check/* w  w  w  .j  a v  a  2 s.  co m*/
 * @return the content type of the file, or null if unknown
 */
public String getContentType(Path path) {
    try {
        // For some reason unknown, this does not work
        // String type = Files.probeContentType(path);
        return new MimetypesFileTypeMap().getContentType(path.toFile());
    } catch (Exception e) {
        // Unknown type
        return null;
    }
}

From source file:org.bonitasoft.connectors.bonita.AddDocuments.java

/**
 * get file mimeType/*from   ww w  . ja  va2  s.  co  m*/
 * 
 * @param file
 * @return String
 */
private String getType(File file) {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    String mimeType = mimeTypesMap.getContentType(file);
    return mimeType;
}

From source file:org.craftercms.cstudio.publishing.processor.SearchAttachmentProcessor.java

private void update(String siteId, String root, List<String> fileList, boolean isDelete) throws IOException {
    for (String fileName : fileList) {
        String mimeType = null;/*w ww  .  ja va  2s.  c  o  m*/
        File file = new File(root + fileName);
        MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
        mimeType = mimeTypesMap.getContentType(fileName);
        if (supportedMimeTypes.contains(mimeType) && !isDelete) {
            searchService.updateDocument(siteId, fileName, file);
        } else if (isDelete) {
            searchService.delete(siteId, fileName);
        }
    }
}

From source file:org.commonjava.aprox.core.ctl.ContentController.java

public String getContentType(final String path) {
    return new MimetypesFileTypeMap().getContentType(path);
}

From source file:com.emc.ecs.sync.source.FilesystemSource.java

public FilesystemSource() {
    mimeMap = new MimetypesFileTypeMap();
    filter = new SourceFilter();
}

From source file:com.github.cxt.Myjersey.jerseycore.FileResource.java

@Path("store/{path:.*}")
@GET//from w  w w  . ja v  a 2s .  c o  m
public Response storeInfo(@PathParam("path") String path, @Context HttpServletRequest request)
        throws Exception {
    File file = new File(request.getServletContext().getRealPath("data/" + path));
    if (file.exists()) {
        if (file.isDirectory()) {
            return listfile(path, file);
        } else {
            String mt = new MimetypesFileTypeMap().getContentType(file);
            //????,?download2
            return Response.ok(file, mt)
                    .header("Content-disposition",
                            "attachment;filename=" + file.getName() + ";filename*=UTF-8''"
                                    + URLEncoder.encode(file.getName(), "UTF-8"))
                    .header("ragma", "No-cache").header("Cache-Control", "no-cache").build();
        }
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<html>").append("\r\n").append("<head><title>404 Not Found</title></head>").append("\r\n")
            .append("<body bgcolor=\"white\">").append("\r\n").append("<center><h1>404 Not Found</h1></center>")
            .append("\r\n").append("</body>").append("\r\n").append("</html>");
    return Response.ok(sb.toString()).header("Content-Type", "text/html;charset=utf-8").build();
}