You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by rw...@apache.org on 2020/04/16 03:57:11 UTC
svn commit: r1876577 -
/pivot/trunk/core/src/org/apache/pivot/util/Service.java
Author: rwhitcomb
Date: Thu Apr 16 03:57:11 2020
New Revision: 1876577
URL: http://svn.apache.org/viewvc?rev=1876577&view=rev
Log:
Refactor code in Service to use "try-with-resources".
Modified:
pivot/trunk/core/src/org/apache/pivot/util/Service.java
Modified: pivot/trunk/core/src/org/apache/pivot/util/Service.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/util/Service.java?rev=1876577&r1=1876576&r2=1876577&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/util/Service.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/util/Service.java Thu Apr 16 03:57:11 2020
@@ -65,22 +65,16 @@ public final class Service {
InputStream serviceInputStream = classLoader.getResourceAsStream(serviceName);
if (serviceInputStream != null) {
- try {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new InputStreamReader(serviceInputStream,
- StandardCharsets.UTF_8));
- String line = reader.readLine();
- while (line != null && (line.length() == 0 || line.startsWith("#"))) {
- line = reader.readLine();
- }
+ try (BufferedReader reader = new BufferedReader(
+ new InputStreamReader(serviceInputStream,
+ StandardCharsets.UTF_8))) {
+ String line;
+ do {
+ line = reader.readLine();
+ } while (line != null && (line.isEmpty() || line.startsWith("#")));
- providerClassName = line;
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
+ // First non-blank, non-comment line should be the provider class name
+ providerClassName = line;
} catch (IOException exception) {
// No-op
}