+ RepackZip

This commit is contained in:
Dmitry Isaenko 2025-05-04 23:55:55 +03:00
parent 04db2d02f6
commit 3d4a0e59d2

View file

@ -44,23 +44,17 @@ public class RepackZip {
* if (lastTimeExec != null) * if (lastTimeExec != null)
return true; return true;
*/ */
Thread repackThread = new Thread(() -> { new Thread(() -> Stream.of(folderContainer.listFiles())
List<File> files = Stream.of(folderContainer.listFiles()) .filter(file -> file.getName().toLowerCase().endsWith(".zip"))
.filter(file -> file.getName().toLowerCase().endsWith(".zip")) .forEach(file -> executor.execute(new InnerRepackZip(file)))
.toList(); ).start();
for (File file : files)
executor.execute(new InnerRepackZip(file));
});
repackThread.start();
return true; return true;
} }
private class InnerRepackZip implements Runnable { private class InnerRepackZip implements Runnable {
private String dirLocation; private String dirLocation;
private File container; private final File container;
private InnerRepackZip(File container) { private InnerRepackZip(File container) {
this.container = container; this.container = container;
@ -68,7 +62,7 @@ public class RepackZip {
@Override @Override
public void run() { public void run() {
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(container))) { try (var zipInputStream = new ZipInputStream(new FileInputStream(container))) {
dirLocation = container.getParentFile().getAbsolutePath() + dirLocation = container.getParentFile().getAbsolutePath() +
File.separator + File.separator +
container.getName().replaceAll("(\\.zip)|(\\.ZIP)", ""); container.getName().replaceAll("(\\.zip)|(\\.ZIP)", "");
@ -100,13 +94,11 @@ public class RepackZip {
return; return;
} }
try (ZipOutputStream outputStream = new ZipOutputStream( try (var outputStream = new ZipOutputStream(new FileOutputStream(newZipFile))) {
new FileOutputStream(newZipFile))) { var entryToCompress = new ZipEntry(entry.getName());
ZipEntry entryToCompress = new ZipEntry(entry.getName());
outputStream.putNextEntry(entryToCompress); outputStream.putNextEntry(entryToCompress);
long fileSize = entry.getSize(); long fileSize = entry.getSize();
int blockSize = 2048; int blockSize = 2048;
if (fileSize < 2048) if (fileSize < 2048)