title: IllegalArgumentException: Bad endianness tag while getting number of pages of a tiff file
body: <p>I'm getting a weird error while manipulating a tiff file. I already do something similar with other file formats and even other tiff files. But out of the sudden, I got the following message:</p>
  
  <pre><code>Bad endianness tag (not 0x4949 or 0x4d4d).
  java.lang.IllegalArgumentException: Bad endianness tag (not 0x4949 or 0x4d4d).
  at com.sun.media.jai.codec.TIFFDirectory.getNumDirectories(TIFFDirectory.java:588)
  at com.sun.media.jai.codecimpl.TIFFImageDecoder.getNumPages(TIFFImageDecoder.java:105)
  at br.com.org.sofia.util.PdfUtil.gerarPDFATiff(PdfUtil.java:213)
  at br.com.GerarControler.gerarPDFA(GerarControler.java:182)
  at br.com.controller.IndexadorControle.indexarUpload(IndexadorControle.java:331)
  at br.com.controller.IndexadorControle.indexarUpload(IndexadorControle.java:289)
  at sofia.control.BuscaUploadController$7.call(BuscaUploadController.java:720)
  at sofia.control.BuscaUploadController$7.call(BuscaUploadController.java:703)
  at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
  at java.util.concurrent.FutureTask.run(FutureTask.java:266)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>The java class:</p>
  
  <pre><code>import com.sun.media.jai.codec.ImageCodec;
  import com.sun.media.jai.codec.ImageDecoder;
  
  public class PdfUtil {
  
  ...
  
    Path path = Paths.get(getInput()); //getInput() returns a string path to the tiff file
    byte[] tiffImage = Files.readAllBytes(path);
  
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    InputStream inputStream = new ByteArrayInputStream(tiffImage);
    ImageDecoder tiffDecoder = ImageCodec.createImageDecoder("tiff", inputStream, null);
    int pages = tiffDecoder.getNumPages();
  ...
  }
  </code></pre>