@Test public void test() { assertEquals("text/plain", MimeTypes.INSTANCE.guessMimeType("hello.txt")); assertEquals("application/msword", MimeTypes.INSTANCE.guessMimeType("hello.doc")); assertEquals("text/html", MimeTypes.INSTANCE.guessMimeType("hello.htm")); assertEquals("text/html", MimeTypes.INSTANCE.guessMimeType("hello.html")); assertEquals("text/plain", MimeTypes.INSTANCE.guessMimeType("/somepath/hello.txt")); assertEquals(null, MimeTypes.INSTANCE.guessMimeType("hello")); assertEquals(null, MimeTypes.INSTANCE.guessMimeType("/")); assertEquals(null, MimeTypes.INSTANCE.guessMimeType("somepath/")); }
public String guessMimeType(String path) { int lastDot = path.lastIndexOf('.'); if (lastDot == -1) { return null; } String extension = path.substring(lastDot + 1); extension = extension.toLowerCase(); String mimeType = extensionToMimeType.get(extension); return mimeType; }
MimeTypes { public String guessMimeType(String path) { int lastDot = path.lastIndexOf('.'); if (lastDot == -1) { return null; } String extension = path.substring(lastDot + 1); extension = extension.toLowerCase(); String mimeType = extensionToMimeType.get(extension); return mimeType; } }
MimeTypes { public String guessMimeType(String path) { int lastDot = path.lastIndexOf('.'); if (lastDot == -1) { return null; } String extension = path.substring(lastDot + 1); extension = extension.toLowerCase(); String mimeType = extensionToMimeType.get(extension); return mimeType; } private  MimeTypes(CharSource source); }
MimeTypes { public String guessMimeType(String path) { int lastDot = path.lastIndexOf('.'); if (lastDot == -1) { return null; } String extension = path.substring(lastDot + 1); extension = extension.toLowerCase(); String mimeType = extensionToMimeType.get(extension); return mimeType; } private  MimeTypes(CharSource source); String guessMimeType(String path); }
MimeTypes { public String guessMimeType(String path) { int lastDot = path.lastIndexOf('.'); if (lastDot == -1) { return null; } String extension = path.substring(lastDot + 1); extension = extension.toLowerCase(); String mimeType = extensionToMimeType.get(extension); return mimeType; } private  MimeTypes(CharSource source); String guessMimeType(String path); static final MimeTypes INSTANCE; }