Your call to getFormatName consumes inputStream , so the stream pointer is at the end of the byte array. Any attempt to read from this stream will report that it is at the end of the "file". You need to reset the thread (or create a new one) before passing it to the ImageIO.read () method:
String format = getFormatName(new ByteArrayInputStream(imageData)); BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));
source share