|
23 | 23 | * When a function name does not contains file or directory, it can be used with both.
|
24 | 24 | * All functions return true if it work and false if it doesn't.
|
25 | 25 | * Long opperation that are multithreaded:
|
26 |
| - * - zip |
27 | 26 | * - unzip
|
28 | 27 | * - copy
|
29 | 28 | *
|
@@ -73,6 +72,9 @@ private static void setDownloadingMessage(String message) {
|
73 | 72 | public static List<String> listFilesRecursively(String path) { return internal.listFilesRecursively(path); }
|
74 | 73 |
|
75 | 74 | public static boolean zip(String source, String destination) { return internal.zip(source, destination); }
|
| 75 | + /** |
| 76 | + * @param directoryInsideZipToGet If it's a/b/ then b/ will be created. To have only b content, use a/b/* |
| 77 | + */ |
76 | 78 | public static boolean unzip(String source, String destination, String directoryInsideZipToGet) {
|
77 | 79 | return internal.unzip(source, destination, directoryInsideZipToGet);
|
78 | 80 | }
|
@@ -313,7 +315,7 @@ private void zipFile(File fileToZip, String fileName, String destination, ZipOut
|
313 | 315 | zos.putNextEntry(new ZipEntry(finalfileName));
|
314 | 316 | zos.closeEntry();
|
315 | 317 | List<Boolean> allOk = Arrays.asList(true);
|
316 |
| - Arrays.stream(fileToZip.listFiles()).parallel().forEach(file -> { |
| 318 | + Arrays.stream(fileToZip.listFiles()).forEach(file -> { |
317 | 319 | try {
|
318 | 320 | zipFile(file, finalfileName + file.getName(), destination, zos);
|
319 | 321 | } catch (IOException e) {
|
@@ -384,14 +386,18 @@ private boolean unzipAllEntries(String source, String destination, String direct
|
384 | 386 |
|
385 | 387 | private boolean createZipEntry(String destination, String directoryInsideZipToGet, InputStream zis, ZipEntry entry)
|
386 | 388 | throws IOException {
|
| 389 | + boolean noDirectory = directoryInsideZipToGet.endsWith("*"); |
| 390 | + if (noDirectory) { |
| 391 | + directoryInsideZipToGet = directoryInsideZipToGet.substring(0, directoryInsideZipToGet.length() - 1); |
| 392 | + } |
387 | 393 | directoryInsideZipToGet = FLUStrings.removeAtTheEndIfNeeded(directoryInsideZipToGet.replace('\\', '/'), FILE_SEPARATOR);
|
388 | 394 | File destinationFile = new File(destination);
|
389 | 395 | String absoluteDestinationPath = FLUStrings.addAtTheEndIfNeeded(destinationFile.getAbsolutePath().replace('\\', '/'),
|
390 | 396 | FILE_SEPARATOR);
|
391 | 397 | String entryName = entry.getName().replace('\\', '/');
|
392 | 398 | if (directoryInsideZipToGet.isEmpty() || directoryInsideZipToGet.equals(".") || entryName.startsWith(directoryInsideZipToGet)) {
|
393 | 399 | // Remove part of the path that we don't want
|
394 |
| - int charToCut = directoryInsideZipToGet.lastIndexOf('/'); |
| 400 | + int charToCut = noDirectory ? directoryInsideZipToGet.length() : directoryInsideZipToGet.lastIndexOf('/'); |
395 | 401 | entryName = FLUStrings.removeAtTheBeginningIfNeeded(entryName.substring(Math.max(0, charToCut)), FILE_SEPARATOR);
|
396 | 402 |
|
397 | 403 | if (entryName.isEmpty()) {
|
|
0 commit comments