List of usage examples for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap
public MimetypesFileTypeMap()
From source file:org.yes.cart.web.filter.ImageFilter.java
public ImageFilter(final ImageService imageService, final SystemService systemService) { this.imageService = imageService; this.systemService = systemService; fileTypeMap = new MimetypesFileTypeMap(); fileTypeMap.addMimeTypes("image/bmp bmp"); fileTypeMap.addMimeTypes("application/x-shockwave-flash swf"); }
From source file:org.seedstack.seed.web.internal.WebResourceResolverImpl.java
@Inject WebResourceResolverImpl(final Application application, final Injector injector, @Named("SeedWebResourcesPath") final String resourcePath) { Configuration configuration = application.getConfiguration(); this.injector = injector; this.resourcePath = resourcePath; this.classpathLocation = "META-INF/resources" + resourcePath; this.classLoader = SeedReflectionUtils.findMostCompleteClassLoader(WebResourceResolverImpl.class); this.docrootLocation = resourcePath; this.mimetypesFileTypeMap = new MimetypesFileTypeMap(); this.serveMinifiedResources = configuration .getBoolean(WebPlugin.WEB_PLUGIN_PREFIX + ".resources.minification-support", true); this.serveGzippedResources = configuration .getBoolean(WebPlugin.WEB_PLUGIN_PREFIX + ".resources.gzip-support", true); this.onTheFlyGzipping = configuration.getBoolean(WebPlugin.WEB_PLUGIN_PREFIX + ".resources.gzip-on-the-fly", true);//from w w w .java 2 s . c o m }
From source file:org.nuxeo.ecm.platform.groups.audit.seam.ExportGroupManagementActions.java
public String downloadExcelAllGroupsExport() throws ClientException { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext econtext = context.getExternalContext(); HttpServletResponse response = (HttpServletResponse) econtext.getResponse(); File excelReport = excelExportAllGroupsDefinition(); response.setContentType(new MimetypesFileTypeMap().getContentType(excelReport)); response.setHeader("Content-disposition", "attachment; filename=\"" + excelReport.getName() + "\""); response.setHeader("Content-Length", String.valueOf(excelReport.length())); try {//from w ww . j a v a 2s .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:annis.administration.BinaryImportHelper.java
public BinaryImportHelper(File f, File dataDir, String toplevelCorpusName, long corpusRef, Map<String, String> mimeTypeMapping) { this.fileSource = f; // create a file-name in the form of "filename_toplevelcorpus_UUID.ending", thus we // need to split the file name into its components String baseName = FilenameUtils.getBaseName(fileSource.getName()); String extension = FilenameUtils.getExtension(fileSource.getName()); UUID uuid = UUID.randomUUID(); String outputName = ""; if (toplevelCorpusName == null) { outputName = baseName + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension); } else {/*from ww w . ja v a 2 s . c o m*/ outputName = baseName + "_" + CommonHelper.getSafeFileName(toplevelCorpusName) + "_" + uuid.toString() + (extension.isEmpty() ? "" : "." + extension); } fileDestination = new File(dataDir, outputName); String fileEnding = FilenameUtils.getExtension(f.getName()); if (mimeTypeMapping.containsKey(fileEnding)) { this.mimeType = mimeTypeMapping.get(fileEnding); } else { this.mimeType = new MimetypesFileTypeMap().getContentType(fileSource); } this.corpusRef = corpusRef; }
From source file:org.commonjava.indy.ftest.core.content.SetContentTypeNotExistsTest.java
@Test public void run() throws Exception { final String content = "This is some content " + System.currentTimeMillis() + "." + System.nanoTime(); final String path = "org/foo/foo-project/1/foo-1.jar"; server.expect("GET", server.formatUrl(STORE, path), (request, response) -> { response.setStatus(200);/*from w w w . ja va 2s . c o m*/ response.setHeader("Content-Length", Integer.toString(content.length())); PrintWriter writer = response.getWriter(); writer.write(content); }); client.stores().create(new RemoteRepository(STORE, server.formatUrl(STORE)), "adding remote", RemoteRepository.class); try (HttpResources httpResources = client.module(IndyRawHttpModule.class).getHttp() .getRaw(client.content().contentPath(remote, STORE, path))) { HttpResponse response = httpResources.getResponse(); String contentType = response.getFirstHeader("Content-Type").getValue(); assertThat(contentType, equalTo(new MimetypesFileTypeMap().getContentType(path))); } }
From source file:de.iai.ilcd.services.FileResource.java
@GET @Path("{sourceId}/{fileName}") @Produces({ "image/*", "application/*" }) public Response getExternalFile(@PathParam("sourceId") String sourceId, @PathParam("fileName") String fileName) { SourceDao sourceDao = new SourceDao(); Source source = sourceDao.getByDataSetId(sourceId); if (source == null) throw new WebApplicationException(404); DigitalFile requestedFile = null;// w ww .j a v a 2 s. c o m for (DigitalFile file : source.getFiles()) { if (file.getFileName().equals(fileName)) { requestedFile = file; break; } } if (requestedFile == null) throw new WebApplicationException(404); // logger.trace("I am here with file: " // +requestedFile.getAbsoluteFileName()); File file = new File(requestedFile.getAbsoluteFileName()); if (!file.exists()) throw new WebApplicationException(404); String mt = new MimetypesFileTypeMap().getContentType(file); return Response.ok(file, mt).build(); }
From source file:com.emc.ecs.sync.target.ArchiveFileTarget.java
@Override public SyncObject reverseFilter(SyncObject obj) { File destFile = createFile(targetRoot.getPath(), obj.getRelativePath()); obj.setTargetIdentifier(destFile.getPath()); return new TFileSyncObject(this, new MimetypesFileTypeMap(), createFile(targetRoot.getPath(), obj.getRelativePath()), obj.getRelativePath()); }
From source file:com.qatickets.service.TicketFileAttachmentService.java
@Transactional(readOnly = false) public void save(File incomingFile, int ticketId, UserProfile user) { log.debug("Save attachment: " + incomingFile); Ticket ticket = ticketService.findById(ticketId); if (ticket != null) { // save attachment TicketFileAttachment a = new TicketFileAttachment(); a.setDate(new Date()); a.setFileName(spamService.clean(incomingFile.getName(), 200)); a.setImage(false);/*from w w w.j a va 2 s . c o m*/ a.setTicket(ticket); a.setUser(user); try { a.setContentType(Files.probeContentType(new File(incomingFile.getName()).toPath())); } catch (IOException e1) { a.setContentType(new MimetypesFileTypeMap().getContentType(incomingFile.getName())); } a.setSize(incomingFile.length()); log.debug("Saved attachment: " + a); this.dao.save(a); // attach to body ticket.addAttachment(a); this.ticketService.save(ticket); // upload to aws /* File file = new File(SystemUtils.getJavaIoTmpDir(), UUID.randomUUID().toString()); try { multpartFile.transferTo(file); s3client.save(a, user, file); } catch (Exception e) { log.error("Error: ", e); } finally { FileUtils.deleteQuietly(file); } */ } }
From source file:com.emc.vipr.sync.source.FilesystemSource.java
public FilesystemSource() { mimeMap = new MimetypesFileTypeMap(); }