Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does Files.probeContentType return null

Tags:

i am using java se7 on mac, the oracle preview.

My problem is that "Files.probeContentType" returns null...is it possible that its due to the early status of se7 for mac? My code:

if(directory == null) return; String content = null; try {     content = Files.probeContentType(directory.toPath()); } catch (IOException e) {     JOptionPane.showMessageDialog(main, e.toString());     return; } if(content == null) {     return; } else if(content.contains("image")) {     main.pctviewer.setImage(directory); } 

the name of the file is:

"/Users/admin/Desktop/temp/q12/formulare/Bildschirmfoto 2012-09-11 um 17.57.59.png"

and in debug mode in eclipse if i hover above File "file path = Unis-path(id:145)" is red

like image 761
Leander Avatar asked Sep 13 '12 13:09

Leander


2 Answers

I have reported the bug to oracle again, hoping they will backport the jdk8 solution (I don't have much hope but you never know).

In the meantime you can use my own backport of the FileTypeDetector available at https://github.com/jeantil/jdk7-mimeutils the maven project packages to a jar which can be added to your classpath to enable mime type detection. I also provide a mime.types file to put in your home folder for the detection to work correctly. I extracted the mime.types file from some version of apache so it's pretty complete.

like image 119
Jean Avatar answered Oct 06 '22 04:10

Jean


I found that the FileTypeDetector is buggy on OS X: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7133484

Apparently this will be fixed in Java 8.

like image 30
huwr Avatar answered Oct 06 '22 04:10

huwr