本文整理匯總了Java中java.net.URLConnection.getFileNameMap方法的典型用法代碼示例。如果您正苦於以下問題:Java URLConnection.getFileNameMap方法的具體用法?Java URLConnection.getFileNameMap怎麽用?Java URLConnection.getFileNameMap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.URLConnection
的用法示例。
在下文中一共展示了URLConnection.getFileNameMap方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: guessMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
private String guessMimeType(String path)
{
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = null;
try
{
contentTypeFor = fileNameMap.getContentTypeFor(URLEncoder.encode(path, "UTF-8"));
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
if (contentTypeFor == null)
{
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
示例2: probeContentType
import java.net.URLConnection; //導入方法依賴的package包/類
/**
* Invokes the appropriate probe method to guess a file's content type,
* and checks that the content type's syntax is valid.
*/
@Override
public final String probeContentType(Path file) throws IOException {
if (file == null)
throw new NullPointerException("'file' is null");
String result = implProbeContentType(file);
// Fall back to content types property.
if (result == null) {
Path fileName = file.getFileName();
if (fileName != null) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
result = fileNameMap.getContentTypeFor(fileName.toString());
}
}
return (result == null) ? null : parse(result);
}
示例3: guessMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
示例4: getMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
public static String getMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(path);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
示例5: guessMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
/** 根據文件名獲取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);
}
示例6: getMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
/***
* try to get file's MediaType
*
* @param fileName file's name
***/
private String getMimeType(String fileName) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(fileName);
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
示例7: CCFile
import java.net.URLConnection; //導入方法依賴的package包/類
public CCFile(String url){
this.url = url;
if (TextUtils.isEmpty(url)){
this.mimeType = "multipart/form-data;";
}else {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
//url = url.replace("#", ""); //解決文件名中含有#號異常的問題
String contentType = fileNameMap.getContentTypeFor(url.replace("#", ""));
if (contentType == null) {
this.mimeType = MediaType.parse("application/octet-stream").toString();
}
this.mimeType = MediaType.parse(contentType).toString();
}
}
示例8: guessMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
public static MediaType guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
path = path.replace("#", ""); //解決文件名中含有#號異常的問題
String contentType = fileNameMap.getContentTypeFor(path);
if (contentType == null) {
contentType = "application/octet-stream";
}
return MediaType.parse(contentType);
}
示例9: guessMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
/**
* 根據文件名獲取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);
}
示例10: guessMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
private String guessMimeType(String path) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = null;
try {
contentTypeFor = fileNameMap.getContentTypeFor(URLEncoder.encode(path, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (contentTypeFor == null) {
contentTypeFor = "application/octet-stream";
}
return contentTypeFor;
}
示例11: getRequestBody
import java.net.URLConnection; //導入方法依賴的package包/類
/**
* 獲取文件上傳使用的RequestBody,MediaType,通過具體文件獲取,當獲取到null時,使用“text/plain”,作為默認值
*
* @param file
* @return
*/
private static RequestBody getRequestBody(File file) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String contentTypeFor = fileNameMap.getContentTypeFor(file.getAbsolutePath());
contentTypeFor = contentTypeFor == null || "".equals(contentTypeFor) ? "text/plain" : contentTypeFor;
MediaType mediaType = MediaType.parse(contentTypeFor);
return RequestBody.create(mediaType, file);
}
示例12: getFileType
import java.net.URLConnection; //導入方法依賴的package包/類
public static String getFileType(String fn, String defaultType) {
FileNameMap fNameMap = URLConnection.getFileNameMap();
String type = fNameMap.getContentTypeFor(fn);
return type == null ? defaultType : type;
}
示例13: getMimeType
import java.net.URLConnection; //導入方法依賴的package包/類
public static final String getMimeType(String fileUrl) {
FileNameMap fileNameMap = URLConnection.getFileNameMap();
String type = fileNameMap.getContentTypeFor(fileUrl);
return type;
}
示例14: mimeType
import java.net.URLConnection; //導入方法依賴的package包/類
/**
* 獲取文件的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);
}