3
我正在開發一個軟件,它將從tar.gz文件中獲取信息,並使用Apache commons-compress lib。但我發現了以下錯誤:Apache Commons壓縮:打開.tar.gz
Caused by: java.lang.IllegalArgumentException: Invalid byte 4 at offset 0 in 'O�!�C' len=8
at org.apache.commons.compress.archivers.tar.TarUtils.parseOctal(TarUtils.java:134)
at org.apache.commons.compress.archivers.tar.TarUtils.parseOctalOrBinary(TarUtils.java:166)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:953)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.parseTarHeader(TarArchiveEntry.java:940)
at org.apache.commons.compress.archivers.tar.TarArchiveEntry.<init>(TarArchiveEntry.java:324)
at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:274)
... 2 more
使用的樣品tar.gz文件是Eclipse的JEE-月神-SR1-Linux的GTK的x86_64.tar.gz
這裏是類使用lib:
public class TarGzBuildAdapter extends BuildAdapter {
public TarGzBuildAdapter(File build) {
super(build);
}
@Override
public List<ArtifactInfo> getArtifactInfos() throws IOException {
TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(
new FileInputStream(this.build));
TarArchiveEntry tarArchiveEntry;
List<ArtifactInfo> artifactInfos = new LinkedList<ArtifactInfo>();
while ((tarArchiveEntry = tarArchiveInputStream.getNextTarEntry()) != null) {
System.out.println(String.format("Name: %s LinkName: %s Size: %Ld RealSize: %Ld",
tarArchiveEntry.getName(), tarArchiveEntry.getLinkName(),
tarArchiveEntry.getSize(), tarArchiveEntry.getRealSize()));
artifactInfos.add(new ArtifactInfo(tarArchiveEntry.getName(), tarArchiveEntry
.getRealSize()));
}
tarArchiveInputStream.close();
return artifactInfos;
}
}
要獲得任何有意義的答案,您必須提供您使用commons-compress編寫的代碼。 – PaulProgrammer 2015-01-26 20:29:02
我敢打賭,這個錯誤是在你的代碼中,而不是在Apache Commons中 – m0skit0 2015-01-26 20:29:41
你使用的是什麼版本的Apache commons壓縮庫 - 它是1.3嗎? – Sigismundus 2015-01-26 20:31:38