Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing multiple images to byteArrayOutputstream

Tags:

java

java-io

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.

like image 802
TP_JAVA Avatar asked Jan 31 '26 01:01

TP_JAVA


1 Answers

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
like image 65
DnR Avatar answered Feb 01 '26 14:02

DnR