Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1033735 // Zip2Zip_b - should merge with Zip2Zip

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5058L/28K).

1  
sclass Zip2Zip_b {
2  
  // must set
3  
  File inZip;
4  
  ZipOutputStream outZip;
5  
  new Set<S> filesWritten;
6  
  
7  
  // optional
8  
  IPred<S> predicate;
9  
  
10  
  *(File *inZip, ZipOutputStream *outZip, Set<S> *filesWritten) {}
11  
  *(ZipOutputStream *outZip) {}
12  
  
13  
  run {
14  
    ZipFile zipFile = new ZipFile(inZip);
15  
    try {
16  
      Enumeration entries = zipFile.entries();
17  
      while (entries.hasMoreElements()) {
18  
        ZipEntry entry = (ZipEntry) entries.nextElement();
19  
        if (entry.isDirectory()) continue;
20  
        S name = entry.getName();
21  
        
22  
        if (predicate != null && !predicate.get(name)) continue;
23  
        if (!filesWritten.add(name)) continue;
24  
        
25  
        modifyZipEntry(entry);
26  
        outZip.putNextEntry(entry);
27  
        copyStreamAndCloseInput(zipFile.getInputStream(entry), outZip);
28  
      }
29  
    } finally {
30  
      zipFile.close();
31  
    }
32  
  }
33  
  
34  
  swappable void modifyZipEntry(ZipEntry e) {}
35  
}

Author comment

Began life as a copy of #1033332

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1033735
Snippet name: Zip2Zip_b - should merge with Zip2Zip
Eternal ID of this version: #1033735/11
Text MD5: ba3484a64e962b5d341aece5ce0fca36
Transpilation MD5: a67042168445ea7b3c9930a3b216a7a1
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-03 07:17:13
Source code size: 940 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 102 / 185
Version history: 10 change(s)
Referenced in: [show references]