use of javax.activation.MimetypesFileTypeMap in project phoebus by ControlSystemStudio.
the class AttachmentsViewController method addFiles.
private void addFiles(List<File> files) {
MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
for (File file : files) {
OlogAttachment ologAttachment = new OlogAttachment();
ologAttachment.setFile(file);
ologAttachment.setFileName(file.getName());
String mimeType = fileTypeMap.getContentType(file.getName());
if (mimeType.startsWith("image")) {
ologAttachment.setContentType("image");
} else {
ologAttachment.setContentType("file");
}
attachments.add(ologAttachment);
}
}
use of javax.activation.MimetypesFileTypeMap in project LabyCookies by Lezurex.
the class WebUtils method getResource.
/**
* Loads a file form the resource folder and gets its MIME type.
*
* @param path Valid path starting in resources folder
* @return {@link Resource} object with useful information for web usage
*/
public Resource getResource(String path) {
final ClassLoader classLoader = getClass().getClassLoader();
final InputStream stream = classLoader.getResourceAsStream(path);
if (stream == null) {
throw new IllegalArgumentException("File \"" + path + "\" was not found!");
} else {
if (path.endsWith(".js")) {
return new Resource(stream, "text/javascript");
} else if (path.endsWith(".css")) {
return new Resource(stream, "text/css");
}
return new Resource(stream, new MimetypesFileTypeMap().getContentType(path));
}
}
use of javax.activation.MimetypesFileTypeMap in project cineast by vitrivr.
the class ImageCodebookGenerator method generate.
@Override
public void generate(Path source, Path destination, int words) throws IOException {
long start = System.currentTimeMillis();
final Decoder<BufferedImage> decoder = new DefaultImageDecoder();
final MimetypesFileTypeMap filetypemap = new MimetypesFileTypeMap("mime.types");
/* Filter the list of files and aggregate it. */
/* Prepare array dequeue. */
ArrayDeque<Path> files = Files.walk(source).filter(path -> {
if (decoder.supportedFiles() != null) {
String type = filetypemap.getContentType(path.toString());
return decoder.supportedFiles().contains(type);
} else {
return true;
}
}).collect(Collectors.toCollection(ArrayDeque::new));
/* Prepare data-structures to track progress. */
int max = files.size();
int counter = 0;
int skipped = 0;
char[] progressBar = new char[15];
int update = max / progressBar.length;
/* */
System.out.println(String.format("Creating codebook of %d words from %d files.", words, files.size()));
/*
* Iterates over the files Dequeue. Every element that has been processed in removed from that Dequeue.
*/
Path path = null;
while ((path = files.poll()) != null) {
if (decoder.init(path, null, null)) {
BufferedImage image = decoder.getNext();
if (image != null) {
this.process(image);
} else {
skipped++;
}
} else {
skipped++;
}
if (counter % update == 0) {
this.updateProgressBar(progressBar, max, counter);
}
System.out.print(String.format("\rAdding vectors to codebook: %d/%d files processed (%d skipped) |%s| (Memory left: %.2f/%.2f GB)", counter, max, skipped, String.valueOf(progressBar), Runtime.getRuntime().freeMemory() / 1000000.0f, Runtime.getRuntime().totalMemory() / 1000000.0f));
counter++;
}
/* Dispose of unnecessary elements. */
files = null;
progressBar = null;
/* Start clustering.*/
System.out.println(String.format("\nClustering... this could take a while."));
this.cluster.process(words);
/* Save file...*/
System.out.println(String.format("Saving vocabulary with %d entries.", words));
UtilIO.save(this.cluster.getAssignment(), destination.toString());
long duration = System.currentTimeMillis() - start;
System.out.println(String.format("Done! Took me %dhours %dmin %dsec", TimeUnit.MILLISECONDS.toHours(duration), TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration)));
}
use of javax.activation.MimetypesFileTypeMap in project Fame by zzzzbw.
the class BackupController method exportArticle.
@PostMapping("export/{articleId}")
public ResponseEntity<Resource> exportArticle(@PathVariable Integer articleId) throws UnsupportedEncodingException {
Resource file = backupService.exportArticle(articleId);
String fileName = URLEncoder.encode(file.getFilename(), "UTF-8");
String type = new MimetypesFileTypeMap().getContentType(fileName);
return ResponseEntity.ok().header(HttpHeaders.CONTENT_TYPE, type).header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\"").header(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION).body(file);
}
use of javax.activation.MimetypesFileTypeMap in project clearth by exactpro.
the class LogsBean method getThreadDumps.
// *** Thread dumps routines ***
public StreamedContent getThreadDumps() {
if (!logsDir.exists())
return null;
try {
if (!outputDir.exists())
outputDir.mkdir();
ThreadDumpGenerator threadDumpGenerator = new ThreadDumpGenerator();
File result = threadDumpGenerator.writeThreadDump(outputDir, UserInfoUtils.getUserName() + "_thread_dump.txt");
result.deleteOnExit();
return new DefaultStreamedContent(new FileInputStream(result), new MimetypesFileTypeMap().getContentType(result), "thread_dump.txt");
} catch (Exception e) {
String msg = "Could not generate thread dumps";
getLogger().error(msg, e);
MessageUtils.addErrorMessage(msg, ExceptionUtils.getDetailedMessage(e));
return null;
}
}
Aggregations