You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/03/10 22:23:13 UTC
[commons-daemon] branch master updated: Use try-with-resources.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-daemon.git
The following commit(s) were added to refs/heads/master by this push:
new 9c6a440 Use try-with-resources.
9c6a440 is described below
commit 9c6a44015c220b70961659f0fc25f817912942b4
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Mar 10 17:23:09 2022 -0500
Use try-with-resources.
---
src/test/java/org/apache/commons/daemon/SimpleDaemon.java | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
diff --git a/src/test/java/org/apache/commons/daemon/SimpleDaemon.java b/src/test/java/org/apache/commons/daemon/SimpleDaemon.java
index f1c3694..39ee6bb 100644
--- a/src/test/java/org/apache/commons/daemon/SimpleDaemon.java
+++ b/src/test/java/org/apache/commons/daemon/SimpleDaemon.java
@@ -228,15 +228,11 @@ public class SimpleDaemon implements Daemon, Runnable, DaemonUserSignal {
return this.directory;
}
- public void log(final String name)
- throws IOException {
- final OutputStream file=new FileOutputStream(name,true);
- final PrintStream out=new PrintStream(file);
- final SimpleDateFormat fmt=new SimpleDateFormat();
-
- out.println(fmt.format(new Date()));
- out.close();
- file.close();
+ public void log(final String name) throws IOException {
+ try (final OutputStream file = new FileOutputStream(name, true);
+ final PrintStream out = new PrintStream(file)) {
+ out.println(new SimpleDateFormat().format(new Date()));
+ }
}
public void handle(final InputStream in, final OutputStream os) {