Package net.sf.jmimemagic
Class MagicMatcher
java.lang.Object
net.sf.jmimemagic.MagicMatcher
- All Implemented Interfaces:
Serializable
,Cloneable
This class represents a single match test.
- Version:
- $Revision: 1.1 $
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate MagicMatch
private static final long
private final ArrayList
<MagicMatcher> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
add a submatch to this magic matchprivate static long
byteArrayToLong
(ByteBuffer data) convert a byte array to a longprivate static short
byteArrayToShort
(ByteBuffer data) Convert a byte array to a short.(package private) static Class
<?> classForName
(String className) Carga una clase excluyendo de la ruta de búsqueda de clases las URL que no correspondan con JAR.protected Object
clone()
private static ClassLoader
Obtiene un ClassLoader que no incluye URL que no referencien directamente a ficheros JAR.String[]
Get the extensions for the underlying detectory.getMatch()
get all submatches for this magic matchboolean
isValid()
Test to see if everything is in order for this match.void
setMatch
(MagicMatch match) void
Set all submatches.test
(byte[] data, boolean onlyMimeMatch) Test to see if this match or any submatches match.test to see if this match or any submatches matchprivate boolean
testByte
(ByteBuffer data) Test the data against the test byte.private boolean
testDetector
(ByteBuffer data) Test the data using a detector.private boolean
testInternal
(byte[] data) private boolean
testLong
(ByteBuffer data) Test the data against a long.private boolean
Test the data against a regex.private boolean
testShort
(ByteBuffer data) Test the data against a short.private boolean
testString
(ByteBuffer data) test the data against the byte array
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
subMatchers
-
match
-
-
Constructor Details
-
MagicMatcher
public MagicMatcher()
-
-
Method Details
-
setMatch
-
getMatch
-
isValid
public boolean isValid()Test to see if everything is in order for this match.- Returns:
- whether or not this match has enough data to be valid.
-
addSubMatcher
add a submatch to this magic match- Parameters:
m
- a magic match
-
setSubMatchers
Set all submatches.- Parameters:
a
- a collection of submatches.
-
getSubMatchers
get all submatches for this magic match- Returns:
- a collection of submatches
-
test
test to see if this match or any submatches match- Parameters:
f
- the file that should be used to test the matchonlyMimeMatch
- DOCUMENT ME!- Returns:
- the deepest magic match object that matched
- Throws:
IOException
- DOCUMENT ME!UnsupportedTypeException
- DOCUMENT ME!
-
test
public MagicMatch test(byte[] data, boolean onlyMimeMatch) throws IOException, UnsupportedTypeException Test to see if this match or any submatches match.- Parameters:
data
- the data that should be used to test the matchonlyMimeMatch
- Indica que sólo se identifique el mimetype de los datos.- Returns:
- the deepest magic match object that matched
- Throws:
IOException
- Cuando falla la lectura de los datos.UnsupportedTypeException
- Cuando no se identifiquen los datos.
-
testInternal
private boolean testInternal(byte[] data) -
testByte
Test the data against the test byte.- Parameters:
data
- the data we are testing.- Returns:
- if we have a match.
-
testString
test the data against the byte array- Parameters:
data
- the data we are testing- Returns:
- if we have a match
-
testShort
Test the data against a short.- Parameters:
data
- the data we are testing.- Returns:
- if we have a match.
-
testLong
Test the data against a long.- Parameters:
data
- the data we are testing.- Returns:
- if we have a match.
-
testRegex
Test the data against a regex.- Parameters:
text
- the data we are testing.- Returns:
- if we have a match.
-
testDetector
Test the data using a detector.- Parameters:
data
- the data we are testing.- Returns:
- if we have a match.
-
getDetectorExtensions
Get the extensions for the underlying detectory.- Returns:
- Listado de extensiones.
-
byteArrayToShort
Convert a byte array to a short.- Parameters:
data
- buffer of byte data.- Returns:
- byte array converted to a short.
-
byteArrayToLong
convert a byte array to a long- Parameters:
data
- buffer of byte data- Returns:
- byte arrays (high and low bytes) converted to a long value
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
classForName
Carga una clase excluyendo de la ruta de búsqueda de clases las URL que no correspondan con JAR.- Parameters:
className
- Nombre de la clase a cargar.- Returns:
- Clase cargada.
- Throws:
ClassNotFoundException
- cuando no se encuentra la clase a cargar.
-
getCleanClassLoader
Obtiene un ClassLoader que no incluye URL que no referencien directamente a ficheros JAR.- Returns:
- ClassLoader sin URL adicionales a directorios sueltos Web.
-