Apache jena 将Jena模型写入Tar.Gz档案

Apache jena 将Jena模型写入Tar.Gz档案,apache-jena,apache-commons-compress,Apache Jena,Apache Commons Compress,我目前正在使用RDF模型。因此,我从数据库查询数据,使用ApacheJena生成模型并使用它们。虽然,我不想每次使用模型时都要查询它们,所以我考虑将它们存储在本地。这些模型非常大,所以我想使用ApacheCommonsCompress对它们进行压缩。到目前为止,这是有效的(省略了try catch块): 您不会说从哪里获得NullPointerException。可以添加堆栈跟踪吗?阅读示例中还缺少一个右大括号,可能在模型之后。put@StefanBodewig对不起,我不应该忘记它。你现在可以

我目前正在使用RDF模型。因此,我从数据库查询数据,使用ApacheJena生成模型并使用它们。虽然,我不想每次使用模型时都要查询它们,所以我考虑将它们存储在本地。这些模型非常大,所以我想使用ApacheCommonsCompress对它们进行压缩。到目前为止,这是有效的(省略了try catch块):


您不会说从哪里获得
NullPointerException
。可以添加堆栈跟踪吗?阅读示例中还缺少一个右大括号,可能在
模型之后。put
@StefanBodewig对不起,我不应该忘记它。你现在可以在问题中找到。我以前应该问这个问题的。您使用的是Commons Compress的哪个版本?乍一看,Compress内部的
NullPointerException
听起来更像是您发现了一个bug,应该报告它。我使用的是当前的1.13版。我想,我会在完成我的硕士论文后立即报告这个错误,现在没有时间。谢谢你,StefanBodewig
public static void write(Map<String, Model> models, String file){
   logger.info("Writing models to file " + file); 
   TarArchiveOutputStream tarOutput = null;;
    TarArchiveEntry entry = null;

   tarOutput = new TarArchiveOutputStream(new GzipCompressorOutputStream(new FileOutputStream(new File(file))));
   for(Map.Entry<String, Model> e : models.entrySet()) {
      logger.info("Packing model " + e.getKey());

      // Convert Model
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      RDFDataMgr.write(baos,e.getValue(), RDFFormat.RDFXML_PRETTY);

      // Prepare Entry
      entry = new TarArchiveEntry(e.getKey());
      entry.setSize(baos.size());
      tarOutput.putArchiveEntry(entry);

      // write into file and close
      tarOutput.write(baos.toByteArray());
      tarOutput.closeArchiveEntry();

   }
   tarOutput.close();
}
public static Map<String, Model> read(String file){
   logger.info("Reading models from file " + file);
   Map<String, Model> models = new HashMap<>();


   TarArchiveInputStream tarInput = new TarArchiveInputStream(new GzipCompressorInputStream(new FileInputStream(file)));

   for(TarArchiveEntry currentEntry = tarInput.getNextTarEntry();currentEntry != null; currentEntry= tarInput.getNextTarEntry()){
      logger.info("Processing model " + currentEntry.getName());    

      // Read the current model
      Model m = ModelFactory.createDefaultModel();
      m.read(tarInput, null);

      // And add it to the output
      models.put(currentEntry.getName(),m);

      tarInput.close();
    }   
      return models;
}
Exception in thread "main" java.lang.NullPointerException
    at org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream.read(GzipCompressorInputStream.java:271)
    at java.io.InputStream.skip(InputStream.java:224)
    at org.apache.commons.compress.utils.IOUtils.skip(IOUtils.java:106)
    at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.skipRecordPadding(TarArchiveInputStream.java:345)
    at org.apache.commons.compress.archivers.tar.TarArchiveInputStream.getNextTarEntry(TarArchiveInputStream.java:272)
    at de.mem89.masterthesis.rdfHydra.StorageHelper.read(StorageHelper.java:88)
    at de.mem89.masterthesis.rdfHydra.StorageHelper.main(StorageHelper.java:124)