简体   繁体   中英

ImageIO is null reading ByteArrayInputStream

I have this piece of code

System.out.println  ("fileData 1 -> " + fileData);

ByteArrayInputStream in = new ByteArrayInputStream(fileData);

System.out.println  ("fileData 2 -> " + in);

try {
    BufferedImage img = ImageIO.read(in);
    System.out.println  ("fileData 3 -> " + img);

....

and this is what I see in the console:

fileData 1 -> [B@7a677c
fileData 2 -> java.io.ByteArrayInputStream@203aa8
fileData 3 -> null

How come that BufferedImage is null and does not throw an Exception ?

The documentation says, it can be null:

Returns a BufferedImage as the result of decoding a supplied InputStream with an ImageReader chosen automatically from among those currently registered. The InputStream is wrapped in an ImageInputStream. If no registered ImageReader claims to be able to read the resulting stream, null is returned. [...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM