/** 根据文件名获取MIME类型 */ public static MediaType guessMimeType(String fileName) { FileNameMap fileNameMap = URLConnection.getFileNameMap(); fileName = fileName.replace("#", ""); //解决文件名中含有#号异常的问题 String contentType = fileNameMap.getContentTypeFor(fileName); if (contentType == null) { return HttpParams.MEDIA_TYPE_STREAM; } return MediaType.parse(contentType); }
/** * 根据文件扩展名获得MimeType * * @param filePath 文件路径或文件名 * @return MimeType * @since 4.1.15 */ public static String getMimeType(String filePath) { return URLConnection.getFileNameMap().getContentTypeFor(filePath); }
/** * 根据文件扩展名获得MimeType * * @param filePath 文件路径或文件名 * @return MimeType * @since 4.1.15 */ public static String getMimeType(String filePath) { return URLConnection.getFileNameMap().getContentTypeFor(filePath); }
public static String getMimeType(String path) { FileNameMap fileNameMap = URLConnection.getFileNameMap(); String contentTypeFor = fileNameMap.getContentTypeFor(path); if (contentTypeFor == null) { contentTypeFor = "application/octet-stream"; } return contentTypeFor; }
/** * 获取文件 MimeType * * @param fileUrl * @return */ public static String getMimeType(String fileUrl) { FileNameMap fileNameMap = URLConnection.getFileNameMap(); String type = fileNameMap.getContentTypeFor(fileUrl); return type; }
/** * Determines the MIME-type of the given resource {@code url} by resolving * the filename extension with the internal FileNameMap. Any fragment * identifier is removed before processing. * * @param url * the URL with the filename to get the MIME type. * @return the guessed content type or {@code null} if the type could not be * determined. */ public static String guessContentTypeFromName(String url) { return getFileNameMap().getContentTypeFor(url); }
public File getCroppedImage(File originalFile, int x1, int y1, int width, int height) throws Exception { if(!this.cropeable) { return originalFile; } FileNameMap fileNameMap = URLConnection.getFileNameMap(); String contentType = fileNameMap.getContentTypeFor(originalFile.getName()); String extension = contentType.substring(contentType.indexOf("/"),contentType.length()); BufferedImage image = ImageIO.read(originalFile); BufferedImage out = image.getSubimage(x1, y1, width, height); File tempFile = File.createTempFile("temp", "." + extension ); tempFile.deleteOnExit(); ImageIO.write(out, extension, tempFile); return tempFile; }
try { FileNameMap fileNameMap = URLConnection.getFileNameMap();
FileNameMap fileNameMap = URLConnection.getFileNameMap();
FileNameMap fileNameMap = URLConnection.getFileNameMap(); StringBuilder nodePath = new StringBuilder(); nodePath.append(product.getMerchantStore().getCode());
@Override public List<OutputContentFile> getFiles(final String merchantStoreCode, final FileContentType staticContentType) throws ServiceException { if (cacheManager.getTreeCache() == null) { throw new ServiceException( "CmsStaticContentFileManagerInfinispan has a null cacheManager.getTreeCache()"); } List<OutputContentFile> images = new ArrayList<OutputContentFile>(); try { FileNameMap fileNameMap = URLConnection.getFileNameMap(); String nodePath = this.getNodePath(merchantStoreCode, staticContentType); final Node<String, Object> merchantNode = this.getNode(nodePath); for (String key : merchantNode.getKeys()) { byte[] imageBytes = (byte[]) merchantNode.get(key); OutputContentFile contentImage = new OutputContentFile(); InputStream input = new ByteArrayInputStream(imageBytes); ByteArrayOutputStream output = new ByteArrayOutputStream(); IOUtils.copy(input, output); String contentType = fileNameMap.getContentTypeFor(key); contentImage.setFile(output); contentImage.setMimeType(contentType); contentImage.setFileName(key); images.add(contentImage); } } catch (final Exception e) { LOGGER.error("Error while fetching file for {} merchant ", merchantStoreCode); throw new ServiceException(e); } return images; }
FileNameMap fileNameMap = URLConnection.getFileNameMap();
outputStaticContentData.setFile(output); outputStaticContentData .setMimeType(URLConnection.getFileNameMap().getContentTypeFor(contentFileName)); outputStaticContentData.setFileName(contentFileName); outputStaticContentData.setFileContentType(fileContentType);
/** * 获取文件的Mime类型 * * @param file 需要处理的文件 * @return 返回文件的mime类型 * @throws java.io.IOException */ public final static String mimeType(String file) throws java.io.IOException { FileNameMap fileNameMap = URLConnection.getFileNameMap(); return fileNameMap.getContentTypeFor(file); }
FileNameMap fileNameMap = URLConnection.getFileNameMap(); String mimeType = fileNameMap.getContentTypeFor("alert.gif");
File request = new File(uri); mbuffer = new FileInputStream(request); FileNameMap fileNameMap = URLConnection.getFileNameMap(); String mimeType = fileNameMap.getContentTypeFor(uri);
/** * 初始化Body类型请求参数 * init Body type params */ private RequestBody initRequestBody(Map<String, Object> params) { MultipartBuilder bodyBuilder = new MultipartBuilder().type(MultipartBuilder.FORM); Set<Map.Entry<String, Object>> entries = params.entrySet(); for (Map.Entry<String, Object> entry : entries) { String key = entry.getKey(); Object value = entry.getValue(); if (value instanceof File) { File file = (File) value; try { FileNameMap fileNameMap = URLConnection.getFileNameMap(); String mimeType = fileNameMap.getContentTypeFor(file.getAbsolutePath()); XgoLog.w("mimeType::" + mimeType); bodyBuilder.addFormDataPart(key, file.getName(), RequestBody.create(MediaType.parse(mimeType), file)); } catch (Exception e) { e.printStackTrace(); XgoLog.e("mimeType is Error !"); } } else { XgoLog.w(key + "::" + value); bodyBuilder.addFormDataPart(key, value.toString()); } } return bodyBuilder.build(); }
/** * Returns the mime type for given filename. * * @param fileName * @return mime type */ public String getMimeType(final String fileName) { return URLConnection.getFileNameMap().getContentTypeFor(fileName); }
private String getContentType(String path) { FileNameMap fileNameMap = URLConnection.getFileNameMap(); String contentType = fileNameMap.getContentTypeFor(path); if (contentType == null) { contentType = "application/octet-stream"; } return contentType; }
private void requestIntent(Uri uri) { Intent intent = new Intent(Intent.ACTION_VIEW); FileNameMap mime = URLConnection.getFileNameMap(); String mimeType = mime.getContentTypeFor(uri.getPath()); intent.setDataAndType(uri, mimeType); try { mActivity.startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(mActivity, OResource.string(mActivity, R.string.toast_no_activity_found_to_handle_file), Toast.LENGTH_LONG).show(); } }