• Stars
    star
    218
  • Rank 181,103 (Top 4 %)
  • Language
    Java
  • License
    ISC License
  • Created over 11 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple file magic number and content-type library which provides mime-type determination from files and byte arrays

Java Simple Magic

Here's a "magic" number package which allows content-type (mime-type) determination from files and byte arrays. It makes use of the magic(5) Unix content-type files to implement the same functionality as the Unix file(1) command in Java which detects the contents of a file. It uses either internal config files or can read /etc/magic, /usr/share/file/magic, or other magic(5) files and determine file content from File, InputStream, or byte[].

  • For more information, visit the home page.
  • The source code be found on the git repository. CircleCI CodeCov
  • Maven packages are published via Maven Central javadoc

Enjoy. Gray Watson

Getting Started

To get started you use the SimpleMagic package like the following:

// create a magic utility using the internal magic file
ContentInfoUtil util = new ContentInfoUtil();
// if you want to use a different config file(s), you can load them by hand:
// ContentInfoUtil util = new ContentInfoUtil("/etc/magic");
// ...
ContentInfo info = util.findMatch("/tmp/upload.tmp");
// or
ContentInfo info = util.findMatch(inputStream);
// or
ContentInfo info = util.findMatch(contentByteArray);

Once you have the ContentInfo it provides:

  • Enumerated type if the type is common
  • Approximate content-name
  • Full message produced by the magic file
  • Mime-type string if one configured by the config file
  • Associated file extensions (if any)

For example:

  • HTML, mime 'text/html', msg 'HTML document text'
  • Java, msg 'Java serialization data, version 5'
  • PDF, mime 'application/pdf', msg 'PDF document, version 1.4'
  • gzip, mime 'application/x-gzip', msg 'gzip compressed data, was "", from Unix...'
  • GIF, mime 'image/gif', msg 'GIF image data, version 89a, 16 x 16'
  • PNG, mime 'image/png', msg 'PNG image, 600 x 371, 8-bit/color RGB, non-interlaced'
  • ISO, mime 'audio/mp4', msg 'ISO Media, MPEG v4 system, iTunes AAC-LC'
  • Microsoft, mime 'application/msword', msg 'Microsoft Word Document'
  • RIFF, mime 'audio/x-wav', msg 'RIFF (little-endian) data, WAVE audio, Microsoft...'
  • JPEG, mime 'image/jpeg', msg 'JPEG image data, JFIF standard 1.01'

Maven Configuration

  • Maven packages are published via Maven Central
<dependency>
	<groupId>com.j256.simplemagic</groupId>
	<artifactId>simplemagic</artifactId>
	<version>1.17</version>
</dependency>

ChangeLog Release Notes

See the ChangeLog.txt file.

More Repositories

1

ormlite-android

ORMLite Android functionality used in conjunction with ormlite-core
Java
1,588
star
2

ormlite-core

Core ORMLite functionality that provides a lite Java ORM in conjunction with ormlite-jdbc or ormlite-android
Java
577
star
3

two-factor-auth

Two Factor Authentication Java code implementing the Time-based One-time Password Algorithm
Java
313
star
4

ormlite-jdbc

ORMLite JDBC functionality that works with JDBC drivers to attach to various database types
Java
224
star
5

ormlite-examples

Various example programs
Java
181
star
6

dmalloc

Debug Malloc memory allocation debugging C library
C
159
star
7

simplejmx

Simple JMX Java Library to help with the publishing of objects using JMX and the web
Java
92
star
8

cloudwatch-logback-appender

Appender that publishes logback log entries to AWS CloudWatch
Java
55
star
9

simplecsv

Simple Java CSV reading and writing library using Java annotations
Java
24
star
10

perl-two-factor-auth

Two Factor Authentication Perl code
Perl
13
star
11

ormlite-tests

More extensive unit tests
Java
6
star
12

simplelogging

Simple Java logging facade which can backend into a number of different logging implementations and is designed to be copied into another project.
Java
5
star
13

simplezip

Java processing of Zip files that gives full control over all Zip disk structures
Java
5
star
14

simplemetrics

Simple Java metrics for counting and publishing metrics from Java applications
Java
3
star
15

test-check-publisher-maven-plugin

Maven plugin designed to take tests results produced by continuous integration systems and publish them to github as a "check" annotation on a particular commit.
Java
2
star
16

simple-web-framework

Simple web framework for providing annotation based web request handling
Java
2
star
17

ormlite-android-tests

Android specific tests for the emulator.
Java
2
star
18

sortu

Unit sort command-line utility with the ability to count unique entries inline. Also includes some cut features to handle fields.
C
1
star
19

mailgw

Mailgw Issues and Feature Requests
1
star
20

null

Unix command line utility which combines /dev/null, tree, md5sum, and other useful features.
C
1
star