Spotter is a library which is able to detect the content type of a file. It is also able to detect the programming language of source files. Spotter uses Apache Tika for the content type recognition and uses the language.yml from the Linguist project.
Add the latest stable version of to the dependency management tool of your choice.
E.g. for maven:
<dependency>
<groupId>com.cloudogu.spotter</groupId>
<artifactId>spotter-core</artifactId>
<version>x.y.z</version>
</dependency>
Use the latest version from maven central:
For versions before 4.0.0 use the following coordinates:
<dependency>
<groupId>com.github.sdorra</groupId>
<artifactId>spotter-core</artifactId>
<version>x.y.z</version>
</dependency>
Detect the content type and the programming language of a file:
ContentType contentType = ContentTypes.detect("com/cloudogu/spotter/Language.java");
System.out.println("Content-Type: " + contentType);
Optional<Language> language = contentType.getLanguage();
if (language.isPresent()) {
System.out.println("Language : " + language.get().getName());
}
This project is licensed under the MIT License - see the LICENSE file for details