Tabnine Logo
net.sf.jmimemagic
Code IndexAdd Tabnine to your IDE (free)

How to use net.sf.jmimemagic

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

origin: vakinge/jeesuite-libs

  private static String perseMimeType(byte[] bytes){
    try {
      MagicMatch match = Magic.getMagicMatch(bytes);
      String mimeType = match.getMimeType();
      return mimeType;
    } catch (Exception e) {
      return null;
    }
  }
}
origin: stackoverflow.com

 byte[] data = FileUtils.toByteArray("file.msg");
MagicMatch match = Magic.getMagicMatch(data);
String mimeType = match.getMimeType();
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: 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: 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: es.gob.afirma.lib/afirma-lib-jmimemagic

@Override
protected Object clone()
  throws CloneNotSupportedException
{
  final MagicMatcher clone = new MagicMatcher();
  clone.setMatch((MagicMatch) this.match.clone());
  final Iterator<MagicMatcher> i = this.subMatchers.iterator();
  final ArrayList<MagicMatcher> sub = new ArrayList<>();
  while (i.hasNext()) {
    final MagicMatcher m = i.next();
    sub.add((MagicMatcher) m.clone());
  }
  clone.setSubMatchers(sub);
  return clone;
}
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: PhoenicisOrg/phoenicis

  private String guessMimeTypeFromDescription(MagicMatch match) {
    if ("MS-DOS executable (EXE)".equals(match.getDescription())) {
      return "application/x-dosexec";
    }

    return "???";
  }
}
origin: es.gob.afirma.lib/afirma-lib-jmimemagic

/** Carga una clase excluyendo de la ruta de b&uacute;squeda de clases las URL que no correspondan con JAR.
 * @param className Nombre de la clase a cargar.
 * @return Clase cargada.
 * @throws ClassNotFoundException cuando no se encuentra la clase a cargar. */
static Class<?> classForName(final String className) throws ClassNotFoundException {
  return getCleanClassLoader().loadClass(className);
}
origin: com.qwazr/qwazr-extractor

private String getMimeMagic(Path filePath) {
  try {
    final MagicMatch match = Magic.getMagicMatch(filePath.toFile(), true, true);
    if (match == null)
      return null;
    return match.getMimeType();
  } catch (MagicParseException | MagicMatchNotFoundException | MagicException e) {
    return null;
  }
}
origin: stackoverflow.com

 MagicMatch match = parser.getMagicMatch(f);
System.out.println(match.getMimeType()) ;
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: 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: jmimemagic/jmimemagic

/**
 * 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);
}
origin: stackoverflow.com

 MagicMatch match = Magic.getMagicMatch(your_byte_array);
String mimeType = match.getMimeType();

if(mimeType.equals("image/x-emf")) {
  //here is emf
}
if(mimeType.equals("image/x-wmf")) {
  //here is wmf
}
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: stackoverflow.com

MagicMatch match = Magic.getMagicMatch(file.getBytes());
   System.out.println(match.getMimeType());
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: stackoverflow.com

 byte[] data = someData
MagicMatch match = Magic.getMagicMatch(data);
System.out.println( match.getMimeType());
origin: arimus/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);
}
net.sf.jmimemagic

Most used classes

  • MagicMatch
    This class represents a single match test
  • Magic
    This class is the primary class for jMimeMagic
  • MagicMatchNotFoundException
    Basic JMimeMagic parse exception. This is simply a holder to identify a parsing problem. It should b
  • MagicException
    Basic JMimeMagic parse exception. This is simply a holder to identify a parsing problem. It should b
  • MagicParseException
    Basic JMimeMagic parse exception. This is simply a holder to identify a parsing problem. It should b
  • MagicParser,
  • UnsupportedTypeException,
  • MagicDetector,
  • TextFileDetector
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