You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Schalk Cronjé <ys...@gmail.com> on 2016/05/19 11:59:01 UTC

NIO2 FIleContentType Provider in Java, Groovy & Kotlin

As I like to say, java.nio.file is like a big wooden crate with some 
diagrams, but it does not actually contain any useful content.

I had to solve a problem yesterday and wrote this 
https://github.com/ysb33r/nio2-filedetector-tika. It will detect the 
content type of a file, bu actually inspecting the first couple of bytes 
of a file rather than guessing it from the file extension. It uses 
Apache Tika underneath to do the real work. This allows the 
java.nio.file.FIles.probeFIieContent(Path) method to actually do 
something useful and not just return null. \o/

I am posting this here as the repo contains three functionally 
equivalant implementations - Java, Groovy & Kotlin. (The published 
artifact on BIntray is the Java one, simply because I did not want to 
add an additional dependency for such a small implementation). At some 
stage I'll get around to comparing the performance of the three 
implementations

This will form part of something else I want to do is showing how to 
write NIO2 providers in alternative JVM languages.

In the mean-time this might be of interest to those who would like to 
compare implementations.

-- 
Schalk W. Cronj�
Twitter / Ello / Toeter : @ysb33r