java - Apache commons untar: IllegalArgumentException with getNextTarEntry -


i having problem compress apache library. untar archive contains binary files. here code:

import java.io.bufferedinputstream; import java.io.bufferedoutputstream; import java.io.file; import java.io.fileinputstream; import java.io.fileoutputstream; import java.io.ioexception;  import org.apache.commons.compress.archivers.tar.tararchiveentry; import org.apache.commons.compress.archivers.tar.tararchiveinputstream;  public class archivemanager {      public static final int buffer_max = 2048;      public static void untar(string filename, string targetpath) throws ioexception {         file tararchivefile = new file(filename);         bufferedoutputstream dest = null;         fileinputstream tararchivestream = new fileinputstream(tararchivefile);         tararchiveinputstream tis = new tararchiveinputstream(new bufferedinputstream(tararchivestream));         tararchiveentry entry = null;         try {             while ((entry = tis.getnexttarentry()) != null) {                 int count;                 file outputfile = new file(targetpath, entry.getname());                  if (entry.isdirectory()) { // entry directory                     if (!outputfile.exists()) {                         outputfile.mkdirs();                     }                 } else { // entry file                     byte[] data = new byte[buffer_max];                     fileoutputstream fos = new fileoutputstream(outputfile);                     dest = new bufferedoutputstream(fos, buffer_max);                     while ((count = tis.read(data, 0, buffer_max)) != -1) {                         dest.write(data, 0, count);                     }                     dest.flush();                     dest.close();                 }             }         } catch(exception e) {             e.printstacktrace();         } {             if (dest != null) {                 dest.flush();                 dest.close();             }             tis.close();         }     } } 

when untaring binary files, getnexttarentry() throws exception:

java.lang.illegalargumentexception: invalid byte 111 @ offset 0 in 'o.txt{nul}{nul}{nul}' len=8     @ org.apache.commons.compress.archivers.tar.tarutils.parseoctal(tarutils.java:99)     @ org.apache.commons.compress.archivers.tar.tararchiveentry.parsetarheader(tararchiveentry.java:786)     @ org.apache.commons.compress.archivers.tar.tararchiveentry.<init>(tararchiveentry.java:308)     @ org.apache.commons.compress.archivers.tar.tararchiveinputstream.getnexttarentry(tararchiveinputstream.java:198)     @ com.airbus.pakito.download.archivemanager.untar(archivemanager.java:22) 

i tried untar simple text files. after having untared last file, getnexttarentry() not return null object empty fileds. entry.getname() empty , new fileoutputstream(outputfile) cannot create file.

java.io.filenotfoundexception: c:\temp (accès refusé)     @ java.io.fileoutputstream.open(native method)     @ java.io.fileoutputstream.<init>(unknown source)     @ java.io.fileoutputstream.<init>(unknown source)     @ com.airbus.pakito.util.archive.untar(archive.java:32) 

do have idea problem comes from?

thanks.

i found out problem comes from.

this a known bug fixed in 1.4 release of apache compress. hope release available soon.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -