private String guessMimeTypeFromDescription(MagicMatch match) { if ("MS-DOS executable (EXE)".equals(match.getDescription())) { return "application/x-dosexec"; } return "???"; } }
/** * add a submatch to this magic match * * @param m a magic match */ public void addSubMatch(MagicMatch m) { log.debug("adding submatch '" + m.getDescription() + "' to '" + getDescription() + "'"); subMatches.add(m); }
/** * add a submatch to this magic match * * @param m a magic match */ public void addSubMatch(MagicMatch m) { log.debug("adding submatch '" + m.getDescription() + "' to '" + getDescription() + "'"); subMatches.add(m); }
/** * set all submatches * * @param a a collection of submatches */ public void setSubMatches(Collection<MagicMatch> a) { log.debug("setting submatches for '" + getDescription() + "'"); subMatches.clear(); subMatches.addAll(a); }
/** * set all submatches * * @param a a collection of submatches */ public void setSubMatches(Collection a) { log.debug("setting submatches for '" + getDescription() + "'"); subMatches.clear(); subMatches.addAll(a); }
/** * set all submatches * * @param a a collection of submatches */ public void setSubMatchers(Collection a) { log.debug("setSubMatchers(): for match '" + match.getDescription() + "'"); subMatchers.clear(); subMatchers.addAll(a); }
/** * set all submatches * * @param a a collection of submatches */ public void setSubMatchers(Collection<MagicMatcher> a) { log.debug("setSubMatchers(): for match '" + match.getDescription() + "'"); subMatchers.clear(); subMatchers.addAll(a); }
public String getDescription(File inputFile) { try { return getMatch(inputFile).getDescription(); } catch (MagicMatchNotFoundException e) { throw new IllegalStateException("Unable to detect mimetype of the file", e); } }
/** * 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 + " "); } }
/** Test to see if everything is in order for this match. * @return whether or not this match has enough data to be valid. */ public boolean isValid() { if (this.match == null || this.match.getTest() == null) { return false; } final String type = new String(this.match.getTest().array()).trim(); final char comparator = this.match.getComparator(); final String description = this.match.getDescription(); final String test = new String(this.match.getTest().array()).trim(); if (!type.equals("") && comparator != '\0' && //$NON-NLS-1$ (comparator == '=' || comparator == '!' || comparator == '>' || comparator == '<') && description != null && !description.equals("") && //$NON-NLS-1$ !test.equals("")) { //$NON-NLS-1$ return true; } return false; }
/** * 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 + " "); } }
/** * test to see if everything is in order for this match * * @return whether or not this match has enough data to be valid */ public boolean isValid() { log.debug("isValid()"); if ((match == null) || (match.getTest() == null)) { return false; } String type = new String(match.getTest().array()); char comparator = match.getComparator(); String description = match.getDescription(); String test = new String(match.getTest().array()); if ((type != null) && !type.equals("") && (comparator != '\0') && ((comparator == '=') || (comparator == '!') || (comparator == '>') || (comparator == '<')) && (description != null) && !description.equals("") && (test != null) && !test.equals("")) { return true; } return false; }
/** * test to see if everything is in order for this match * * @return whether or not this match has enough data to be valid */ public boolean isValid() { log.debug("isValid()"); if ((match == null) || (match.getTest() == null)) { return false; } String type = new String(match.getTest().array()); char comparator = match.getComparator(); String description = match.getDescription(); String test = new String(match.getTest().array()); if ((type != null) && !type.equals("") && (comparator != '\0') && ((comparator == '=') || (comparator == '!') || (comparator == '>') || (comparator == '<')) && (description != null) && !description.equals("") && (test != null) && !test.equals("")) { return true; } return false; }
/** * 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 + " "); } }
/** * 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 + " "); } }
String description = match.getDescription(); String type = match.getType(); String test = new String(match.getTest().array()); submatch.getDescription() + "'"); match.addSubMatch(submatch); } else {
String test = new String(match.getTest().array()); String mimeType = match.getMimeType(); String description = match.getDescription();
String test = new String(match.getTest().array()); String mimeType = match.getMimeType(); String description = match.getDescription();
this.match.getDescription(); final String type = this.match.getType(); this.match.getMimeType();