You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2019/03/02 12:39:42 UTC
[GitHub] liketic commented on a change in pull request #1958: Use automatic
resource management to close streams
liketic commented on a change in pull request #1958: Use automatic resource management to close streams
URL: https://github.com/apache/bookkeeper/pull/1958#discussion_r261825534
##########
File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/Cookie.java
##########
@@ -217,16 +217,9 @@ public void writeToDirectory(File directory) throws IOException {
}
public void writeToFile (File versionFile) throws IOException {
- FileOutputStream fos = new FileOutputStream(versionFile);
- BufferedWriter bw = null;
- try {
- bw = new BufferedWriter(new OutputStreamWriter(fos, UTF_8));
+ try (FileOutputStream fos = new FileOutputStream(versionFile);
+ BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, UTF_8))) {
Review comment:
Thanks @sigee , are you suggest we add a try block for each closable resource here? I think that's won't be necessary. As this [doc](https://www.oracle.com/technetwork/articles/java/trywithresources-401775.html) said: ```Any resource declared within a try block opening will be closed.```, so one try-block is enough. WDYT?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services