/** * 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; }
/** * 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; }
/** 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(); } }
Iterator<MagicMatcher> i = magicParser.getMatchers().iterator();
Iterator i = magicParser.getMatchers().iterator();
/** 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; } }
Collection matchers = magicParser.getMatchers(); log.debug("getMagicMatch(byte[]): have " + matchers.size() + " matchers");
Collection<MagicMatcher> matchers = magicParser.getMatchers(); log.debug("getMagicMatch(byte[]): have " + matchers.size() + " matchers");
Collection matchers = magicParser.getMatchers(); log.debug("getMagicMatch(File): have " + matchers.size() + " matches");
Collection<MagicMatcher> matchers = magicParser.getMatchers(); log.debug("getMagicMatch(File): have " + matchers.size() + " matches");