Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Close stream - File Downloader
Hello all,
I have a question regarding downloading a file and closing the stream.
In the example https://vaadin.com/wiki/-/wiki/Main/Letting+the+user+download+a+file a new ByteArrayOutputStream and InputStream is created, but never closed.
Is this correct? Who is closing the streams?
Best Regards,
Thomas
It is not mandatory. The close operation of those is NOP. See also here.
http://stackoverflow.com/questions/2330569/closing-a-bytearrayoutputstream-has-no-effect
Maybe this will enligthen you : )
//test if it's an image
if(getFileExtension(aUploadedFile)) {
OneFiletoUpload oftu = new OneFiletoUpload();
oftu.setOutputfile(destinationfile);
getManyuploadfiles().add(oftu);
FileOutputStream fos = new FileOutputStream(aUploadedFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = inputstream.read(bytes)) != -1) {
fos.write(bytes, 0, read);
}
fos.close();
}