3

I've a requirement to add multiple images to a output stream and display those images in JSF.

Ex code:

List<inputStream> images = list of inputstream - each image is one input stream

ByteArrayOutputStream stream = new ByteArrayOutputStream()
for(inputStream iStream: images){
    stream.write(IOUtils.toByteArray(iStream);
}
return stream.toByteArray();

Now it is displaying only first Image but not displaying remaining images.

Please help me here to get pass multiple images and display in jsp.

TP_JAVA
  • 1,002
  • 5
  • 23
  • 49

1 Answers1

3

You can try like this:

ByteArrayOutputStream stream = new ByteArrayOutputStream();
List<byte[]> imagesByteList = new List<byte[]>;
for(inputStream iStream: images){
    stream.write(IOUtils.toByteArray(iStream);     
    imagesByteList.add(stream.toByteArray());
    stream.reset();
}
return imagesByteList; // here you get all your image in bytes array form
DnR
  • 3,487
  • 3
  • 23
  • 31
  • Thanks for the response...so it is returning list of byte[]..in my JSP i've to iterate and display it? but I should have only one link in my JSP which should display all the images by clicking on single link – TP_JAVA Apr 22 '15 at 03:02
  • Yes. I guess it is not a problem right? you can handle the iteration on page load – DnR Apr 22 '15 at 03:09
  • But These images are check front and back side..so clicking on single link have to show two images... – TP_JAVA Apr 22 '15 at 03:13
  • urmm, I don't get it. – DnR Apr 22 '15 at 03:19
  • Since it is a list..I've to iterate in that case each image will have single link but i want to display all the images upon clicking on single link. – TP_JAVA Apr 22 '15 at 03:21
  • I guess you can use a single link to pass the list of images. take a look at [this](http://stackoverflow.com/questions/1538821/pass-a-list-to-another-jsp-file) – DnR Apr 22 '15 at 03:26