Skip navigation links

Simple Magic 1.17 API

This package provides some simple magic value features that simulate the Unix file(1) command to determine the type of a file or of bytes from the content.

See: Description

Packages 
Package Description
com.j256.simplemagic
Top level code used externally.
com.j256.simplemagic.endian
Endian classes which convert binary data from different machine formats.
com.j256.simplemagic.entries
Internal storing of the entries read from the magic file(s).
com.j256.simplemagic.logger  
com.j256.simplemagic.logger.backend  
com.j256.simplemagic.types
Various types which do the pattern matching.

This package provides some simple magic value features that simulate the Unix file(1) command to determine the type of a file or of bytes from the content. The ContentInfoUtil class is the main external class that loads the rules and determines the content-types.

The change log file shows the various features and bug fixes in each version.

SimpleMagic home page.

// create a magic utility using the internal magic file
ContentInfoUtil util = new ContentInfoUtil();
// get the content info for this file-path or null if no match
ContentInfo info = util.findMatch("/tmp/upload.tmp");
// display content type information
if (info == null) {
        System.out.println("Unknown content-type");
} else {
        // other information in ContentInfo type
        System.out.println("Content-type is: " + info.getName());
}

Skip navigation links

This content is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.