Class MagicMatcher

java.lang.Object
net.sf.jmimemagic.MagicMatcher
All Implemented Interfaces:
Serializable, Cloneable

public final class MagicMatcher extends Object implements Cloneable, Serializable
This class represents a single match test.
Version:
$Revision: 1.1 $
See Also:
  • Field Details

  • Constructor Details

    • MagicMatcher

      public MagicMatcher()
  • Method Details

    • setMatch

      public void setMatch(MagicMatch match)
    • getMatch

      public MagicMatch 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

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

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

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

      public MagicMatch test(File f, boolean onlyMimeMatch) throws 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:
      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 match
      onlyMimeMatch - 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

      private boolean testByte(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(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(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(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(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(ByteBuffer data)
      Test the data using a detector.
      Parameters:
      data - the data we are testing.
      Returns:
      if we have a match.
    • getDetectorExtensions

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

      private static short byteArrayToShort(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(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 Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • classForName

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

      private static 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.