MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / addToZip

Method addToZip

java/src/org/openqa/selenium/io/Zip.java:58–88  ·  view source on GitHub ↗
(String basePath, ZipOutputStream zos, File toAdd)

Source from the content-addressed store, hash-verified

56 }
57
58 private static void addToZip(String basePath, ZipOutputStream zos, File toAdd)
59 throws IOException {
60 Path dirPath = toAdd.toPath();
61
62 if (Files.isDirectory(dirPath)) {
63 try (DirectoryStream<Path> stream = Files.newDirectoryStream(dirPath)) {
64 for (Path path : stream) {
65 addToZip(basePath, zos, path.toFile());
66 }
67 } catch (IOException e) {
68 LOG.warning(() -> String.format("Failed to read directory %s for zipping: %s", toAdd, e));
69 }
70 } else {
71 try (FileInputStream fis = new FileInputStream(toAdd)) {
72 String name = toAdd.getAbsolutePath().substring(basePath.length() + 1);
73
74 ZipEntry entry = new ZipEntry(name.replace('\\', '/'));
75 entry.setTime(toAdd.lastModified());
76 entry.setLastModifiedTime(FileTime.fromMillis(toAdd.lastModified()));
77 zos.putNextEntry(entry);
78
79 int len;
80 byte[] buffer = new byte[4096];
81 while ((len = fis.read(buffer)) != -1) {
82 zos.write(buffer, 0, len);
83 }
84
85 zos.closeEntry();
86 }
87 }
88 }
89
90 public static File unzipToTempDir(String source, String prefix, String suffix)
91 throws IOException {

Callers 1

zipMethod · 0.95

Calls 6

warningMethod · 0.80
isDirectoryMethod · 0.65
lengthMethod · 0.65
readMethod · 0.65
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected