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

Perfect. Thanks fot the answer!

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();
					}