Package java.net

Examples of java.net.FileNameMap


     * @param f File to send
     */
    public SendStreamResponse(File f) {
        try {
            init(new FileInputStream(f), "inline; filename=" + URLEncoder.encode(f.getName()) + ";");
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
            contentType = fileNameMap.getContentTypeFor(f.getName());
        } catch (FileNotFoundException e) {
            log.error("Error:", e);
            errorCode = HttpServletResponse.SC_NOT_FOUND;
        }
    }
View Full Code Here


        String contentType = null;

        String name = fileContent.getFile().getName().getBaseName();
        if (name != null)
        {
            FileNameMap fileNameMap = URLConnection.getFileNameMap();
            contentType = fileNameMap.getContentTypeFor(name);
        }

        return new DefaultFileContentInfo(contentType, null);
    }
View Full Code Here

import gnu.testlet.Testlet;

public class getFileNameMap implements Testlet {

  public void test(TestHarness harness) {
    FileNameMap fnm = URLConnection.getFileNameMap();
    harness.check(fnm != null);
   
    // A simple one everyone is likely to have.
    harness.check(fnm.getContentTypeFor("foo.ps"),
            "application/postscript");
  }
View Full Code Here

        response.addHeader("Cache-Control", "post-check=0, pre-check=0, false");
        response.setHeader("Pragma", "no-cache"); // HTTP/1.0
    }

    public static String getContentTypeByFileName(String fileName) {
        FileNameMap mime = URLConnection.getFileNameMap();
        return mime.getContentTypeFor(fileName);
    }
View Full Code Here

        response.addHeader("Cache-Control", "post-check=0, pre-check=0, false");
        response.setHeader("Pragma", "no-cache"); // HTTP/1.0
    }

    public static String getContentTypeByFileName(String fileName) {
        FileNameMap mime = URLConnection.getFileNameMap();
        return mime.getContentTypeFor(fileName);
    }
View Full Code Here

        response.addHeader("Cache-Control", "post-check=0, pre-check=0, false");
        response.setHeader("Pragma", "no-cache"); // HTTP/1.0
    }

    public static String getContentTypeByFileName(String fileName) {
        FileNameMap mime = URLConnection.getFileNameMap();
        return mime.getContentTypeFor(fileName);
    }
View Full Code Here

      ResponseBuilder result = Response.ok(fs);
      if (download) {
        result.header("Content-Disposition",
            "inline; filename=\"" + status.getPath().getName() + "\"").type(MediaType.APPLICATION_OCTET_STREAM);
      } else {
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String mimeType = fileNameMap.getContentTypeFor(status.getPath().getName());
        result.header("Content-Disposition",
            "filename=\"" + status.getPath().getName() + "\"").type(mimeType);
      }
      return result.build();
    } catch (FileNotFoundException ex) {
View Full Code Here

        response.addHeader("Cache-Control", "post-check=0, pre-check=0, false");
        response.setHeader("Pragma", "no-cache"); // HTTP/1.0
    }

    public static String getContentTypeByFileName(String fileName) {
        FileNameMap mime = URLConnection.getFileNameMap();
        return mime.getContentTypeFor(fileName);
    }
View Full Code Here

   * @tests java.net.URLConnection#getFileNameMap()
   */
  public void test_getFileNameMap() {
        // Tests for the standard MIME types -- users may override these
        // in their JRE
        FileNameMap map = URLConnection.getFileNameMap();
       
        // These types are defaulted
        assertEquals("text/html", map.getContentTypeFor(".htm"));
        assertEquals("text/html", map.getContentTypeFor(".html"));
        assertEquals("text/plain", map.getContentTypeFor(".text"));
        assertEquals("text/plain", map.getContentTypeFor(".txt"));
       
        // These types come from the properties file
        assertEquals("application/pdf", map.getContentTypeFor(".pdf"));
        assertEquals("application/zip", map.getContentTypeFor(".zip"));
       
    URLConnection.setFileNameMap(new FileNameMap() {
      public String getContentTypeFor(String fileName) {
        return "Spam!";
      }
    });
    try {
      assertEquals("Incorrect FileNameMap returned", "Spam!",
                    URLConnection.getFileNameMap().getContentTypeFor(null));
    } finally {
      // unset the map so other tests don't fail
      URLConnection.setFileNameMap(null);
    }
        // RI fails since it does not support fileName that does not begin with
        // '.'
        assertEquals("image/gif", map.getContentTypeFor("gif"));
  }
View Full Code Here

    return base64.decode(content);
  }
 
  public static String getMimeType(String fileName) throws java.io.IOException
  {
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    return fileNameMap.getContentTypeFor(fileName);
  }
View Full Code Here

TOP

Related Classes of java.net.FileNameMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.