RDFXMLReader implements WorkflowBundleReader { @Override public String guessMediaTypeForSignature(byte[] firstBytes) { if (firstBytes.length < 100) return null; Charset latin1 = Charset.forName("ISO-8859-1"); String pk = new String(firstBytes, 0, 2, latin1); if (!pk.equals("PK")) return null; String mimetype = new String(firstBytes, 30, 8, latin1); if (!mimetype.equals("mimetype")) return null; String bundle = new String(firstBytes, 38, APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE.length(), latin1); if (!bundle.equals(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE)) return null; return APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE; }  @Override Set<String> getMediaTypes(); @Override WorkflowBundle readBundle(File bundleFile, String mediaType); @Override WorkflowBundle readBundle(InputStream inputStream, String mediaType); @Override String guessMediaTypeForSignature(byte[] firstBytes); static final String APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE; static final String APPLICATION_RDF_XML; }
@Test public void guessMediaType() throws Exception { byte[] firstBytes = new byte[1024]; getClass().getResourceAsStream(EXAMPLE_SCUFL2).read(firstBytes); assertEquals(APPLICATION_VND_TAVERNA_SCUFL2_WORKFLOW_BUNDLE, bundleIO.guessMediaTypeForSignature(firstBytes)); firstBytes[45] = 32; assertEquals(null, bundleIO.guessMediaTypeForSignature(firstBytes)); }