Skip to content

Commit ddad4e6

Browse files
Vladimir Kotalahornace
authored andcommitted
use try-with-resources on the Reader
also fix some readability issues
1 parent a903f80 commit ddad4e6

File tree

1 file changed

+13
-13
lines changed
  • opengrok-indexer/src/main/java/org/opengrok/indexer/web

1 file changed

+13
-13
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/web/Util.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,31 +1196,31 @@ public static boolean dump(Writer out, File file, boolean compressed) {
11961196
* {@link IOException}s get caught and logged, but not re-thrown.
11971197
* @param out dump destination
11981198
* @param file file to dump
1199-
* @param compressed if {@code true} the denoted file is assumed to be
1200-
* gzipped
1199+
* @param compressed if {@code true} the denoted file is assumed to be gzipped
12011200
* @param contextPath an optional override of "/source/" as the context path
12021201
* @return {@code true} on success (everything read and written)
12031202
* @throws NullPointerException if a parameter is {@code null}.
12041203
*/
1205-
public static boolean dumpXref(Writer out, File file, boolean compressed,
1206-
String contextPath) {
1204+
public static boolean dumpXref(Writer out, File file, boolean compressed, String contextPath) {
1205+
12071206
if (!file.exists()) {
12081207
return false;
12091208
}
1210-
/**
1209+
1210+
/*
12111211
* For backward compatibility, read the OpenGrok-produced document
12121212
* using the system default charset.
12131213
*/
1214-
try (InputStream iss = new BufferedInputStream(
1215-
new FileInputStream(file))) {
1216-
Reader in = compressed ? new InputStreamReader(new GZIPInputStream(
1217-
iss)) : new InputStreamReader(iss);
1218-
dumpXref(out, in, contextPath);
1219-
return true;
1214+
try (InputStream iss = new BufferedInputStream(new FileInputStream(file))) {
1215+
try (Reader in = compressed ? new InputStreamReader(new GZIPInputStream(iss)) :
1216+
new InputStreamReader(iss)) {
1217+
dumpXref(out, in, contextPath);
1218+
return true;
1219+
}
12201220
} catch (IOException e) {
1221-
LOGGER.log(Level.WARNING, "An error occured while piping file " +
1222-
file, e);
1221+
LOGGER.log(Level.WARNING, "An error occurred while piping file " + file, e);
12231222
}
1223+
12241224
return false;
12251225
}
12261226

0 commit comments

Comments
 (0)