title: Issue with reading Tiff image metadata with imageIO
body: <p>I'm writing a program that is supposed to taking in a bunch of tiff's and put them together.  I got it to work for most of the image files I read in but a large batch of them throw out an error when I try to read them in.  </p>
  
  <p>Here is a snippet of code I have:</p>
  
  <pre><code>int numPages = 0;           
  inStream = ImageIO.createImageInputStream(imageFile);
  reader.setInput(inStream);
  
  while(true){
      bufferedImages.add(reader.readAll(numPages, reader.getDefaultReadParam()));
      numPages++;
  }
  </code></pre>
  
  <p>Yes I catch the out of bounds exception so we don't have to worry about that.  My problem is that I get the following error:</p>
  
  <blockquote>
    <p>javax.imageio.IIOException: I/O error reading image metadata!
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:340)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:310)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.prepareRead(TIFFImageReader.java:971)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1153)
        at javax.imageio.ImageReader.readAll(ImageReader.java:1067)
        at sel.image.appender.ImageAppender.mergeImages(ImageAppender.java:59)
        at sel.imagenow.processor.AetnaLTCProcessor.processBatch(AetnaLTCProcessor.java:287)
        at sel.imagenow.processor.AetnaLTCProcessor.processImpl(AetnaLTCProcessor.java:81)
        at sel.processor.AbstractImageNowProcessor.process(AbstractImageNowProcessor.java:49)
        at sel.RunConverter.main(RunConverter.java:37)</p>
    
    <p>Caused by: java.io.EOFException
        at javax.imageio.stream.ImageInputStreamImpl.readShort(ImageInputStreamImpl.java:229)
        at javax.imageio.stream.ImageInputStreamImpl.readUnsignedShort(ImageInputStreamImpl.java:242)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFIFD.initialize(TIFFIFD.java:194)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageMetadata.initializeFromStream(TIFFImageMetadata.java:110)
        at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.readMetadata(TIFFImageReader.java:336)
        ... 9 more</p>
  </blockquote>
  
  <p>I did make sure to add in the right JAI lib and my reader is using the "TIFF" type so the reader (and writer) is correct but for some reason the metadata is wrong.  Now I can open and view all these images normally in windows so they really aren't corrupted or anything.  Java just doesn't want to read them in right.  Since I'm just using the stream meatadata to write them out later I don't care that much about the metadata I just need it to read in the file to the list so I can append it.  I did find a writer.replaceImageMetaData method on the writer but the TIFFwriter version of IOWriter doens't have code for it.  I'm stuck, anyone anything?  Is there maybe a way to read in parts of the metadata to see what is wrong and fix it?        </p>