Tabnine Logo
Magic
Code IndexAdd Tabnine to your IDE (free)

How to use
Magic
in
net.sf.jmimemagic

Best Java code snippets using net.sf.jmimemagic.Magic (Showing top 20 results out of 315)

origin: es.gob.afirma.lib/afirma-lib-jmimemagic

/** Get a match from a stream of data. */
public static MagicMatch getMagicMatch(final byte[] data) throws MagicParseException, MagicMatchNotFoundException, MagicException {
  return getMagicMatch(data, false);
}
origin: arimus/jmimemagic

/**
 * print the contents of a magic file
 *
 * @param stream DOCUMENT ME!
 *
 * @throws MagicParseException DOCUMENT ME!
 */
public static void printMagicFile(PrintStream stream)
  throws MagicParseException
{
  if (!initialized) {
    initialize();
  }
  Collection<MagicMatcher> matchers = Magic.getMatchers();
  log.debug("have " + matchers.size() + " matches");
  MagicMatcher matcher = null;
  Iterator<MagicMatcher> i = matchers.iterator();
  while (i.hasNext()) {
    matcher = (MagicMatcher) i.next();
    log.debug("printing");
    printMagicMatcher(stream, matcher, "");
  }
}
origin: arimus/jmimemagic

  /**
   * DOCUMENT ME!
   *
   * @param args DOCUMENT ME!
   */
  public static void main(String[] args)
  {
    try {
      if (args.length == 0) {
        System.err.println("usage: test <file>");
        System.exit(1);;
      }
      File f = new File(args[0]);

      if (f.exists()) {
        MagicMatch match = Magic.getMagicMatch(f, true, false);

        System.out.println("filename: " + args[0]);
        printMagicMatch(System.out, match, "");
      } else {
        System.err.println("file '" + f.getCanonicalPath() + "' not found");
      }
    } catch (MagicMatchNotFoundException e) {
      System.out.println("no match found");
    } catch (Exception e) {
      System.err.println("error: " + e);
      e.printStackTrace(System.err);
    }
  }
}
origin: jmimemagic/jmimemagic

/**
 * return the parsed MagicMatch objects that were created from the magic.xml
 * definitions
 *
 * @return the parsed MagicMatch objects
 *
 * @throws MagicParseException DOCUMENT ME!
 */
public static Collection getMatchers()
  throws MagicParseException
{
  log.debug("getMatchers()");
  if (!initialized) {
    initialize();
  }
  Iterator i = magicParser.getMatchers().iterator();
  ArrayList m = new ArrayList();
  while (i.hasNext()) {
    MagicMatcher matcher = (MagicMatcher) i.next();
    try {
      m.add(matcher.clone());
    } catch (CloneNotSupportedException e) {
      log.error("failed to clone matchers");
      throw new MagicParseException("failed to clone matchers");
    }
  }
  return m;
}
origin: arimus/jmimemagic

  addHint(ext, matcher);
} else if (matcher.getMatch().getType().equals("detector")) {
  String[] exts = matcher.getDetectorExtensions();
    addHint(exts[j], matcher);
origin: jmimemagic/jmimemagic

/**
 * print a magic match
 *
 * @param stream DOCUMENT ME!
 * @param matcher DOCUMENT ME!
 * @param spacing DOCUMENT ME!
 */
private static void printMagicMatcher(PrintStream stream, MagicMatcher matcher, String spacing)
{
  stream.println(spacing + "name: " + matcher.getMatch().getDescription());
  stream.println(spacing + "children: ");
  Collection matchers = matcher.getSubMatchers();
  Iterator i = matchers.iterator();
  while (i.hasNext()) {
    printMagicMatcher(stream, (MagicMatcher) i.next(), spacing + "  ");
  }
}
origin: jmimemagic/jmimemagic

/**
 * print a magic match
 *
 * @param stream DOCUMENT ME!
 * @param match DOCUMENT ME!
 * @param spacing DOCUMENT ME!
 */
public static void printMagicMatch(PrintStream stream, MagicMatch match, String spacing)
{
  stream.println(spacing + "=============================");
  stream.println(spacing + "mime type: " + match.getMimeType());
  stream.println(spacing + "description: " + match.getDescription());
  stream.println(spacing + "extension: " + match.getExtension());
  stream.println(spacing + "test: " + new String(match.getTest().array()));
  stream.println(spacing + "bitmask: " + match.getBitmask());
  stream.println(spacing + "offset: " + match.getOffset());
  stream.println(spacing + "length: " + match.getLength());
  stream.println(spacing + "type: " + match.getType());
  stream.println(spacing + "comparator: " + match.getComparator());
  stream.println(spacing + "=============================");
  Collection submatches = match.getSubMatches();
  Iterator i = submatches.iterator();
  while (i.hasNext()) {
    printMagicMatch(stream, (MagicMatch) i.next(), spacing + "    ");
  }
}
origin: arimus/jmimemagic

/**
 * return the parsed MagicMatch objects that were created from the magic.xml
 * definitions
 *
 * @return the parsed MagicMatch objects
 *
 * @throws MagicParseException DOCUMENT ME!
 */
public static Collection<MagicMatcher> getMatchers()
  throws MagicParseException
{
  log.debug("getMatchers()");
  if (!initialized) {
    initialize();
  }
  Iterator<MagicMatcher> i = magicParser.getMatchers().iterator();
  List<MagicMatcher> m = new ArrayList<MagicMatcher>();
  while (i.hasNext()) {
    MagicMatcher matcher = (MagicMatcher) i.next();
    try {
      m.add(matcher.clone());
    } catch (CloneNotSupportedException e) {
      log.error("failed to clone matchers");
      throw new MagicParseException("failed to clone matchers");
    }
  }
  return m;
}
origin: es.gob.afirma.lib/afirma-lib-jmimemagic

/** Create a parser and initialize it. */
public static synchronized void initialize() throws MagicParseException {
  if (!initialized) {
    magicParser = new MagicParser();
    magicParser.initialize();
    // build hint map
    final Iterator<MagicMatcher> i = magicParser.getMatchers().iterator();
    while (i.hasNext()) {
      final MagicMatcher matcher = i.next();
      final String ext = matcher.getMatch().getExtension();
      if (ext != null && !ext.trim().equals("")) { //$NON-NLS-1$
        addHint(ext, matcher);
      }
      else if (matcher.getMatch().getType().equals("detector")) { //$NON-NLS-1$
        final String[] exts = matcher.getDetectorExtensions();
        for (final String ext2 : exts) {
          addHint(ext2, matcher);
        }
      }
    }
    initialized = true;
  }
}
origin: arimus/jmimemagic

/**
 * print a magic match
 *
 * @param stream DOCUMENT ME!
 * @param matcher DOCUMENT ME!
 * @param spacing DOCUMENT ME!
 */
private static void printMagicMatcher(PrintStream stream, MagicMatcher matcher, String spacing)
{
  stream.println(spacing + "name: " + matcher.getMatch().getDescription());
  stream.println(spacing + "children: ");
  Collection<MagicMatcher> matchers = matcher.getSubMatchers();
  Iterator<MagicMatcher> i = matchers.iterator();
  while (i.hasNext()) {
    printMagicMatcher(stream, (MagicMatcher) i.next(), spacing + "  ");
  }
}
origin: arimus/jmimemagic

/**
 * print a magic match
 *
 * @param stream DOCUMENT ME!
 * @param match DOCUMENT ME!
 * @param spacing DOCUMENT ME!
 */
public static void printMagicMatch(PrintStream stream, MagicMatch match, String spacing)
{
  stream.println(spacing + "=============================");
  stream.println(spacing + "mime type: " + match.getMimeType());
  stream.println(spacing + "description: " + match.getDescription());
  stream.println(spacing + "extension: " + match.getExtension());
  stream.println(spacing + "test: " + new String(match.getTest().array()));
  stream.println(spacing + "bitmask: " + match.getBitmask());
  stream.println(spacing + "offset: " + match.getOffset());
  stream.println(spacing + "length: " + match.getLength());
  stream.println(spacing + "type: " + match.getType());
  stream.println(spacing + "comparator: " + match.getComparator());
  stream.println(spacing + "=============================");
  Collection<MagicMatch> submatches = match.getSubMatches();
  Iterator<MagicMatch> i = submatches.iterator();
  while (i.hasNext()) {
    printMagicMatch(stream, (MagicMatch) i.next(), spacing + "    ");
  }
}
origin: jmimemagic/jmimemagic

/**
 * get a match from a stream of data
 *
 * @param data DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MagicParseException DOCUMENT ME!
 * @throws MagicMatchNotFoundException DOCUMENT ME!
 * @throws MagicException DOCUMENT ME!
 */
public static MagicMatch getMagicMatch(byte[] data)
  throws MagicParseException, MagicMatchNotFoundException, MagicException
{
  return getMagicMatch(data, false);
}
origin: jmimemagic/jmimemagic

MagicMatch match = Magic.getMagicMatch(f, true, false);
printMagicMatch(System.out, match, "");
origin: jmimemagic/jmimemagic

/**
 * print the contents of a magic file
 *
 * @param stream DOCUMENT ME!
 *
 * @throws MagicParseException DOCUMENT ME!
 */
public static void printMagicFile(PrintStream stream)
  throws MagicParseException
{
  if (!initialized) {
    initialize();
  }
  Collection matchers = Magic.getMatchers();
  log.debug("have " + matchers.size() + " matches");
  MagicMatcher matcher = null;
  Iterator i = matchers.iterator();
  while (i.hasNext()) {
    matcher = (MagicMatcher) i.next();
    log.debug("printing");
    printMagicMatcher(stream, matcher, "");
  }
}
origin: es.gob.afirma.lib/afirma-lib-jmimemagic

  /** Get a match from a stream of data. */
  public static MagicMatch getMagicMatch(final byte[] data,
                      final boolean onlyMimeMatch) throws MagicParseException,
                                        MagicMatchNotFoundException,
                                        MagicException {
    if (!initialized) {
      initialize();
    }

    final Collection<MagicMatcher> matchers = magicParser.getMatchers();

    MagicMatcher matcher = null;
    MagicMatch match = null;
    final Iterator<MagicMatcher> i = matchers.iterator();

    while (i.hasNext()) {
      matcher = i.next();
      try {
        if ((match = matcher.test(data, onlyMimeMatch)) != null) {
          return match;
        }
      }
      catch (final Throwable e) {
        throw new MagicException(e);
      }
    }
    throw new MagicMatchNotFoundException();
  }
}
origin: jmimemagic/jmimemagic

  addHint(ext, matcher);
} else if (matcher.getMatch().getType().equals("detector")) {
  String[] exts = matcher.getDetectorExtensions();
    addHint(exts[j], matcher);
origin: arimus/jmimemagic

/**
 * get a match from a stream of data
 *
 * @param data DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws MagicParseException DOCUMENT ME!
 * @throws MagicMatchNotFoundException DOCUMENT ME!
 * @throws MagicException DOCUMENT ME!
 */
public static MagicMatch getMagicMatch(byte[] data)
  throws MagicParseException, MagicMatchNotFoundException, MagicException
{
  return getMagicMatch(data, false);
}
origin: jmimemagic/jmimemagic

initialize();
origin: jmimemagic/jmimemagic

/**
 * get a match from a file
 *
 * @param file the file to match content in
 * @param extensionHints whether or not to use extension to optimize order of content tests
 *
 * @return the MagicMatch object representing a match in the file
 *
 * @throws MagicParseException DOCUMENT ME!
 * @throws MagicMatchNotFoundException DOCUMENT ME!
 * @throws MagicException DOCUMENT ME!
 */
public static MagicMatch getMagicMatch(File file, boolean extensionHints)
  throws MagicParseException, MagicMatchNotFoundException, MagicException
{
  return getMagicMatch(file, extensionHints, false);
}
origin: arimus/jmimemagic

initialize();
net.sf.jmimemagicMagic

Javadoc

This class is the primary class for jMimeMagic

Most used methods

  • getMagicMatch
    get a match from a stream of data
  • addHint
    Add a hint to use the specified matcher for the given extension
  • initialize
    create a parser and initialize it
  • getMatchers
    return the parsed MagicMatch objects that were created from the magic.xml definitions
  • printMagicMatch
    print a magic match
  • printMagicMatcher
    print a magic match

Popular in Java

  • Updating database using SQL prepared statement
  • findViewById (Activity)
  • putExtra (Intent)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • GridBagLayout (java.awt)
    The GridBagLayout class is a flexible layout manager that aligns components vertically and horizonta
  • Permission (java.security)
    Legacy security code; do not use.
  • Date (java.util)
    A specific moment in time, with millisecond precision. Values typically come from System#currentTime
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • JCheckBox (javax.swing)
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now