gpt4 book ai didi

org.apache.taverna.scufl2.api.io.WorkflowBundleIO.writeBundle()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 09:23:05 28 4
gpt4 key购买 nike

本文整理了Java中org.apache.taverna.scufl2.api.io.WorkflowBundleIO.writeBundle()方法的一些代码示例,展示了WorkflowBundleIO.writeBundle()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WorkflowBundleIO.writeBundle()方法的具体详情如下:
包路径:org.apache.taverna.scufl2.api.io.WorkflowBundleIO
类名称:WorkflowBundleIO
方法名:writeBundle

WorkflowBundleIO.writeBundle介绍

[英]Write a WorkflowBundle to a file with specified media type.

Scufl2Tools#setParents(WorkflowBundle) will be called on the bundle to ensure everything contained by the bundle has it as an ancestor.
[中]将WorkflowBundle写入具有指定媒体类型的文件。
Scufl2Tools#setParents(WorkflowBundle)将在包上被调用,以确保包中包含的所有内容都将其作为祖先。

代码示例

代码示例来源:origin: org.apache.taverna.language/taverna-databundle

public static void setWorkflowBundle(Bundle dataBundle,
    WorkflowBundle wfBundle) throws IOException {
  Path bundlePath = withExtension(getWorkflow(dataBundle), DOT_WFBUNDLE);
  checkExistingAnyExtension(bundlePath);
  // TODO: Save as nested folder?
  try (OutputStream outputStream = newOutputStream(bundlePath)) {
    getWfBundleIO().writeBundle(wfBundle, outputStream,
        WFBUNDLE_CONTENT_TYPE);
  } catch (WriterException e) {
    throw new IOException("Can't write workflow bundle to: "
        + bundlePath, e);
  }
  // wfdesc
  Path wfdescPath = getWorkflowDescription(dataBundle);
  try (OutputStream outputStream = newOutputStream(wfdescPath)) {
    getWfBundleIO().writeBundle(wfBundle, outputStream, WFDESC_TURTLE);
  } catch (IllegalArgumentException | WriterException e) {
    logger.warn("Can't write wfdesc to: " + bundlePath, e);
    delete(wfdescPath);
    // throw new IOException("Can't write wfdesc to: " + bundlePath, e);
  }
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test(expected = IOException.class)
public void writeBundleWrongLocation() throws Exception {
  File bundleDir = tempFile();
  bundleDir.delete();
  File bundleFile = new File(bundleDir, "nonExistingDir");
  bundleIO.writeBundle(wfBundle, bundleFile,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void writeBundleStream() throws Exception {
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  bundleIO.writeBundle(wfBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  String bundleTxt = new String(output.toByteArray(), UTF_8);
      String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle();
      bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", "");
      getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(getStructureFormatWorkflowBundle, bundleTxt);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void writeBundleFile() throws Exception {
  File bundleFile = tempFile();
  bundleIO.writeBundle(wfBundle, bundleFile,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  String bundleTxt = FileUtils.readFileToString(bundleFile, UTF_8);
      String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle();
      bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", "");
      getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(getStructureFormatWorkflowBundle, bundleTxt);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void readToWriteRoundTrip() throws Exception {
  InputStream inputStream = new ByteArrayInputStream(
      getStructureFormatWorkflowBundle().getBytes("utf-8"));
  WorkflowBundle readBundle = bundleIO.readBundle(inputStream,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  bundleIO.writeBundle(readBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  String bundleTxt = new String(output.toByteArray(), UTF_8);
      String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle();
      bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", "");
      getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(getStructureFormatWorkflowBundle, bundleTxt);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Test
public void writeBundleToStream() throws Exception {
  ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  bundleIO.writeBundle(workflowBundle, outStream,
      APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
  outStream.close();
  InputStream inStream = new ByteArrayInputStream(outStream.toByteArray());
  UCFPackage ucfPackage;
  try {
    // Avoid UCFPackage from creating a temporary file
    System.setProperty("org.odftoolkit.odfdom.tmpfile.disable", "true");
    ucfPackage = new UCFPackage(inStream);
  } finally {
    System.clearProperty("org.odftoolkit.odfdom.tmpfile.disable");
  }
  verifyPackageStructure(ucfPackage);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test(expected = IllegalArgumentException.class)
public void writeBundleUnknownMediaType() throws Exception {
  File bundleFile = tempFile();
  bundleIO.writeBundle(wfBundle, bundleFile,
  "application/vnd.example.unknownStuff");
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Ignore
@Test
public void testParsedWorkflow() throws Exception {
  assertEquals("HelloWorld", workflowBundle.getName());
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  bundleIO.writeBundle(workflowBundle, output,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  String bundleTxt = new String(output.toByteArray(), "UTF-8");
  assertEquals(testWorkflowBundleIO.getStructureFormatWorkflowBundle(),
      bundleTxt);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-t2flow

@Test
public void readSimpleWorkflow() throws Exception {
  URL wfResource = getClass().getResource(AS_T2FLOW);
  assertNotNull("Could not find workflow " + AS_T2FLOW, wfResource);
  WorkflowBundle wfBundle = io.readBundle(wfResource,
      APPLICATION_VND_TAVERNA_T2FLOW_XML);
  Profile profile = wfBundle.getMainProfile();
  assertEquals(1, wfBundle.getProfiles().size());
  assertEquals(profile,
      wfBundle.getProfiles().getByName("taverna-2.1.0"));
  
  String report = IOUtils.toString(getClass().getResourceAsStream("/as.txt"));
  ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
  io.writeBundle(wfBundle, byteStream, StructureReader.TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
      String byteStreamTtoString = byteStream.toString("utf-8");
      report = report.replaceAll("\r", "").replaceAll("\n", "");
      byteStreamTtoString = byteStreamTtoString.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(report, byteStreamTtoString);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-t2flow

@Test
  public void readSemanticAnnotations() throws Exception {
    URL wfResource = getClass().getResource(SEMANTIC_ANNOTATIONS);
    assertNotNull("Could not find workflow " + SEMANTIC_ANNOTATIONS, wfResource);
    T2FlowParser parser = new T2FlowParser();
    parser.setValidating(true);
    parser.setStrict(false);
    WorkflowBundle wfBundle = parser.parseT2Flow(wfResource.openStream());
    assertEquals(4, wfBundle.getAnnotations().size());
    for (Annotation x : wfBundle.getAnnotations()) {
      System.out.println(x.getTarget());
//            System.out.println(x.getBodyStatements().get(0));
    }
    File f = File.createTempFile("annotation", ".wfbundle");
    System.err.println(f);
    new WorkflowBundleIO().writeBundle(wfBundle, f, "application/vnd.taverna.scufl2.workflow-bundle");
  }

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Test
public void writeBundleToFile() throws Exception {
  File bundleFile = tempFile();
  bundleIO.writeBundle(workflowBundle, bundleFile,
      APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
  UCFPackage ucfPackage = new UCFPackage(bundleFile);
  verifyRootFile(ucfPackage);
  verifyPackageStructure(ucfPackage);
  // TODO: Check RDF/XML using xpath
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Test
public void differentMediaType() throws Exception {
  UCFPackage resources = originalBundle.getResources();
  resources.setPackageMediaType("application/x-something-else");
  assertEquals("application/x-something-else", resources.getPackageMediaType());
  
  resources.addResource("Hello there", "hello.txt", "text/plain");
  File bundleFile = tempFile();
  bundleIO.writeBundle(originalBundle, bundleFile, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
  assertEquals("application/x-something-else", resources.getPackageMediaType());
  assertEquals(0, resources.getRootFiles().size());
  // RDFXMLWriter does not touch the rootFile or media type if it's non-null
  
  ZipFile zipFile = new ZipFile(bundleFile);
  ZipEntry hello = zipFile.getEntry("hello.txt");
  assertEquals("hello.txt", hello.getName());
  assertEquals("Hello there",
      IOUtils.toString(zipFile.getInputStream(hello), "ASCII"));		
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Test
public void singleFile() throws Exception {
  UCFPackage resources = originalBundle.getResources();
  assertEquals(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE, resources.getPackageMediaType());
  resources.addResource("Hello there", "hello.txt", "text/plain");
  File bundleFile = tempFile();
  bundleIO.writeBundle(originalBundle, bundleFile, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);		
  assertEquals(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE, resources.getPackageMediaType());
  assertEquals(1, resources.getRootFiles().size());
  assertEquals("workflowBundle.rdf", resources.getRootFiles().get(0).getPath());
  
  ZipFile zipFile = new ZipFile(bundleFile);
  ZipEntry hello = zipFile.getEntry("hello.txt");
  assertEquals("hello.txt", hello.getName());
  assertEquals("Hello there",
      IOUtils.toString(zipFile.getInputStream(hello), "ASCII"));		
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Test
public void configurationReadTwice() throws Exception {
  InputStream inputStream = new ByteArrayInputStream(
      getStructureFormatWorkflowBundle().getBytes("utf-8"));
  WorkflowBundle readBundle = bundleIO.readBundle(inputStream,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  assertEquals(1, readBundle.getMainProfile().getConfigurations().size());
  new Scufl2Tools().setParents(readBundle);
  assertEquals(1, readBundle.getMainProfile().getConfigurations().size());
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  bundleIO.writeBundle(readBundle, output, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  assertEquals(1, readBundle.getMainProfile().getConfigurations().size());
  String bundleTxt = new String(output.toByteArray(), UTF_8);
      String getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle();
      bundleTxt = bundleTxt.replaceAll("\r", "").replaceAll("\n", "");
      getStructureFormatWorkflowBundle = getStructureFormatWorkflowBundle.replaceAll("\r", "").replaceAll("\n", "");
  assertEquals(getStructureFormatWorkflowBundle, bundleTxt);
  
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-wfbundle

@Test
public void awkwardFilenames() throws Exception {
  workflowBundle.getProfiles().removeByName("tavernaServer");
  String funnyName = "Funny_%2f_characters_50%_of the time";
  workflowBundle.getMainProfile().setName(funnyName);        
  workflowBundle.getMainWorkflow().setName(funnyName);
  File bundleFile = tempFile();
  bundleIO.writeBundle(workflowBundle, bundleFile,
      APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
  UCFPackage ucfPackage = new UCFPackage(bundleFile);
  Map<String, ResourceEntry> profiles = ucfPackage.listResources("profile");
  assertEquals(2, profiles.size());
  assertTrue(profiles.keySet().contains("Funny_%252f_characters_50%25_of%20the%20time.rdf"));
  assertTrue(profiles.keySet().contains("Funny_%252f_characters_50%25_of%20the%20time/"));
  
  Map<String, ResourceEntry> workflows = ucfPackage.listResources("workflow");
  assertEquals(1, workflows.size());
  assertEquals("Funny_%252f_characters_50%25_of%20the%20time.rdf", workflows.keySet().iterator().next());
  
  // and.. can we read it in again correctly?
  WorkflowBundle readBundle = bundleIO.readBundle(bundleFile, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE);
  assertEquals(funnyName, readBundle.getMainProfile().getName());
  assertEquals(funnyName, readBundle.getMainWorkflow().getName());
  // did the JSON parse back in?
  JsonNode oldJson = workflowBundle.getMainProfile().getConfigurations().getByName("Hello").getJson();
  assertTrue(oldJson.get("script").asText().startsWith("hello"));           
  JsonNode newJson = readBundle.getMainProfile().getConfigurations().getByName("Hello").getJson();
  assertTrue(newJson.get("script").asText().startsWith("hello"));        
  assertEquals(oldJson, newJson);
}

代码示例来源:origin: org.apache.taverna.language/taverna-scufl2-api

@Ignore
@Test
public void writeBundleFileSetParents() throws Exception {
  File bundleFile = tempFile();
  // Deliberately orphan a profile and a processor
  Profile profile = wfBundle.getProfiles().getByName("tavernaWorkbench");
  profile.setParent(null);        
  wfBundle.getProfiles().add(profile);        
  processor.setParent(null);
  workflow.getProcessors().add(processor);        
  
  assertNull(processor.getParent());
  assertNull(profile.getParent());        
  bundleIO.writeBundle(wfBundle, bundleFile,
      TEXT_VND_TAVERNA_SCUFL2_STRUCTURE);
  assertNotNull(processor.getParent());
  assertNotNull(profile.getParent());                
  String bundleTxt = FileUtils.readFileToString(bundleFile, UTF_8);
  assertTrue(bundleTxt.contains("Processor 'Hello'"));
  assertTrue(bundleTxt.contains("Profile 'tavernaWorkbench'"));		
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com