• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I get a byte-array to display the image in a browser ???  RSS feed

 
achana chan
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a .gif image stored in a byte array :
public byte[] picture;
I really do not want to write to a file first, and then use getImage() method to display the picture because it is an i/o overhead.
Are there any other ways of doing this ???
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically you want to have the image data served by a servlet from the byte array instead of the web server from a file. You have to arrange that the URL in the <img> tag points to a servlet that has the byte array. You have to set the response content-type to "image/gif" and the content-length to the byte[].length. See the HttpServletResponse API.
You MUST get an output stream instead of a writer so the bytes will go out unaltered. Then just write the byte array and close the stream.
This is a common item in many servlet books and you can find plenty of related discussions in older threads here.
Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!