Class MagicMatcher

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable

    public final class MagicMatcher
    extends java.lang.Object
    implements java.lang.Cloneable, java.io.Serializable
    This class represents a single match test.
    Version:
    $Revision: 1.1 $
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MagicMatcher()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSubMatcher​(MagicMatcher m)
      add a submatch to this magic match
      private static long byteArrayToLong​(java.nio.ByteBuffer data)
      convert a byte array to a long
      private static short byteArrayToShort​(java.nio.ByteBuffer data)
      Convert a byte array to a short.
      (package private) static java.lang.Class<?> classForName​(java.lang.String className)
      Carga una clase excluyendo de la ruta de búsqueda de clases las URL que no correspondan con JAR.
      protected java.lang.Object clone()  
      private static java.lang.ClassLoader getCleanClassLoader()
      Obtiene un ClassLoader que no incluye URL que no referencien directamente a ficheros JAR.
      java.lang.String[] getDetectorExtensions()
      Get the extensions for the underlying detectory.
      MagicMatch getMatch()  
      java.util.Collection<MagicMatcher> getSubMatchers()
      get all submatches for this magic match
      boolean isValid()
      Test to see if everything is in order for this match.
      void setMatch​(MagicMatch match)  
      void setSubMatchers​(java.util.Collection<MagicMatcher> a)
      Set all submatches.
      MagicMatch test​(byte[] data, boolean onlyMimeMatch)
      Test to see if this match or any submatches match.
      MagicMatch test​(java.io.File f, boolean onlyMimeMatch)
      test to see if this match or any submatches match
      private boolean testByte​(java.nio.ByteBuffer data)
      Test the data against the test byte.
      private boolean testDetector​(java.nio.ByteBuffer data)
      Test the data using a detector.
      private boolean testInternal​(byte[] data)  
      private boolean testLong​(java.nio.ByteBuffer data)
      Test the data against a long.
      private boolean testRegex​(java.lang.String text)
      Test the data against a regex.
      private boolean testShort​(java.nio.ByteBuffer data)
      Test the data against a short.
      private boolean testString​(java.nio.ByteBuffer data)
      test the data against the byte array
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MagicMatcher

        public MagicMatcher()
    • Method Detail

      • setMatch

        public void setMatch​(MagicMatch match)
      • 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

        public void addSubMatcher​(MagicMatcher m)
        add a submatch to this magic match
        Parameters:
        m - a magic match
      • setSubMatchers

        public void setSubMatchers​(java.util.Collection<MagicMatcher> a)
        Set all submatches.
        Parameters:
        a - a collection of submatches.
      • getSubMatchers

        public java.util.Collection<MagicMatcher> getSubMatchers()
        get all submatches for this magic match
        Returns:
        a collection of submatches
      • test

        public MagicMatch test​(java.io.File f,
                               boolean onlyMimeMatch)
                        throws java.io.IOException,
                               UnsupportedTypeException
        test to see if this match or any submatches match
        Parameters:
        f - the file that should be used to test the match
        onlyMimeMatch - DOCUMENT ME!
        Returns:
        the deepest magic match object that matched
        Throws:
        java.io.IOException - DOCUMENT ME!
        UnsupportedTypeException - DOCUMENT ME!
      • test

        public MagicMatch test​(byte[] data,
                               boolean onlyMimeMatch)
                        throws java.io.IOException,
                               UnsupportedTypeException
        Test to see if this match or any submatches match.
        Parameters:
        data - the data that should be used to test the match
        onlyMimeMatch - Indica que sólo se identifique el mimetype de los datos.
        Returns:
        the deepest magic match object that matched
        Throws:
        java.io.IOException - Cuando falla la lectura de los datos.
        UnsupportedTypeException - Cuando no se identifiquen los datos.
      • testInternal

        private boolean testInternal​(byte[] data)
      • testByte

        private boolean testByte​(java.nio.ByteBuffer data)
        Test the data against the test byte.
        Parameters:
        data - the data we are testing.
        Returns:
        if we have a match.
      • testString

        private boolean testString​(java.nio.ByteBuffer data)
        test the data against the byte array
        Parameters:
        data - the data we are testing
        Returns:
        if we have a match
      • testShort

        private boolean testShort​(java.nio.ByteBuffer data)
        Test the data against a short.
        Parameters:
        data - the data we are testing.
        Returns:
        if we have a match.
      • testLong

        private boolean testLong​(java.nio.ByteBuffer data)
        Test the data against a long.
        Parameters:
        data - the data we are testing.
        Returns:
        if we have a match.
      • testRegex

        private boolean testRegex​(java.lang.String text)
        Test the data against a regex.
        Parameters:
        text - the data we are testing.
        Returns:
        if we have a match.
      • testDetector

        private boolean testDetector​(java.nio.ByteBuffer data)
        Test the data using a detector.
        Parameters:
        data - the data we are testing.
        Returns:
        if we have a match.
      • getDetectorExtensions

        public java.lang.String[] getDetectorExtensions()
        Get the extensions for the underlying detectory.
        Returns:
        Listado de extensiones.
      • byteArrayToShort

        private static short byteArrayToShort​(java.nio.ByteBuffer data)
        Convert a byte array to a short.
        Parameters:
        data - buffer of byte data.
        Returns:
        byte array converted to a short.
      • byteArrayToLong

        private static long byteArrayToLong​(java.nio.ByteBuffer data)
        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

        protected java.lang.Object clone()
                                  throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException
      • classForName

        static java.lang.Class<?> classForName​(java.lang.String className)
                                        throws java.lang.ClassNotFoundException
        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:
        java.lang.ClassNotFoundException - cuando no se encuentra la clase a cargar.
      • getCleanClassLoader

        private static java.lang.ClassLoader getCleanClassLoader()
        Obtiene un ClassLoader que no incluye URL que no referencien directamente a ficheros JAR.
        Returns:
        ClassLoader sin URL adicionales a directorios sueltos Web.