本文整理了Java中java.net.URLConnection.getFileNameMap()
方法的一些代码示例,展示了URLConnection.getFileNameMap()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。URLConnection.getFileNameMap()
方法的具体详情如下:
包路径:java.net.URLConnection
类名称:URLConnection
方法名:getFileNameMap
[英]Returns the table which is used by all URLConnection instances to determine the MIME-type according to a file extension.
[中]返回所有URLConnection实例用于根据文件扩展名确定MIME类型的表。
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 根据文件名获取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);
}
代码示例来源:origin: looly/hutool
/**
* 根据文件扩展名获得MimeType
*
* @param filePath 文件路径或文件名
* @return MimeType
* @since 4.1.15
*/
public static String getMimeType(String filePath) {
return URLConnection.getFileNameMap().getContentTypeFor(filePath);
}
代码示例来源:origin: looly/hutool
/**
* 根据文件扩展名获得MimeType
*
* @param filePath 文件路径或文件名
* @return MimeType
* @since 4.1.15
*/
public static String getMimeType(String filePath) {
return URLConnection.getFileNameMap().getContentTypeFor(filePath);
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
public static String getMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
代码示例来源:origin: biezhi/wechat-api
/**
* 获取文件 MimeType
*
* @param fileUrl
* @return
*/
public static String getMimeType(String fileUrl) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String type = fileNameMap.getContentTypeFor(fileUrl);
return type;
}
代码示例来源:origin: robovm/robovm
/**
* 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);
}
代码示例来源:origin: shopizer-ecommerce/shopizer
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;
}
代码示例来源:origin: shopizer-ecommerce/shopizer
try {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
代码示例来源:origin: shopizer-ecommerce/shopizer
FileNameMap fileNameMap = URLConnection.getFileNameMap();
代码示例来源:origin: shopizer-ecommerce/shopizer
FileNameMap fileNameMap = URLConnection.getFileNameMap();
StringBuilder nodePath = new StringBuilder();
nodePath.append(product.getMerchantStore().getCode());
代码示例来源:origin: shopizer-ecommerce/shopizer
@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;
}
代码示例来源:origin: shopizer-ecommerce/shopizer
FileNameMap fileNameMap = URLConnection.getFileNameMap();
代码示例来源:origin: shopizer-ecommerce/shopizer
outputStaticContentData.setFile(output);
outputStaticContentData
.setMimeType(URLConnection.getFileNameMap().getContentTypeFor(contentFileName));
outputStaticContentData.setFileName(contentFileName);
outputStaticContentData.setFileContentType(fileContentType);
代码示例来源:origin: 0opslab/opslabJutil
/**
* 获取文件的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);
}
代码示例来源:origin: stackoverflow.com
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor("alert.gif");
代码示例来源:origin: stackoverflow.com
File request = new File(uri);
mbuffer = new FileInputStream(request);
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String mimeType = fileNameMap.getContentTypeFor(uri);
代码示例来源:origin: cn-ljb/rxjava_for_android
/**
* 初始化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();
}
代码示例来源:origin: apache/wicket
/**
* Returns the mime type for given filename.
*
* @param fileName
* @return mime type
*/
public String getMimeType(final String fileName)
{
return URLConnection.getFileNameMap().getContentTypeFor(fileName);
}
代码示例来源:origin: huxq17/SwipeCardsView
private String getContentType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentType = fileNameMap.getContentTypeFor(path);
if (contentType == null) {
contentType = "application/octet-stream";
}
return contentType;
}
代码示例来源:origin: Odoo-mobile/framework
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();
}
}
内容来源于网络,如有侵权,请联系作者删除!