Skip to content

Commit

Permalink
Close ZipOutputStream in eclipse dependency downloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawi01 committed Oct 19, 2024
1 parent c8d6152 commit d21d551
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
Expand Down Expand Up @@ -66,17 +67,12 @@ public static void main(String[] args) throws Exception {
String pluginSource = updateSite.getResolvedUrl() + "/plugins/";

for (String artifact : artifacts) {
try {
downloadFile(artifact, pluginSource, pluginTarget);
} catch (Exception e) {
}

// Download artifact
downloadFile(artifact, pluginSource, pluginTarget);
// Download artifact source
int index = artifact.lastIndexOf("_");
String source = artifact.substring(0, index) + ".source" + artifact.substring(index);
try {
downloadFile(source, pluginSource, pluginTarget);
} catch (Exception e) {
}
downloadFile(source, pluginSource, pluginTarget);
}

writeEclipseLibrary(target, eclipseVersion);
Expand All @@ -102,23 +98,27 @@ private static void downloadFile(String filename, String repositoryUrl, String t
} catch (IOException e) {
System.out.println("[error]");
} finally {
if (in != null) try {
in.close();
} catch (Exception ignore) {
}
if (out != null) out.close();
closeQuietly(in);
closeQuietly(out);
}
}

private static void copyZipButStripSignatures(InputStream rawIn, OutputStream rawOut) throws IOException {
ZipInputStream in = new ZipInputStream(rawIn);
ZipOutputStream out = new ZipOutputStream(rawOut);

ZipEntry zipEntry;
while ((zipEntry = in.getNextEntry()) != null) {
if (zipEntry.getName().matches("META-INF/.*\\.(SF|RSA)")) continue;
out.putNextEntry(zipEntry);
copy(in, out);
ZipInputStream in = null;
ZipOutputStream out = null;
try {
in = new ZipInputStream(rawIn);
out = new ZipOutputStream(rawOut);

ZipEntry zipEntry;
while ((zipEntry = in.getNextEntry()) != null) {
if (zipEntry.getName().matches("META-INF/.*\\.(SF|RSA)")) continue;
out.putNextEntry(zipEntry);
copy(in, out);
}
} finally {
closeQuietly(in);
closeQuietly(out);
}
}

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

private static void closeQuietly(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException ignore) {
}
}
}

private static InputStream getStreamForUrl(String url) throws IOException, MalformedURLException {
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setRequestProperty("User-Agent", "lombok");
Expand Down

0 comments on commit d21d551

Please sign in to comment.