Close more inputstreams

This commit is contained in:
Roel Spilker
2020-01-20 13:55:43 +01:00
parent 7ca43108f5
commit 18d70e7bc6
3 changed files with 30 additions and 18 deletions
+9 -5
View File
@@ -354,11 +354,15 @@ public class Delombok {
StringBuilder s = new StringBuilder();
try {
InputStreamReader isr = new InputStreamReader(in, "UTF-8");
char[] c = new char[4096];
while (true) {
int r = isr.read(c);
if (r == -1) break;
s.append(c, 0, r);
try {
char[] c = new char[4096];
while (true) {
int r = isr.read(c);
if (r == -1) break;
s.append(c, 0, r);
}
} finally {
isr.close();
}
} finally {
in.close();
@@ -364,16 +364,20 @@ class ShadowClassLoader extends ClassLoader {
FileInputStream jar = new FileInputStream(jarLoc);
try {
ZipInputStream zip = new ZipInputStream(jar);
while (true) {
ZipEntry entry = zip.getNextEntry();
if (entry == null) {
jarLocCache.put(key, false);
return false;
try {
while (true) {
ZipEntry entry = zip.getNextEntry();
if (entry == null) {
jarLocCache.put(key, false);
return false;
}
if (!"META-INF/ShadowClassLoader".equals(entry.getName())) continue;
boolean v = sclFileContainsSuffix(zip, suffix);
jarLocCache.put(key, v);
return v;
}
if (!"META-INF/ShadowClassLoader".equals(entry.getName())) continue;
boolean v = sclFileContainsSuffix(zip, suffix);
jarLocCache.put(key, v);
return v;
} finally {
zip.close();
}
} finally {
jar.close();
@@ -21,11 +21,15 @@ public class FetchCurrentVersion {
InputStream in = new URL("https://projectlombok.org/download").openStream();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(in, "UTF-8"));
for (String line = br.readLine(); line != null; line = br.readLine()) {
Matcher m = VERSION_PATTERN.matcher(line);
if (m.matches() && m.group(1).equals("currentVersionFull") == fetchFull) return m.group(2).replace(""", "\"");
try {
for (String line = br.readLine(); line != null; line = br.readLine()) {
Matcher m = VERSION_PATTERN.matcher(line);
if (m.matches() && m.group(1).equals("currentVersionFull") == fetchFull) return m.group(2).replace(""", "\"");
}
throw new IOException("Expected a span with id 'currentVersion'");
} finally {
br.close();
}
throw new IOException("Expected a span with id 'currentVersion'");
} finally {
in.close();
}