Skip to content

Commit

Permalink
🛠️ add ability to save package as source
Browse files Browse the repository at this point in the history
  • Loading branch information
teras committed Sep 2, 2022
1 parent 912af07 commit f9f17fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

import static java.util.stream.Collectors.toList;
import static org.crossmobile.bridge.system.BaseUtils.listFiles;
Expand Down Expand Up @@ -678,6 +682,31 @@ public static boolean endsWithPathSeparator(String path) {
return path.endsWith("/") || path.endsWith("\\");
}

public static boolean zip(File sourceDir, File destZip) {

try (ZipOutputStream zs = new ZipOutputStream(new FileOutputStream(destZip))) {
Path pp = Paths.get(sourceDir.getPath());
Files.walk(pp)
.filter(path -> !Files.isDirectory(path))
.forEach(path -> {
ZipEntry zipEntry = new ZipEntry(pp.relativize(path).toString());
try {
zs.putNextEntry(zipEntry);
Files.copy(path, zs);
zs.closeEntry();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
} catch (Throwable th) {
if (th instanceof RuntimeException && th.getMessage().isEmpty() && th.getCause() != null)
th = th.getCause();
Log.error(th);
return false;
}
return true;
}

public static boolean unzip(File zipFilePath, File destDir) {
if (zipFilePath == null)
return false;
Expand Down

0 comments on commit f9f17fc

Please sign in to comment.