Skip to content

Commit

Permalink
Use try-with-resources instead of Closer.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 537940469
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Jun 5, 2023
1 parent e27cfe2 commit b5345e6
Showing 1 changed file with 3 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
*/
package com.google.auto.service.processor;

import static com.google.common.base.Charsets.UTF_8;
import static java.nio.charset.StandardCharsets.UTF_8;

import com.google.common.io.Closer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
Expand Down Expand Up @@ -57,12 +56,9 @@ static String getPath(String serviceName) {
*/
static Set<String> readServiceFile(InputStream input) throws IOException {
HashSet<String> serviceClasses = new HashSet<String>();
Closer closer = Closer.create();
try {
// TODO(gak): use CharStreams
BufferedReader r = closer.register(new BufferedReader(new InputStreamReader(input, UTF_8)));
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, UTF_8))) {
String line;
while ((line = r.readLine()) != null) {
while ((line = reader.readLine()) != null) {
int commentStart = line.indexOf('#');
if (commentStart >= 0) {
line = line.substring(0, commentStart);
Expand All @@ -73,10 +69,6 @@ static Set<String> readServiceFile(InputStream input) throws IOException {
}
}
return serviceClasses;
} catch (Throwable t) {
throw closer.rethrow(t);
} finally {
closer.close();
}
}

Expand Down

0 comments on commit b5345e6

Please sign in to comment.