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

How to use
getMagicMatch
method
in
net.sf.jmimemagic.Magic

Best Java code snippets using net.sf.jmimemagic.Magic.getMagicMatch (Showing top 17 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: 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

/**
 * 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

/**
 * 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

/**
 * 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: PhoenicisOrg/phoenicis

private MagicMatch getMatch(File inputFile) throws MagicMatchNotFoundException {
  final Path path = Paths.get(inputFile.getAbsolutePath());
  try {
    byte[] data = Files.readAllBytes(path);
    return Magic.getMagicMatch(data, true);
  } catch (MagicException | MagicParseException | IOException e) {
    throw new IllegalStateException("Unable to detect mimetype of the file", e);
  }
}
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: 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: jvelo/mayocat-shop

private Optional<String> guessExtension(byte[] bytes)
{
  try {
    // No extension : try to guess it
    MagicMatch match = Magic.getMagicMatch(bytes);
    String guessedExtension = match.getExtension();
    if (!Strings.isNullOrEmpty(guessedExtension)) {
      return Optional.of(guessedExtension);
    } else {
      return Optional.absent();
    }
  } catch (Exception e) {
    this.logger.warn("Error while attempting to guess attachment extension", e);
    return Optional.absent();
  }
}
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

MagicMatch match = Magic.getMagicMatch(f, true, false);
origin: net.sf.taverna.t2.workbench.views/results

private String getMimeType(ExternalReferenceSPI externalReference, InvocationContext context) {
  if (!mimeTypes.containsKey(externalReference)) {
    InputStream inputStream = externalReference.openStream(context);
    try {
      byte[] bytes = new byte[64];
      inputStream.read(bytes);
      mimeTypes.put(externalReference, Magic.getMagicMatch(bytes, true).getMimeType());
    } catch (IOException e) {
      e.printStackTrace();
      logger.debug("Failed to read from stream to determine mimetype", e);
    } catch (MagicParseException e) {
      e.printStackTrace();
      logger.debug("Error calling mime magic", e);
    } catch (MagicMatchNotFoundException e) {
      e.printStackTrace();
      logger.debug("Error calling mime magic", e);
    } catch (MagicException e) {
      e.printStackTrace();
      logger.debug("Error calling mime magic", e);
    } finally {
      try {
        inputStream.close();
      } catch (IOException e) {
        e.printStackTrace();
        logger.debug("Failed to close stream after determining mimetype", e);
      }
    }
  }
  return mimeTypes.get(externalReference);
}
origin: net.sf.taverna.t2.workbench.views/results

  bytes = new byte[64];
  inputStream.read(bytes);
  magicMatch = Magic.getMagicMatch(bytes, true);
} catch (IOException e) {
  e.printStackTrace();
origin: net.sf.taverna.t2.workbench.views/results

  bytes = new byte[64];
  inputStream.read(bytes);
  mimeType = Magic.getMagicMatch(bytes, true).getMimeType();
} catch (IOException e) {
  e.printStackTrace();
origin: com.expedia.dsp/datasqueeze

  fileType = FileType.SEQ;
} else {
  final String mimeType = Magic.getMagicMatch(header, false).getMimeType();
  log.info("File mime Type {}", mimeType);
  if (FileType.TEXT.getValue().equalsIgnoreCase(mimeType)) {
origin: net.sf.taverna.t2.workbench.views/results

  magicMatch = Magic.getMagicMatch(byteArray);
  mimeType = magicMatch.getMimeType();
} catch (MagicParseException e1) {
origin: anthonydahanne/ReGalAndroid

@Test
public void getPhotoInputStream() throws IOException, G3GalleryException, MagicParseException, MagicMatchNotFoundException, MagicException {
  try {
    itemClient.getItem(createdPhotoId);
  }catch(G3ItemNotFoundException ex){
    //item does not exist yet, so we need to add it first
    addPhoto();
  }
  Item item1 = itemClient.getItem(createdPhotoId);
  String url = item1.getEntity().getFileUrl();
  InputStream inputStream = itemClient.getPhotoInputStream(url);
  //conversion stuff..
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  ByteStreams.copy(inputStream, outputStream);
  byte[] photoDownloadedAsAByteArray = outputStream.toByteArray();
  // getMagicMatch accepts  byte[],
  String contentType = Magic.getMagicMatch(photoDownloadedAsAByteArray).getMimeType();
  // it should be an image file
  assertEquals("image/png", contentType);
}
net.sf.jmimemagicMagicgetMagicMatch

Javadoc

get a match from a file

Popular methods of Magic

  • 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

  • Reading from database using SQL prepared statement
  • setScale (BigDecimal)
  • onRequestPermissionsResult (Fragment)
  • notifyDataSetChanged (ArrayAdapter)
  • Socket (java.net)
    Provides a client-side TCP socket.
  • MessageFormat (java.text)
    Produces concatenated messages in language-neutral way. New code should probably use java.util.Forma
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Iterator (java.util)
    An iterator over a sequence of objects, such as a collection.If a collection has been changed since
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Base64 (org.apache.commons.codec.binary)
    Provides Base64 encoding and decoding as defined by RFC 2045.This class implements section 6.8. Base
  • Top Vim 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