ImageIO.createImageOutputStream returns null
See original GitHub issueI am using the TwelveMonkey TIFF plugin to save TIFF files to a network share that is connected as NFS.
On one computer that I use (Windows 7) this appears to work flawlessly. However on another computer (Windows 10) I get an occasional issue where ImageIO.createImageOutputStream
returns null.
Here is a snippet of the problematic code:
File directory = new File(this.savePath);
if (!directory.exists()) { directory.mkdirs(); }
File file = Paths.get(this.savePath, fullFileName).toFile();
try (ImageOutputStream outStream = ImageIO.createImageOutputStream(file)) {
writer.setOutput(outStream);
writer.prepareWriteSequence(null); //null means we will use the default streamMetadata.
...
It seems that for roughly 1 out of 3 runs of this code the outputStream gets returned as null
. This then correctly causes an exception to be thrown at writer.setOutput(outStream
.
How can I figure out why the plugin is failing to create an outputStream?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
ImageIO.createImageInputStream is returning null, how come?
Try using an InputStream constructed with the File . ImageIO.createImageInputStream(new FileInputStream(f));. Here's a related example.
Read more >ImageIO (Java Platform SE 7 ) - Oracle Help Center
Returns an ImageWriter corresponding to the given ImageReader , if there is one, or null if the plug-in for this ImageReader does not...
Read more >ImageIO.createImageOutputStream - Java - Tabnine
ImageIO.createImageOutputStream (Showing top 20 results out of 1,602) ... writeToSequence(new IIOImage(image, null, null), writer.getDefaultWriteParam()) ...
Read more >javax.imageio.ImageIO#createImageOutputStream
This page shows Java code examples of javax.imageio.ImageIO#createImageOutputStream.
Read more >In ImageIO.write() and ImageIO.read() null stream is not ...
ImageOutputStream is created through code "stream = createImageOutputStream(output);" In the finally block stream is closed without null check
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, in todays testing I did in fact see a stack trace printed out and you were right about the cause.
Here is the stack trace:
I noticed that this only happens when there isn’t a break point that results in a pause between creating the
File
and callingcreateImageOutputStream
so it’s probably something to do with timing.I’ll have to do some more reading about
RandomAccessFile
, hopefully I can make the program briefly pause until theFile
is read to be passed in tocreateImageOutputStream
.Since this is clearly not related to TwelveMonkeys I’ll go ahead and close this. Thanks for the help!
Thanks @haraldk , I’ll see if I can dig into what is going on in
com.sun.imageio.spi.FileImageOutputStreamSpi
.When looking at the output in the debugger I didn’t see any stack traces coming up which makes me think that the
null
I was getting may actually come directly fromImageIO.createImageOutputStream
: