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

39
LINES

< > BotCompany Repo | #1024958 // zip2tar_withPredicate

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

Uses 578K of libraries. Click here for Pure Java version (2207L/14K).

1  
!include once #1024944 // Apache Commons Compress
2  
3  
import org.apache.commons.compress.archivers.tar.*;
4  
5  
svoid zip2tar_withPredicate(File inZip, File outTar, IF1<S, Bool> predicate) ctex {
6  
  temp FileOutputStream out = newFileOutputStream(outTar);
7  
  zip2tar_withPredicate(inZip, out, predicate);
8  
}
9  
10  
svoid zip2tar_withPredicate(File inZip, OutputStream out, IF1<S, Bool> predicate) {
11  
  zip2tar_withPredicate(inZip, bufferedOutputStream(out), predicate);
12  
}
13  
14  
svoid zip2tar_withPredicate(File inZip, BufferedOutputStream out, IF1<S, Bool> predicate) ctex {
15  
  TarArchiveOutputStream tarOut = new(out);
16  
  tarOut.setLongFileMode(tarOut.LONGFILE_GNU);
17  
  zip2tar_withPredicate(inZip, tarOut, predicate);
18  
  out.flush();
19  
}
20  
21  
svoid zip2tar_withPredicate(File inZip, TarArchiveOutputStream outTar, IF1<S, Bool> predicate) ctex {
22  
  ZipFile zipFile = new ZipFile(inZip);
23  
  Enumeration entries = zipFile.entries();
24  
  while (entries.hasMoreElements()) {
25  
    ZipEntry entry = (ZipEntry) entries.nextElement(); 
26  
    continue unless predicate.get(entry.getName());
27  
    
28  
    TarArchiveEntry te = new(entry.getName());
29  
    te.setModTime(entry.getTime());
30  
    te.setSize(entry.getSize());
31  
    outTar.putArchiveEntry(te);
32  
33  
    InputStream fin = zipFile.getInputStream(entry);
34  
    copyStream(fin, outTar);
35  
    fin.close();
36  
  }
37  
  outTar.flush();
38  
  zipFile.close();
39  
}

Author comment

Began life as a copy of #1024945

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1024958
Snippet name: zip2tar_withPredicate
Eternal ID of this version: #1024958/1
Text MD5: 7aad144cf2b7ce1ab279998fa657e5ab
Transpilation MD5: babcd9da8d36048ecf4db185d74a6e5c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-31 16:32:25
Source code size: 1378 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 193 / 276
Referenced in: [show references]