groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schalk Cronjé <>
Subject NIO2 FIleContentType Provider in Java, Groovy & Kotlin
Date Thu, 19 May 2016 11:59:01 GMT
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 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 

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

View raw message