Example usage for java.net URLConnection getFileNameMap

List of usage examples for java.net URLConnection getFileNameMap

Introduction

In this page you can find the example usage for java.net URLConnection getFileNameMap.

Prototype

public static FileNameMap getFileNameMap() 

Source Link

Document

Loads filename map (a mimetable) from a data file.

Usage

From source file:Main.java

public static void main(String args[]) throws Exception {

    URL u = new URL("http://www.java2s.com");
    URLConnection uc = u.openConnection();

    System.out.println(uc.getFileNameMap());
}

From source file:Main.java

public static String guessMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }//w  ww .  j  a  v  a  2s. c  o m
    return contentTypeFor;
}

From source file:Main.java

private static String guessMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }//from   www .  j a v  a2 s. c o  m
    return contentTypeFor;
}

From source file:Main.java

public static String getMimeType(String filename) {
    FileNameMap filenameMap = URLConnection.getFileNameMap();
    String contentTypeFor = filenameMap.getContentTypeFor(filename);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }//  w ww .j a v a 2 s. c om
    return contentTypeFor;
}

From source file:Main.java

private static String getMimeType(String filename) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(filename);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }/*ww w .  j  av a  2 s. c  om*/
    return contentTypeFor;
}

From source file:Main.java

public static String getFileType(String fn, String defaultType) {
    FileNameMap fNameMap = URLConnection.getFileNameMap();
    String type = fNameMap.getContentTypeFor(fn);
    return type == null ? defaultType : type;
}

From source file:Main.java

public static String getMimeTypeForFile(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    return fileNameMap.getContentTypeFor(path);
}

From source file:Main.java

public static String getMimeType(String path) {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String contentTypeFor = fileNameMap.getContentTypeFor(path);
    if (contentTypeFor == null) {
        contentTypeFor = "application/octet-stream";
    }// w w  w .ja v  a  2  s. c  o m
    return contentTypeFor;
}

From source file:org.openstatic.http.HttpResponse.java

/** Determine the content type of a local file */
public static String getContentTypeFor(String filename) {
    String lc_file = filename.toLowerCase();
    if (lc_file.endsWith(".html") || lc_file.endsWith(".htm")) {
        return "text/html";
    } else if (lc_file.endsWith(".txt")) {
        return "text/plain";
    } else if (lc_file.endsWith(".css")) {
        return "text/css";
    } else if (lc_file.endsWith(".js")) {
        return "text/javascript";
    } else if (lc_file.endsWith(".jpg") || lc_file.endsWith(".jpe") || lc_file.endsWith(".jpeg")) {
        return "image/jpeg";
    } else if (lc_file.endsWith(".gif")) {
        return "image/gif";
    } else {/*from ww w.j  a  v a 2  s. com*/
        FileNameMap fnm = URLConnection.getFileNameMap();
        return fnm.getContentTypeFor(filename);
    }
}

From source file:org.jbpm.bpel.tools.ant.DeploymentTask.java

protected void writeRequest(PostMethod post) throws IOException {
    // process part
    String contentType = URLConnection.getFileNameMap().getContentTypeFor(processArchive.getName());
    FilePart processPart = new FilePart("processArchive", processArchive, contentType,
            FileUtil.DEFAULT_CHARSET.name());

    // multipart request
    post.setRequestEntity(new MultipartRequestEntity(new Part[] { processPart }, post.getParams()));

    log("deploying process: " + processArchive.getName());
}