fix #48 by detecting file type using jmimemagic Java library #49
Conversation
Thanks very much. Are you sure there isn't a built-in solution for reading the mime type of a file? I found some suggestions here. I only ask because this library adds 1.8MB to the final jar file size. It's fine if there is no other way; I'm just looking at the other options. |
I found that if you add |
If we can make the minimum requirement to be Java 7 for running Nightcode, we do not need any 3rd party library to detect the file type. Java 7 has the API to probe the content. This might be a breaking change for some; Nightcode should switch to version 0.2.0 to include this change. Please let me know what you think - I will update the pull request. |
A lot of Mac users are still using Java 6, because that's what it comes with. I wonder if there is a simpler solution. Maybe we should just remove the |
I tried running Nightcode on Java 6 and got the below exception:
It seems that Nightcode already requires Java 7 to run. My plan was to use the Java-7 feature dynamically if available else fallback to 10MB-limit based detection, which would be unnecessary if Java 7 is a requirement. |
JRE6 had its end in Feb2013 (http://www.oracle.com/technetwork/java/eol-135779.html), -- just my 2c |
I wasn't aware there were still problems running it with Java 6. I compiled the latest version with OpenJDK 6, so that is puzzling. Perhaps requiring Java 7 is the best option then. If you modify the PR with the change I'd be happy to accept. I'll make sure to mention the change when I release it. |
It was my fault that I built the JAR with Java 7 and ran it on Java 6 - the problem turned out to be AOT compilation that required Java 7 classes. I have updated the PR in a way that on Java 7 the detection will work using Java-7 API via reflection and on Java 6 it falls back on length check. Will appreciate if somebody can test in other ways - I might have forgotten about corner cases. |
I tried the change and it seems to have issues when I select any file with a non-whitelisted extension. I don't see any error output in the console, however. |
Maybe reflecting Java 7 functions won't work since we are targeting Java 6 in the project.clj? It may be less error prone to just check the file size. |
Did you run into the issue on Java 7? It's working on Java 7 + 64-bit Ubuntu for me. Only in Java 6 I can see somehow the non-whitelisted files are not working. |
I switched to compile with OpenJDK 7 and it seems to work now. Technically this may still cause issues for Mac users running Java 6 -- see this issue for reference. For some reason, Java 6 on OS X has problems running Swing apps compiled with JDK 7, even when they target Java 6. That said, I think it's an OK trade-off to make since Java 6 is so outdated. |
I found the issue - I was not catching |
Sure please do. Would this allow me to compile with OpenJDK 6?
|
I believe it should. I compiled using Sun JDK 6 and ran using both Sun JDK 6 and Sun JDK 7. |
This PR uses jMimeMagic to detect file type if the file extension is not one among the white-listed types. Also adds
.cljx
and.edn
to known Clojure file extensions.