in taverna-external-tool-activity/src/main/java/org/apache/taverna/activities/externaltool/local/LocalToolInvocation.java [373:460]
public HashMap<String, Object> submit_wait_fetch_results(ReferenceService referenceService) throws InvocationException {
ByteArrayOutputStream stdout_buf = new ByteArrayOutputStream();
ByteArrayOutputStream stderr_buf = new ByteArrayOutputStream();
while (true) {
try {
copy_stream(running.getInputStream(), stdout_buf);
copy_stream(running.getErrorStream(), stderr_buf);
} catch (IOException e1) {
throw new InvocationException(e1);
}
try {
int exitcode = running.exitValue();
if (!usecase.getValidReturnCodes().contains(exitcode)) {
try {
throw new InvocationException("Invalid exit code " + exitcode + ":" + stderr_buf.toString("US-ASCII"));
} catch (UnsupportedEncodingException e) {
throw new InvocationException("Invalid exit code " + exitcode + ":" + stderr_buf.toString());
}
}
else
break;
} catch (IllegalThreadStateException e) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
throw new InvocationException(e);
}
}
}
HashMap<String, Object> results = new HashMap<String, Object>();
results.put("STDOUT", stdout_buf.toByteArray());
results.put("STDERR", stderr_buf.toByteArray());
for (Map.Entry<String, ScriptOutput> cur : usecase.getOutputs().entrySet()) {
ScriptOutput scriptOutput = cur.getValue();
File result = new File(tempDir.getAbsoluteFile() + "/" + cur.getValue().getPath());
if (result.exists()) {
AbstractExternalReference ref;
if (isRetrieveData()) {
FileInputStream is;
try {
is = new FileInputStream(result);
} catch (FileNotFoundException e) {
throw new InvocationException(e);
}
if (scriptOutput.isBinary()) {
ref = inlineByteArrayReferenceBuilder.createReference(is, null);
} else {
ref = inlineStringReferenceBuilder.createReference(is, null);
}
try {
is.close();
} catch (IOException e) {
throw new InvocationException(e);
}
}
else {
ref = new FileReference(result);
if (scriptOutput.isBinary()) {
((FileReference) ref)
.setDataNature(ReferencedDataNature.BINARY);
} else {
((FileReference) ref)
.setDataNature(ReferencedDataNature.TEXT);
((FileReference) ref).setCharset("UTF-8");
}
}
results.put(cur.getKey(), ref);
} else {
ErrorDocument ed = referenceService.getErrorDocumentService().registerError("No result for " + cur.getKey(), 0, getContext());
results.put(cur.getKey(), ed);
}
}
if (isRetrieveData()) {
forgetRun();
try {
deleteDirectory(tempDir.getCanonicalPath());
} catch (IOException e) {
throw new InvocationException(e);
}
}
return results;
}