Java 类java.net.FileNameMap 实例源码

项目:GitHub    文件:PostFormRequest.java   
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;
}
项目:cniao5    文件:PostFormRequest.java   
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;
}
项目:Hotspot-master-devp    文件:PostFormRequest.java   
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;
}
项目:openjdk-jdk10    文件:AbstractFileTypeDetector.java   
/**
 * 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);
}
项目:okhttputils-masterlaotang    文件:PostFormRequest.java   
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;
}
项目:NApply    文件:OkHttpClientManager.java   
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;
}
项目:AyoSunny    文件:XgoHttpClient.java   
/**
 * 初始化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();
}
项目:Lizzy    文件:FileNameMapProvider.java   
@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;
}
项目:gen-misc    文件:Files.java   
/**
 * 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;
        }
    }
}
项目:Logistics-guard    文件:OkHttpClientManager.java   
private String guessMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:GitHub    文件:Utils.java   
public static String getMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:GitHub    文件:HttpUtils.java   
/** 根据文件名获取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);
}
项目:GitHub    文件:Utils.java   
public static String getMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:stynico    文件:PostFormRequest.java   
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;
}
项目:EvolvingNetLib    文件:CCFile.java   
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();
    }
}
项目:yyox    文件:BaseHttpManager.java   
private String guessMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:RxEasyHttp    文件:HttpParams.java   
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);
}
项目:retrofit-rxjava-request-with-progress    文件:FileConverterFactory.java   
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);
}
项目:XinFramework    文件:HttpUtils.java   
/**
 * 根据文件名获取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);
}
项目:SmartChart    文件:PostFormRequest.java   
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;
}
项目:CommonFramework    文件:PostFileMapUtils.java   
/**
 * 获取文件上传使用的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);
}
项目:OpenJSharp    文件:FileURLConnection.java   
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;
    }
}
项目:OpenJSharp    文件:FileURLConnection.java   
public synchronized InputStream getInputStream()
    throws IOException {

    int iconHeight;
    int iconWidth;

    connect();

    if (is == null) {
        if (isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();

            StringBuffer buf = new StringBuffer();

            if (files == null) {
                throw new FileNotFoundException(filename);
            }

            Collections.sort(files, Collator.getInstance());

            for (int i = 0 ; i < files.size() ; i++) {
                String fileName = files.get(i);
                buf.append(fileName);
                buf.append("\n");
            }
            // Put it into a (default) locale-specific byte-stream.
            is = new ByteArrayInputStream(buf.toString().getBytes());
        } else {
            throw new FileNotFoundException(filename);
        }
    }
    return is;
}
项目:OpenJSharp    文件:FileURLConnection.java   
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;
    }
}
项目:OpenJSharp    文件:FileURLConnection.java   
public synchronized InputStream getInputStream()
    throws IOException {

    int iconHeight;
    int iconWidth;

    connect();

    if (is == null) {
        if (isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();

            StringBuffer buf = new StringBuffer();

            if (files == null) {
                throw new FileNotFoundException(filename);
            }

            sort(files);

            for (int i = 0 ; i < files.size() ; i++) {
                String fileName = files.get(i);
                buf.append(fileName);
                buf.append("\n");
            }
            // Put it into a (default) locale-specific byte-stream.
            is = new ByteArrayInputStream(buf.toString().getBytes());
        } else {
            throw new FileNotFoundException(filename);
        }
    }
    return is;
}
项目:TPlayer    文件:MimeTypeHelper.java   
/**
 * 根据文件名猜测文件的mime类型
 *
 * @param filename
 * @return
 */
public static String guessMimeType(String filename) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = null;
    try {
        contentTypeFor = fileNameMap.getContentTypeFor(URLEncoder.encode(filename, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:jdk8u-jdk    文件:FileURLConnection.java   
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;
    }
}
项目:jdk8u-jdk    文件:FileURLConnection.java   
public synchronized InputStream getInputStream()
    throws IOException {

    int iconHeight;
    int iconWidth;

    connect();

    if (is == null) {
        if (isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();

            StringBuffer buf = new StringBuffer();

            if (files == null) {
                throw new FileNotFoundException(filename);
            }

            Collections.sort(files, Collator.getInstance());

            for (int i = 0 ; i < files.size() ; i++) {
                String fileName = files.get(i);
                buf.append(fileName);
                buf.append("\n");
            }
            // Put it into a (default) locale-specific byte-stream.
            is = new ByteArrayInputStream(buf.toString().getBytes());
        } else {
            throw new FileNotFoundException(filename);
        }
    }
    return is;
}
项目:openjdk-jdk10    文件:FileURLConnection.java   
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;
    }
}
项目:openjdk-jdk10    文件:FileURLConnection.java   
public synchronized InputStream getInputStream()
    throws IOException {

    int iconHeight;
    int iconWidth;

    connect();

    if (is == null) {
        if (isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();

            StringBuilder sb = new StringBuilder();

            if (files == null) {
                throw new FileNotFoundException(filename);
            }

            Collections.sort(files, Collator.getInstance());

            for (int i = 0 ; i < files.size() ; i++) {
                String fileName = files.get(i);
                sb.append(fileName);
                sb.append("\n");
            }
            // Put it into a (default) locale-specific byte-stream.
            is = new ByteArrayInputStream(sb.toString().getBytes());
        } else {
            throw new FileNotFoundException(filename);
        }
    }
    return is;
}
项目:MarsBootProject    文件:RequestParams.java   
/***
 * 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;
}
项目:appslandia-sweetsop    文件:HttpClient.java   
public static FileNameMap getFileNameMap() {
    return HttpURLConnection.getFileNameMap();
}
项目:appslandia-sweetsop    文件:HttpClient.java   
public static void setFileNameMap(FileNameMap map) {
    HttpURLConnection.setFileNameMap(map);
}
项目:openjdk9    文件:FileURLConnection.java   
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;
    }
}
项目:openjdk9    文件:FileURLConnection.java   
public synchronized InputStream getInputStream()
    throws IOException {

    int iconHeight;
    int iconWidth;

    connect();

    if (is == null) {
        if (isDirectory) {
            FileNameMap map = java.net.URLConnection.getFileNameMap();

            StringBuilder sb = new StringBuilder();

            if (files == null) {
                throw new FileNotFoundException(filename);
            }

            Collections.sort(files, Collator.getInstance());

            for (int i = 0 ; i < files.size() ; i++) {
                String fileName = files.get(i);
                sb.append(fileName);
                sb.append("\n");
            }
            // Put it into a (default) locale-specific byte-stream.
            is = new ByteArrayInputStream(sb.toString().getBytes());
        } else {
            throw new FileNotFoundException(filename);
        }
    }
    return is;
}
项目:ktball    文件:OkHttpUploadRequest.java   
private String guessMimeType(String path)
{
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null)
    {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:DUtil    文件:Utils.java   
/**
 * 根据文件名解析contentType
 *
 * @param name
 * @return
 */
public static String getMimeType(String name) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = null;
    try {
        contentTypeFor = fileNameMap.getContentTypeFor(URLEncoder.encode(name, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:NewsMe    文件:PostFormRequest.java   
private String guessMimeType(String path)
{
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null)
    {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:meishiDemo    文件:OkHttpUploadRequest.java   
private String guessMimeType(String path)
{
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null)
    {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}
项目:Fast-Android-Networking    文件:Utils.java   
public static String getMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }
    return contentTypeFor;
}