/** * 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, ""); } }
/** * 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, ""); } }
/** * 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(); } }