@Override public String getMimeType(String filePath) { String extension = StringUtils.getFilenameExtension(filePath); if (this.mimeTypes.containsKey(extension)) { return this.mimeTypes.get(extension).toString(); } else { try { return Optional.of(Files.probeContentType(Paths.get(filePath))).orElse("application/octet-stream"); } catch (IOException e) { return "application/octet-stream"; } } }
@ExpectWarning("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") void npe3() throws IOException{ use(Files.probeContentType(PATH).length()); }
@Override Tuple<Path, BlobInfo> parse(String... args) throws IOException { if (args.length < 2 || args.length > 3) { throw new IllegalArgumentException(); } Path path = Paths.get(args[0]); String contentType = Files.probeContentType(path); String blob = args.length < 3 ? path.getFileName().toString() : args[2]; return Tuple.of(path, BlobInfo.newBuilder(args[1], blob).setContentType(contentType).build()); }
public static String getMimeType(File file) { try { String answer = java.nio.file.Files.probeContentType(file.toPath()); if (Strings.isNotBlank(answer)) { return answer;
MoreObjects.firstNonNull(Files.probeContentType(path), DEFAULT_CONTENT_TYPE);
IOUtils.copyLarge(in, out); String contentType = Files.probeContentType(tempFile); if (contentType == null) { if (LOGGER.isLoggable(Level.WARNING)) {
.setContentType(Files.probeContentType(localFile.toPath())) .build();
@Override @SuppressFBWarnings("PATH_TRAVERSAL_IN") // suppressing because we are using the getValidFilePath public String getMimeType(String s) { try { String validatedPath = SecurityUtils.getValidFilePath(s); return Files.probeContentType(Paths.get(validatedPath)); } catch (IOException e) { log.warn("Could not find content type for file: " + SecurityUtils.encode(s), e); return null; } }
static SignalServiceAttachmentStream createAttachment(File attachmentFile) throws IOException { InputStream attachmentStream = new FileInputStream(attachmentFile); final long attachmentSize = attachmentFile.length(); String mime = Files.probeContentType(attachmentFile.toPath()); if (mime == null) { mime = "application/octet-stream"; } // TODO mabybe add a parameter to set the voiceNote, preview, width, height and caption option Optional<byte[]> preview = Optional.absent(); Optional<String> caption = Optional.absent(); return new SignalServiceAttachmentStream(attachmentStream, mime, attachmentSize, Optional.of(attachmentFile.getName()), false, preview, 0, 0, caption, null); }
private String getContentType(final Path path) { try { return Files.probeContentType(path); } catch (final IOException exception) { return "application/octet-stream"; //$NON-NLS-1$ } } };
/** * Sets the media type to the media type detected by {@link java.nio.file.Files#probeContentType(java.nio.file.Path)} on * the specified file. * @param value the file to use * @return returns this builder * @throws IOException if an I/O error occurs */ public Builder mediaType(File value) throws IOException { this.mediaType = Files.probeContentType(value.toPath()); return this; }
@Override public String getContentType() throws IOException { return Files.probeContentType(file.toPath()); } }
private static String getContentType(String filename) { try { return (Files.probeContentType(Paths.get(filename))); } catch (IOException exception) { return "text/plain"; } }
@Override public String getContentType( UUID uuid ) throws IOException { final Path path = Paths.get( repository.toString(), uuid.toString() ); final String result = Files.probeContentType( path ); Log.debug( "UUID '{}' content type: {}", uuid, result ); return result; }
private MimeType getMimeType(final Path path) { try { return new MimeType(Files.probeContentType(path)); } catch (final IOException | MimeTypeParseException ex) { ex.printStackTrace(); } return null; }
/** * Sets the media type to the media type detected by {@link java.nio.file.Files#probeContentType(java.nio.file.Path)} on * the specified file. * @param value the path to use * @return returns this builder * @throws IOException if an I/O error occurs */ public Builder mediaType(Path value) throws IOException { details.mediaType(Files.probeContentType(value)); return this; }
public static String readFileContentType(String filePath) throws AppManagementException{ String fileContentType = null; try { fileContentType = Files.probeContentType(Paths.get(filePath)); } catch (IOException e) { throw new AppManagementException("Error occurred while reading file details from file "+filePath); } return fileContentType; }
public static BufferedImage loadImageByMimeType(Path file) throws IOException { String mime = Files.probeContentType(file); Iterable<ImageReader> iter = new IterableFacade<>(ImageIO.getImageReadersByMIMEType(mime)); for (ImageReader reader : iter) { InputStream in = Files.newInputStream(file); try (ImageInputStream ii = ImageIO.createImageInputStream(in);) { reader.setInput(ii); return reader.read(0); } } throw new IOException("No ImageReader found for the file: " + file); }
@Override public InputStream visitPathResource(final PathResourceReference pathResourceReference) throws IOException { final String contentType = Files.probeContentType(pathResourceReference.getPath()); if (!contentTypeAcceptor.accept(contentType)) { throw new IOException("Unexcepted mime type '" + contentType + "'"); //$NON-NLS-1$//$NON-NLS-2$ } return Files.newInputStream(pathResourceReference.getPath()); }
@Override public InputStream visitPathResource(final PathResourceReference pathResourceReference) throws IOException { final String contentType = Files.probeContentType(pathResourceReference.getPath()); if (!contentTypeAcceptor.accept(contentType)) { throw new IOException("Unexcepted mime type '" + contentType + "'"); //$NON-NLS-1$//$NON-NLS-2$ } return Files.newInputStream(pathResourceReference.getPath()); }