title: File type detection in Java without I/O
body: <p>There is a built-in method in the Java JDK that detects file types:</p>
  
  <pre><code>Files.probeContentType(Paths.get("/temp/word.doc"));
  </code></pre>
  
  <p>The javadoc says that a FileTypeDetector may examine the filename, or it may examine a few bytes in the file, which means that it would have to actually try to pull the file from a URL.</p>
  
  <p>This is unacceptable in our app; the content of the file is available only through an InputStream.</p>
  
  <p>I tried to step through the code to see what the JDK is actually doing, but it seems that it goes to <code>FileTypeDetectors.defaultFileTypeDetector.probeContentType(path)</code> which goes to <code>sun.nio.fs.AbstractFileTypeDetector</code>, and I couldn't step into that code because there's no source attachment.</p>
  
  <p>How do I use JDK file type detection and force it to use file content that I supply, rather than having it go out and perform I/O on its own?</p>