title: Get extension and mime type from bytes[] in java
body: <p>I have a servlet that queries the bytes of a file, reads and responds to the content.</p>
  <pre><code>OutputStream out = response.getOutputStream();
  FileInputStream in = new FileInputStream(my_file);
  byte[] buffer = new byte[4096];
  int length;
  while ((length = in.read(buffer)) &gt; 0){
      out.write(buffer, 0, length);
  }
  in.close();
  out.flush();
  </code></pre>
  <p>I need to know what the extension of the read file is, so I can name the file with the extension correctly.</p>
  <p>Searching I found the following:</p>
  <pre><code>URLConnection.guessContentTypeFromStream(new ByteArrayInputStream(bytes));
  </code></pre>
  <p>This doesn't support all file types, like pdf for example. I need a more assertive solution</p>