當前位置: 首頁>>代碼示例>>Java>>正文


Java FileNameMap類代碼示例

本文整理匯總了Java中java.net.FileNameMap的典型用法代碼示例。如果您正苦於以下問題:Java FileNameMap類的具體用法?Java FileNameMap怎麽用?Java FileNameMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FileNameMap類屬於java.net包,在下文中一共展示了FileNameMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: guessMimeType

import java.net.FileNameMap; //導入依賴的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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:PostFormRequest.java

示例2: probeContentType

import java.net.FileNameMap; //導入依賴的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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:AbstractFileTypeDetector.java

示例3: initRequestBody

import java.net.FileNameMap; //導入依賴的package包/類
/**
 * 初始化Body類型請求參數
 * init Body type params
 */
private RequestBody initRequestBody(TreeMap<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();
}
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:30,代碼來源:XgoHttpClient.java

示例4: getContentType

import java.net.FileNameMap; //導入依賴的package包/類
@Override
public ContentType getContentType(final String contentName)
{
    ContentType ret = null;
    final int idx = contentName.lastIndexOf('.');

    if (idx >= 0)
    {
        final String ext = contentName.substring(idx); // Shall not throw IndexOutOfBoundsException.

        final FileNameMap map = URLConnection.getFileNameMap();
        final String contentType = map.getContentTypeFor(contentName);

        if (contentType != null)
        {
            ret = new ContentType(new String[] { ext }, new String[] { contentType }, null, null);
        }
    }

    return ret;
}
 
開發者ID:LizzyProject,項目名稱:Lizzy,代碼行數:22,代碼來源:FileNameMapProvider.java

示例5: getMimeType

import java.net.FileNameMap; //導入依賴的package包/類
/**
 * Determines the mime-type of the passed file-name, based on the extension
 * of the file and not the content.
 *
 * @param fileName the file-name to determine the mime-type for
 * @return the mime-type of the specified file-name, or the default
 * mime-type if not determinable
 * @see Files#DEFAULT_MIMETYPE
 */
public static String getMimeType(final String fileName) {

    if (fileName == null || fileName.equals("")) {
        return DEFAULT_MIMETYPE;
    } else {

        // check the extension
        final String ext = getExtension(fileName);
        final String defMimeType = MIMETYPES.get(ext);

        if (defMimeType == null) {
            final FileNameMap fileNameMap = URLConnection.getFileNameMap();
            final String mimeType = fileNameMap.getContentTypeFor(fileName);

            return "".equals(mimeType) || mimeType == null ? DEFAULT_MIMETYPE
                    : mimeType;
        } else {
            return defMimeType;
        }
    }
}
 
開發者ID:pmeisen,項目名稱:gen-misc,代碼行數:31,代碼來源:Files.java

示例6: guessMimeType

import java.net.FileNameMap; //導入依賴的package包/類
private String guessMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
 
開發者ID:NaOHAndroid,項目名稱:Logistics-guard,代碼行數:9,代碼來源:OkHttpClientManager.java

示例7: getMimeType

import java.net.FileNameMap; //導入依賴的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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:Utils.java

示例8: guessMimeType

import java.net.FileNameMap; //導入依賴的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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:HttpUtils.java

示例9: guessMimeType

import java.net.FileNameMap; //導入依賴的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;
}
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:14,代碼來源:PostFormRequest.java

示例10: CCFile

import java.net.FileNameMap; //導入依賴的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();
    }
}
 
開發者ID:CodingCodersCode,項目名稱:EvolvingNetLib,代碼行數:16,代碼來源:CCFile.java

示例11: guessMimeType

import java.net.FileNameMap; //導入依賴的package包/類
private 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);
}
 
開發者ID:zhou-you,項目名稱:RxEasyHttp,代碼行數:10,代碼來源:HttpParams.java

示例12: guessMimeType

import java.net.FileNameMap; //導入依賴的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);
}
 
開發者ID:imfms,項目名稱:retrofit-rxjava-request-with-progress,代碼行數:10,代碼來源:FileConverterFactory.java

示例13: guessMimeType

import java.net.FileNameMap; //導入依賴的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);
}
 
開發者ID:wzx54321,項目名稱:XinFramework,代碼行數:13,代碼來源:HttpUtils.java

示例14: getRequestBody

import java.net.FileNameMap; //導入依賴的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);
}
 
開發者ID:ymqq,項目名稱:CommonFramework,代碼行數:15,代碼來源:PostFileMapUtils.java

示例15: initializeHeaders

import java.net.FileNameMap; //導入依賴的package包/類
private void initializeHeaders() {
    try {
        connect();
        exists = file.exists();
    } catch (IOException e) {
    }
    if (!initializedHeaders || !exists) {
        length = file.length();
        lastModified = file.lastModified();

        if (!isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();
            contentType = map.getContentTypeFor(filename);
            if (contentType != null) {
                properties.add(CONTENT_TYPE, contentType);
            }
            properties.add(CONTENT_LENGTH, String.valueOf(length));

            /*
             * Format the last-modified field into the preferred
             * Internet standard - ie: fixed-length subset of that
             * defined by RFC 1123
             */
            if (lastModified != 0) {
                Date date = new Date(lastModified);
                SimpleDateFormat fo =
                    new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
                fo.setTimeZone(TimeZone.getTimeZone("GMT"));
                properties.add(LAST_MODIFIED, fo.format(date));
            }
        } else {
            properties.add(CONTENT_TYPE, TEXT_PLAIN);
        }
        initializedHeaders = true;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:37,代碼來源:FileURLConnection.java


注:本文中的java.net.FileNameMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。