Example #1
0
 /**
  * Prepare a Research Object to be sent as a package in a zip format to dArceo.
  *
  * @param researchObject Research Object
  * @return input stream with zipped ro.
  * @throws IOException
  */
 public static InputStream toZipInputStream(ResearchObjectSerializable researchObject) {
   File tmpFile = null;
   Set<String> entries = new HashSet<>();
   try {
     tmpFile = File.createTempFile("dArceoArtefact", ".zip");
     tmpFile.deleteOnExit();
     ZipOutputStream zipOutput = new ZipOutputStream(new FileOutputStream(tmpFile));
     for (ResearchObjectComponentSerializable component :
         researchObject.getSerializables().values()) {
       Path componentPath = Paths.get(CONTENT_PATH, component.getPath());
       putEntryAndDirectoriesPath(
           zipOutput, componentPath.toString(), component.getSerialization(), entries);
     }
     // add metadata
     putMetadataId(zipOutput, entries, researchObject.getUri());
     zipOutput.flush();
     zipOutput.close();
     InputStream result = new FileInputStream(tmpFile);
     tmpFile.delete();
     return result;
   } catch (IOException e) {
     LOGGER.error("Can't prepare a RO " + researchObject.getUri() + " for dArceo", e);
     if (tmpFile != null) {
       tmpFile.delete();
     }
     return null;
   }
 }
Example #2
0
 @Test
 public void testZipInputStreamToResearchObject() {
   URI id = URI.create("http://www.example.com/ROs/simple/");
   ResearchObjectSerializable ro =
       IO.toResearchObject(id, getClass().getClassLoader().getResourceAsStream("simple.zip"));
   // check the content of the returned ro
   for (ResearchObjectComponentSerializable component : ro.getSerializables().values()) {
     System.out.println(component.getUri());
   }
   Assert.assertNotNull(ro.getSerializables().get(id.resolve("1.txt")));
   Assert.assertNotNull(ro.getSerializables().get(id.resolve("2.txt")));
   Assert.assertNotNull(ro.getSerializables().get(id.resolve(".ro/manifest.rdf")));
   Assert.assertNotNull(ro.getSerializables().get(id.resolve(".ro/evo_info.ttl")));
 }