From 0bc7f199007c6403d02c45d56b2e88e8f6314583 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Fri, 18 Oct 2024 00:04:21 +0200 Subject: [PATCH] [refactor] The 'copy zip files stripping signatures' code cleaned up ever so slightly; timestamps of zip entries is now preserved. --- .../DownloadEclipseDependencies.java | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java b/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java index 0aa9934d..eff44bf7 100644 --- a/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java +++ b/src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java @@ -90,22 +90,14 @@ public class DownloadEclipseDependencies { return; } System.out.print("Downloading '" + filename + "'... "); - ZipInputStream in = null; - ZipOutputStream out = null; + + InputStream in = null; + OutputStream out = null; try { - in = new ZipInputStream(getStreamForUrl(repositoryUrl + filename)); - out = new ZipOutputStream(new FileOutputStream(targetFile)); + in = getStreamForUrl(repositoryUrl + filename); + out = new FileOutputStream(targetFile); - ZipEntry zipEntry; - while ((zipEntry = in.getNextEntry()) != null) { - String name = zipEntry.getName(); - - // Remove signature files - if (name.matches("META-INF/.*\\.(SF|RSA)")) continue; - - out.putNextEntry(new ZipEntry(name)); - copy(in, out); - } + copyZipButStripSignatures(in, out); System.out.println("[done]"); } catch (IOException e) { System.out.println("[error]"); @@ -118,6 +110,18 @@ public class DownloadEclipseDependencies { } } + 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); + } + } + private static void copy(InputStream from, OutputStream to) throws IOException { byte[] b = new byte[4096]; while (true) {