Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Error reading image from InputStream

 
Anil Bharadia
Greenhorn
Posts: 15
Eclipse IDE jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting NegativeArraySizeException in line
img = ImageIO.read(is);

 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch.
The only thing I can think of is that the data you are reading is not an image file. Try just writing the data to disk and opening it with an image viewer. Do you have control of the other side of the socket? How is the image written?
 
Rob Spoor
Sheriff
Posts: 20822
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:The only thing I can think of is that the data you are reading is not an image file.

Then ImageIO.read should return null, not throw an exception.

Anil, can you show us the complete stack trace?
 
Anil Bharadia
Greenhorn
Posts: 15
Eclipse IDE jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Friends, its solved
i have control over other side of the socket.

i have changed the image type while i write it to OutputStream

from this
ImageIO.write(image, "jpeg", os);
// os is the OutputStream
to this
ImageIO.write(image, "BMP", os);

now it runs perfectly

thanks for your advice.
 
It means our mission is in jeapordy! Quick, read this tiny ad!
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!