mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
test the new mime type detection
This commit is contained in:
parent
ee56cfe2b4
commit
3637b832e5
@ -27,7 +27,8 @@ public class MimeTypeUtil {
|
||||
* @throws IOException e
|
||||
*/
|
||||
public static String guessMimeType(Path file, String name) throws IOException {
|
||||
String mimeType = URLConnection.getFileNameMap().getContentTypeFor(name);
|
||||
String mimeType = name == null ?
|
||||
null : URLConnection.getFileNameMap().getContentTypeFor(name);
|
||||
if (mimeType == null) {
|
||||
try (InputStream is = Files.newInputStream(file)) {
|
||||
final byte[] headerBytes = new byte[64];
|
||||
|
@ -27,5 +27,8 @@ public class TestMimeTypeUtil {
|
||||
// Detect PPTX files
|
||||
path = Paths.get(ClassLoader.getSystemResource("file/apache.pptx").toURI());
|
||||
Assert.assertEquals(MimeType.OFFICE_PRESENTATION, MimeTypeUtil.guessMimeType(path, "apache.pptx"));
|
||||
|
||||
// Detect TXT files
|
||||
Assert.assertEquals(MimeType.TEXT_PLAIN, MimeTypeUtil.guessMimeType(path, "file.txt"));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user