-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try with resources #5
Conversation
@@ -300,8 +293,6 @@ private void populateFile( File file ) throws IOException | |||
try ( FileOutputStream outputStream = new FileOutputStream( file ) ) | |||
{ | |||
outputStream.write( data.getBytes() ); | |||
outputStream.flush(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think the .flush()
is guaranteed by try-with-resources... but perhaps by not wrapping FOS in a BufferedOutputStream then that's not a problem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
close also flushes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @roxspring is right about FOS not wrapped in BOS not being problem for flushing or not. But I'm not sure that close also flushes. There is flush
called in FOS.finalize
but close
inherited from OutputStream
is no-op (immaterial), as FOS.close
doesn't seem to call flush neither.
On the other hand close
of BufferedOutputStream
flushes indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling flush just before close is generally useless cause close ensures all data have been written.
That said we are speaking of a FileOutputStream where flush() is a noop so it is even safer to drop.
@roxspring