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).

sclass Zip2Zip_b {
  // must set
  File inZip;
  ZipOutputStream outZip;
  new Set<S> filesWritten;
  
  // optional
  IPred<S> predicate;
  
  *(File *inZip, ZipOutputStream *outZip, Set<S> *filesWritten) {}
  *(ZipOutputStream *outZip) {}
  
  run {
    ZipFile zipFile = new ZipFile(inZip);
    try {
      Enumeration entries = zipFile.entries();
      while (entries.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (entry.isDirectory()) continue;
        S name = entry.getName();
        
        if (predicate != null && !predicate.get(name)) continue;
        if (!filesWritten.add(name)) continue;
        
        modifyZipEntry(entry);
        outZip.putNextEntry(entry);
        copyStreamAndCloseInput(zipFile.getInputStream(entry), outZip);
      }
    } finally {
      zipFile.close();
    }
  }
  
  swappable void modifyZipEntry(ZipEntry e) {}
}

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: 99 / 180
Version history: 10 change(s)
Referenced in: [show references]