解析java / scala中的7z文件时出现异常

时间:2018-04-01 00:42:51

标签: java scala apache-commons java-io

我编写了一个scala代码来解析7z文件。我正在使用org.apache.commons.compress.archivers.sevenz.SevenZFile来解析它。代码似乎写得很好。下面是解析7z文件的代码片段。

else if(file.endsWith("7z")) {
          val archiveFile:SevenZFile = new SevenZFile(new File(file));
          val contentBytes:ByteArrayOutputStream = new ByteArrayOutputStream();
          val entry = archiveFile.getNextEntry
          if(entry != null) {
            println("7z file in process: " + entry.getName);
            if(entry.isDirectory()) {
            println("Found directory entry: " + entry.getName);
          }
          else {
              val buffer = new Array[Byte](1024);
              while(archiveFile.read(buffer) != -1) {
              contentBytes.write(buffer, 0, archiveFile.read(buffer));
              //println(contentBytes.toString());
              arrayBufferValues += contentBytes.toString();
          }
          println("Done with processing file ====>>>>> " + Paths.get(file).getFileName + " ---- " + entry.getName);
          parseFilesMap.put(Paths.get(file).getFileName + "^" + entry.getName, arrayBufferValues)
          arrayBufferValues.clear();
}

我得到以下异常

java.io.IOException: kDummy is unsupported, please report
at org.apache.commons.compress.archivers.sevenz.SevenZFile.readFilesInfo(SevenZFile.java:710)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.readHeader(SevenZFile.java:241)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.readHeaders(SevenZFile.java:197)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:94)
at org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:116)
at Main$$anonfun$main$1.apply(TestFileProcessZip7z.scala:50)
at Main$$anonfun$main$1.apply(TestFileProcessZip7z.scala:25)
at scala.collection.immutable.List.foreach(List.scala:381)
at Main$.main(TestFileProcessZip7z.scala:25)
at Main.main(TestFileProcessZip7z.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at scala.reflect.internal.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:70)
at scala.reflect.internal.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:101)
at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:70)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:101)
at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:22)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:39)
at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:29)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:39)
at scala.tools.nsc.ScriptRunner.scala$tools$nsc$ScriptRunner$$runCompiled(ScriptRunner.scala:175)
at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:192)
at scala.tools.nsc.ScriptRunner$$anonfun$runScript$1.apply(ScriptRunner.scala:192)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1$$anonfun$apply$mcZ$sp$1.apply(ScriptRunner.scala:161)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply$mcZ$sp(ScriptRunner.scala:161)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129)
at scala.tools.nsc.ScriptRunner$$anonfun$withCompiledScript$1.apply(ScriptRunner.scala:129)
at scala.tools.nsc.util.package$.trackingThreads(package.scala:43)
at scala.tools.nsc.util.package$.waitingForThreads(package.scala:27)
at scala.tools.nsc.ScriptRunner.withCompiledScript(ScriptRunner.scala:128)
at scala.tools.nsc.ScriptRunner.runScript(ScriptRunner.scala:192)
at scala.tools.nsc.ScriptRunner.runScriptAndCatch(ScriptRunner.scala:205)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:67)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:87)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:98)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)

原因是什么,如何解决。谢谢!

1 个答案:

答案 0 :(得分:0)

此异常是由于文件使用bzip2压缩通过7zip压缩而导致的。