title: MIME-type checking with JMimeMagic - MagicMatchNotFoundException
body: <p>I need check <code>currentFile</code> of MIME-type. If result is success and file have MIME-type <code>return true</code>. If wasn't checking succed <code>return false</code>.<br>
  With this goal I use <a href="http://sourceforge.net/projects/jmimemagic/" rel="nofollow">JMimeMagic</a>.<br>
  I try do this <a href="http://www.rgagnon.com/javadetails/java-0487.html" rel="nofollow">according this post</a></p>
  
  <p>Output from this code is - <code>net.sf.jmimemagic.MagicMatchNotFoundException</code>  </p>
  
  <p>You need have <strong>JDK 7</strong> - for changing File to byte[] at this way(<code>Files.readAllBytes(path)</code>). </p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>    class ProbeContentTypeCheker implements Checker {
  
      @Override
      public boolean check(File currentFile) {
          String mimeType = null;
          try {
              Path path = Paths.get(currentFile.getAbsolutePath());
              byte[] data = Files.readAllBytes(path);
              MagicMatch match = Magic.getMagicMatch(data);
              mimeType = match.getMimeType();
          } catch (MagicParseException | MagicMatchNotFoundException
                  | MagicException | IOException e) {
              e.printStackTrace();
          }
  
          if (null != mimeType) {
              return true;
          }
  
          return false;
      }
  }
  </code></pre>
  
  <p><strong>Output (only if it's "wrong" type):</strong>  </p>
  
  <pre><code> net.sf.jmimemagic.MagicMatchNotFoundException
      at net.sf.jmimemagic.Magic.getMagicMatch(Magic.java:222)
      at net.sf.jmimemagic.Magic.getMagicMatch(Magic.java:170)
      at task.ProbeContentTypeCheker.check(FileScan.java:357)
      at task.FolderScan.findFiles(FileScan.java:223)
      at task.FolderScan.findFiles(FileScan.java:215)
      at task.FolderScan.run(FileScan.java:202)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)  
  </code></pre>
  
  <p>If file is "ok" type => output to console normal. But after some time arise another <strong>exception</strong>:  </p>
  
  <pre><code>Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space
      at java.lang.String.toCharArray(String.java:2753)
      at org.apache.oro.text.perl.Perl5Util.match(Unknown Source)
      at net.sf.jmimemagic.MagicMatcher.testRegex(MagicMatcher.java:663)
      at net.sf.jmimemagic.MagicMatcher.testInternal(MagicMatcher.java:433)
      at net.sf.jmimemagic.MagicMatcher.test(MagicMatcher.java:341)
      at net.sf.jmimemagic.Magic.getMagicMatch(Magic.java:208)
      at net.sf.jmimemagic.Magic.getMagicMatch(Magic.java:170)
      at task.ProbeContentTypeCheking.check(FileScan.java:384)
      at task.FolderScan.findFiles(FileScan.java:228)
      at task.FolderScan.findFiles(FileScan.java:225)
      at task.FolderScan.findFiles(FileScan.java:225)
      at task.FolderScan.run(FileScan.java:209)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p><strong>Question:</strong>  </p>
  
  <ul>
  <li>How do solve this arises of exception?</li>
  </ul>