Skip to content

Commit d21d551

Browse files
committed
Close ZipOutputStream in eclipse dependency downloader
1 parent c8d6152 commit d21d551

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java

+31-22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import java.io.BufferedInputStream;
2525
import java.io.ByteArrayInputStream;
26+
import java.io.Closeable;
2627
import java.io.File;
2728
import java.io.FileOutputStream;
2829
import java.io.FilenameFilter;
@@ -66,17 +67,12 @@ public static void main(String[] args) throws Exception {
6667
String pluginSource = updateSite.getResolvedUrl() + "/plugins/";
6768

6869
for (String artifact : artifacts) {
69-
try {
70-
downloadFile(artifact, pluginSource, pluginTarget);
71-
} catch (Exception e) {
72-
}
73-
70+
// Download artifact
71+
downloadFile(artifact, pluginSource, pluginTarget);
72+
// Download artifact source
7473
int index = artifact.lastIndexOf("_");
7574
String source = artifact.substring(0, index) + ".source" + artifact.substring(index);
76-
try {
77-
downloadFile(source, pluginSource, pluginTarget);
78-
} catch (Exception e) {
79-
}
75+
downloadFile(source, pluginSource, pluginTarget);
8076
}
8177

8278
writeEclipseLibrary(target, eclipseVersion);
@@ -102,23 +98,27 @@ private static void downloadFile(String filename, String repositoryUrl, String t
10298
} catch (IOException e) {
10399
System.out.println("[error]");
104100
} finally {
105-
if (in != null) try {
106-
in.close();
107-
} catch (Exception ignore) {
108-
}
109-
if (out != null) out.close();
101+
closeQuietly(in);
102+
closeQuietly(out);
110103
}
111104
}
112105

113106
private static void copyZipButStripSignatures(InputStream rawIn, OutputStream rawOut) throws IOException {
114-
ZipInputStream in = new ZipInputStream(rawIn);
115-
ZipOutputStream out = new ZipOutputStream(rawOut);
116-
117-
ZipEntry zipEntry;
118-
while ((zipEntry = in.getNextEntry()) != null) {
119-
if (zipEntry.getName().matches("META-INF/.*\\.(SF|RSA)")) continue;
120-
out.putNextEntry(zipEntry);
121-
copy(in, out);
107+
ZipInputStream in = null;
108+
ZipOutputStream out = null;
109+
try {
110+
in = new ZipInputStream(rawIn);
111+
out = new ZipOutputStream(rawOut);
112+
113+
ZipEntry zipEntry;
114+
while ((zipEntry = in.getNextEntry()) != null) {
115+
if (zipEntry.getName().matches("META-INF/.*\\.(SF|RSA)")) continue;
116+
out.putNextEntry(zipEntry);
117+
copy(in, out);
118+
}
119+
} finally {
120+
closeQuietly(in);
121+
closeQuietly(out);
122122
}
123123
}
124124

@@ -131,6 +131,15 @@ private static void copy(InputStream from, OutputStream to) throws IOException {
131131
}
132132
}
133133

134+
private static void closeQuietly(Closeable closeable) {
135+
if (closeable != null) {
136+
try {
137+
closeable.close();
138+
} catch (IOException ignore) {
139+
}
140+
}
141+
}
142+
134143
private static InputStream getStreamForUrl(String url) throws IOException, MalformedURLException {
135144
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
136145
connection.setRequestProperty("User-Agent", "lombok");

0 commit comments

Comments
 (0)