org.mmbase.util
Class MagicFile
java.lang.Object
|
+--org.mmbase.util.MagicFile
- public class MagicFile
- extends java.lang.Object
Parse the UNIX magic file and determine types of files.
Implementation made on the basis of actual magic file and its manual.
TODO:
- link the info with mimetypes
- add test modifiers
- add commandline switches for warning, error and debugging messages
Ignored features of magic:
- date types
- indirect offsets (prefix of '&' in sublevel match or (address+bytes) where offset = value of address plus bytes
- AND'ing of type
BUGS:
- test string isn't read when end of line is reached in absence of a message string
Tested:
- .doc
- .rtf
- .pdf
- .sh
- .gz
- .bz2
- .html
- .rpm
- .wav
Not supported by magic file:
- StarOffice
- Author:
- cjr@dds.nl
|
Constructor Summary |
MagicFile()
Constructor: reads detection data from magic file |
|
Method Summary |
java.util.Enumeration |
elements()
|
boolean |
fromXML(java.lang.String path)
|
static void |
main(java.lang.String[] argv)
|
java.lang.String |
test(byte[] lithmus)
|
java.lang.String |
test(java.lang.String path)
|
boolean |
toXML(java.io.File f)
Write the current datastructure to an XML file
XXX Ugly and hardcoded paths |
boolean |
toXML(java.lang.String path)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
magicfile
protected static java.lang.String magicfile
MAGICXMLFILE
protected static java.lang.String MAGICXMLFILE
BUFSIZE
protected static int BUFSIZE
lithmus
protected byte[] lithmus
magicxml
protected java.lang.String magicxml
detectors
protected java.util.Vector detectors
MagicFile
public MagicFile()
- Constructor: reads detection data from magic file
test
public java.lang.String test(java.lang.String path)
- Parameters:
path - Location of file to be checked- Returns:
- Type of the file as determined by the magic file
test
public java.lang.String test(byte[] lithmus)
elements
public java.util.Enumeration elements()
- Returns:
- Enumeration of detectors
toXML
public boolean toXML(java.lang.String path)
throws java.io.IOException
toXML
public boolean toXML(java.io.File f)
throws java.io.IOException
- Write the current datastructure to an XML file
XXX Ugly and hardcoded paths
fromXML
public boolean fromXML(java.lang.String path)
main
public static void main(java.lang.String[] argv)
MMBase 2002