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

39
LINES

< > BotCompany Repo | #1024945 // zip2tar

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

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

!include once #1024944 // Apache Commons Compress

import org.apache.commons.compress.archivers.tar.*;

svoid zip2tar(File inZip, File outTar) ctex {
  temp FileOutputStream out = newFileOutputStream(outTar);
  zip2tar(inZip, out);
}

svoid zip2tar(File inZip, OutputStream out) {
  zip2tar(inZip, bufferedOutputStream(out));
}

svoid zip2tar(File inZip, BufferedOutputStream out) ctex {
  TarArchiveOutputStream tarOut = new(out);
  tarOut.setLongFileMode(tarOut.LONGFILE_GNU);
  zip2tar(inZip, tarOut);
  out.flush();
}

svoid zip2tar(File inZip, TarArchiveOutputStream outTar) ctex {
  ZipFile zipFile = new ZipFile(inZip);
  Enumeration entries = zipFile.entries();
  while (entries.hasMoreElements()) {
    ZipEntry entry = (ZipEntry) entries.nextElement(); 
    //System.out.println("Copying " + entry.getName());
    TarArchiveEntry te = new(entry.getName());
    te.setModTime(entry.getTime());
    te.setSize(entry.getSize());
    outTar.putArchiveEntry(te);

    InputStream fin = zipFile.getInputStream(entry);
    copyStream(fin, outTar);
    fin.close();
    outTar.closeArchiveEntry();
  }
  outTar.flush();
  zipFile.close();
}

Author comment

Began life as a copy of #1001173

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1024945
Snippet name: zip2tar
Eternal ID of this version: #1024945/23
Text MD5: b7e65eb98c796021ae5c39a040785752
Transpilation MD5: f9d7720711c4fc8b81dff9208b923aa2
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-05-26 22:18:45
Source code size: 1180 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 274 / 438
Version history: 22 change(s)
Referenced in: [show references]