<?xml version="1.0" encoding="UTF-8"?>
<s:scufl xmlns:s="http://org.embl.ebi.escience/xscufl/0.1alpha" version="0.2" log="0">
  <s:workflowdescription lsid="urn:lsid:net.sf.taverna:wfDefinition:c94dedfd-a757-4234-9f6f-4c0c93eeb7a9" author="" title="file-to-base64" />
  <s:processor name="Encode_byte___to_base64">
    <s:local critical="true">org.embl.ebi.escience.scuflworkers.java.EncodeBase64</s:local>
  </s:processor>
  <s:processor name="File_to_byte_array">
    <s:beanshell critical="true">
      <s:scriptvalue>File f = new File(filename);
if (!f.exists() || !f.canRead() || f.length() == 0)
    throw new Exception("File unreadable or zero length");
if (f.length() &gt; 1000000)
    throw new Exception("File too big to convert to base64");
byte[] bytesArray = new byte[f.length()];
FileInputStream filein = new FileInputStream(filename);
int total = 0;
byte[] buffer = new byte[1000];
int i;
int n = filein.read(buffer);
while (n &gt;= 0) {
    for (i=0; i&lt;n; ++i)
        bytesArray[total + i] = buffer[i];
    total += n;
    n = filein.read(buffer);
}
if (total != f.length())
    throw new Exception("File size does not match amount of data read");
bytes = bytesArray;</s:scriptvalue>
      <s:beanshellinputlist>
        <s:beanshellinput s:syntactictype="'text/plain'">filename</s:beanshellinput>
      </s:beanshellinputlist>
      <s:beanshelloutputlist>
        <s:beanshelloutput s:syntactictype="'application/octet-stream'">bytes</s:beanshelloutput>
      </s:beanshelloutputlist>
      <s:dependencies s:classloader="iteration" />
    </s:beanshell>
  </s:processor>
  <s:link source="FileName" sink="File_to_byte_array:filename" />
  <s:link source="File_to_byte_array:bytes" sink="Encode_byte___to_base64:bytes" />
  <s:link source="Encode_byte___to_base64:base64" sink="Base64String" />
  <s:source name="FileName" />
  <s:sink name="Base64String" />
</s:scufl>

