سؤال

I have a webapp running on Java 6 in Tomcat 6. ImageIO.read is returning null.

It attempts to retrieve tiff images from a computer on the same [Windows] network. To do this, I use JCIFS as auth, and jai to read the images.

In QA, this works, I retrieve and display the TIFs. In production, it does not.

I am able to access the images and it correctly retrieves the file paths.

Here is the error from the log:

2013-11-18 11:06:47,405 [webapp] INFO  [http-8080-6] 
ScannedService.getScannedDocuments(66) | Customer.java 
get files at Paths[smb://sharedDrived/path/1HK01001.TIF]

2013-11-18 11:06:47,421 [webapp] INFO  [http-8080-6] 
ScannedDocument.<init>(32) | ScannedDocument.java 
constructor, image value: null

The null is what is returned by:

ImageIO.read(smbStream);

Why that line is returning null?

هل كانت مفيدة؟

المحلول

The reason ImageIO.read returns null, is that no ImageReader plugin claims to be able to read it (otherwise, unless input is null, a read is attempted using the first plugin that claims it can read the input, and you either get an image or an exception is thrown).

This can be caused by two things. Either there is no plugins installed (discovered by ImageIO). Or the input is corrupted so that it's not recognized. You seem to have done enough debugging/testing to determine that the latter is not the issue here. So I still think the problem is with the installation of jai-imageio, or possibly that the JAI plugins are not discovered by ImageIO.

You can try (either in your application's start-up, or every time you get a null image) to print all the formats supported by ImageIO (using ImageIO.getReaderFormatNames()) to the debug log, and see if TIFF is listed.

Note that if you provide the jai-imageio JARs as part of your web application (in WEB-INF/lib), the plugins are not automatically discovered after a re-deploy, unless you do ImageIO.scanForPlugins(). In that case, I suggest you read Deploying the plugins in a web app.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top