Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/j256/simplemagic
Simple file magic number and content-type library which provides mime-type determination from files and byte arrays
https://github.com/j256/simplemagic
java magic mime unix
Last synced: 7 days ago
JSON representation
Simple file magic number and content-type library which provides mime-type determination from files and byte arrays
- Host: GitHub
- URL: https://github.com/j256/simplemagic
- Owner: j256
- License: isc
- Created: 2013-05-06T13:18:01.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2023-12-05T22:09:43.000Z (about 1 year ago)
- Last Synced: 2024-12-25T08:06:05.012Z (14 days ago)
- Topics: java, magic, mime, unix
- Language: Java
- Homepage: http://256stuff.com/sources/simplemagic/
- Size: 5.09 MB
- Stars: 221
- Watchers: 14
- Forks: 45
- Open Issues: 32
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
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](http://256stuff.com/sources/simplemagic/).
* The source code be found on the [git repository](https://github.com/j256/simplemagic). [![CircleCI](https://circleci.com/gh/j256/simplemagic.svg?style=svg)](https://circleci.com/gh/j256/simplemagic) [![CodeCov](https://img.shields.io/codecov/c/github/j256/simplemagic.svg)](https://codecov.io/github/j256/simplemagic/)
* Maven packages are published via [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.j256.simplemagic/simplemagic/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/com.j256.simplemagic/simplemagic/) [![javadoc](https://javadoc.io/badge2/com.j256.simplemagic/simplemagic/javadoc.svg)](https://javadoc.io/doc/com.j256.simplemagic/simplemagic)Enjoy. Gray Watson
# Getting Started
To get started you use the SimpleMagic package like the following:
```java
// 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```](https://github.com/j256/simplemagic/blob/master/src/main/java/com/j256/simplemagic/ContentInfo.java)
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](https://maven-badges.herokuapp.com/maven-central/com.j256.simplemagic/simplemagic/badge.svg?style=flat-square)](https://maven-badges.herokuapp.com/maven-central/com.j256.simplemagic/simplemagic/)
``` xml
com.j256.simplemagic
simplemagic
1.17```
# ChangeLog Release Notes
See the [ChangeLog.txt file](src/main/javadoc/doc-files/changelog.txt).