WorkflowBundleIO { public WorkflowBundle readBundle(File bundleFile, String mediaType) throws ReaderException, IOException { if (mediaType == null) { byte[] firstBytes = new byte[FIRST_BYTES]; try (FileInputStream fileIn = new FileInputStream(bundleFile)) { fileIn.read(firstBytes); } mediaType = guessMediaTypeForSignature(firstBytes); } WorkflowBundleReader reader = getReaderForMediaType(mediaType); if (reader == null) { if (mediaType == null) throw new IllegalArgumentException( "Could not guess media type for " + bundleFile); throw new IllegalArgumentException( "Could not find reader for media type " + mediaType); } return reader.readBundle(bundleFile, mediaType); }  WorkflowBundleReader getReaderForMediaType(String mediaType); List<WorkflowBundleReader> getReaders(); Set<String> getSupportedReaderMediaTypes(); Set<String> getSupportedWriterMediaTypes(); WorkflowBundleWriter getWriterForMediaType(String mediaType); List<WorkflowBundleWriter> getWriters(); String guessMediaTypeForSignature(byte[] firstBytes); WorkflowBundle readBundle(File bundleFile, String mediaType); WorkflowBundle readBundle(InputStream inputStream, String mediaType); WorkflowBundle readBundle(URL url, String mediaType); void setReaders(List<WorkflowBundleReader> readers); void setWriters(List<WorkflowBundleWriter> writers); void writeBundle(WorkflowBundle wfBundle, File destination,
			String mediaType); void writeBundle(WorkflowBundle wfBundle, OutputStream output,
			String mediaType); WorkflowBundle createBundle();  }
@Test public void readBundleFile() throws Exception { File bundleFile = tempFile(); FileUtils.writeStringToFile(bundleFile, getStructureFormatWorkflowBundle(), UTF_8); WorkflowBundle wfBundle = bundleIO.readBundle(bundleFile, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); assertEquals("HelloWorld", wfBundle.getName()); assertEquals("HelloWorld", wfBundle.getMainWorkflow().getName()); assertTrue(wfBundle.getMainWorkflow().getProcessors() .containsName("Hello")); }
@Test public void readBundleFileNoMediaType() throws Exception { File bundleFile = tempFile(); FileUtils.writeStringToFile(bundleFile, getStructureFormatWorkflowBundle(), UTF_8); WorkflowBundle wfBundle = bundleIO.readBundle(bundleFile,null); assertNotNull(wfBundle); File emptyFile = File.createTempFile("test", "txt"); try { @SuppressWarnings("unused") WorkflowBundle none = bundleIO.readBundle(emptyFile,null); fail("Should throw IllegalArgumentException for unrecognized file"); } catch (IllegalArgumentException ex) { } }
@Test public void readBundleStream() throws Exception { InputStream inputStream = new ByteArrayInputStream( getStructureFormatWorkflowBundle().getBytes("utf-8")); WorkflowBundle wfBundle = bundleIO.readBundle(inputStream, TEXT_VND_TAVERNA_SCUFL2_STRUCTURE); assertEquals("HelloWorld", wfBundle.getName()); assertEquals("HelloWorld", wfBundle.getMainWorkflow().getName()); assertTrue(wfBundle.getMainWorkflow().getProcessors() .containsName("Hello")); }
@Test public void readBundleStreamNoMediaType() throws Exception { InputStream inputStream = new ByteArrayInputStream( getStructureFormatWorkflowBundle().getBytes("utf-8")); WorkflowBundle wfBundle = bundleIO.readBundle(inputStream, null); assertNotNull(wfBundle); assertEquals("HelloWorld", wfBundle.getName()); }