0

This is a follow up of How to upload an image using ByteArrayOutputStream in Vaadin?

I put the code from there into my app. However, the inner part of the overridden getStream() is called only once and on the next image change attempt, no more. The code outside is executed. No statics used.

final byte [] imageBytes =  beanItem.getPicture(); // a byte []
 StreamSource streamSource = new StreamResource.StreamSource() {
    @Override
    public InputStream getStream() {
        System.out.println(">>>> streamResource:getStream called.size:" + imageBytes.length);
        return (imageBytes == null) ? null : new ByteArrayInputStream(imageBytes);
        }
};

  StreamResource imageResource = new StreamResource(streamSource, "");
  image.setSource (imageResource);

Any help is appreciated.

Regards Gerry

user1226230
  • 381
  • 1
  • 3
  • 11
  • Check this another question here: https://stackoverflow.com/questions/9501237/read-stream-twice – Tatu Lund Oct 10 '18 at 14:49
  • Thanks for the hint. Will check it tomorrow. I wonder if the solution of the referred thread will be applicable as shown in the above fragment, the stream is fully re-created on each call. Perhaps the stream consuming image is not able to detect that a new stream is loaded and thereby sees no need to call the stream again. – user1226230 Oct 10 '18 at 18:14
  • How do you call this piece of code? Do you have it inside a `ValueChangedListener` or in a `ClickListener` ? – Niby Oct 11 '18 at 13:58
  • @Niby: Yes, exactly a 'valueChangeListener' in a table. – user1226230 Oct 11 '18 at 18:29

0 Answers0