in taverna-external-tool-activity/src/main/java/org/apache/taverna/activities/externaltool/local/LocalToolInvocation.java [196:293]
public String setOneInput(ReferenceService referenceService,
T2Reference t2Reference, ScriptInput input)
throws InvocationException {
if (input.getCharsetName() == null) {
input.setCharsetName(Charset.defaultCharset().name());
}
String target = null;
String targetSuffix = null;
if (input.isFile()) {
targetSuffix = input.getTag();
} else if (input.isTempFile()) {
targetSuffix = "tempfile." + (nTempFiles++) + ".tmp";
}
if (input.isBinary()) {
return setOneBinaryInput(referenceService, t2Reference, input,
targetSuffix);
}
logger.info("Target is " + target);
if (input.isFile() || input.isTempFile()) {
target = tempDir.getAbsolutePath() + "/" + targetSuffix;
// Try to get it as a file
Reader r;
Writer w;
FileReference fileRef = getAsFileReference(referenceService,
t2Reference);
if (fileRef != null) {
if (!input.isForceCopy()) {
if (linkCommand != null) {
String source = fileRef.getFile().getAbsolutePath();
String actualLinkCommand = getActualOsCommand(
linkCommand, source, targetSuffix, target);
logger.info("Link command is " + actualLinkCommand);
String[] splitCmds = actualLinkCommand.split(" ");
ProcessBuilder builder = new ProcessBuilder(splitCmds);
builder.directory(tempDir);
try {
int code = builder.start().waitFor();
if (code == 0) {
return target;
} else {
logger.error("Link command gave errorcode: "
+ code);
}
} catch (InterruptedException e) {
// go through
} catch (IOException e) {
// go through
}
}
}
if (fileRef.getDataNature().equals(ReferencedDataNature.TEXT)) {
r = new InputStreamReader(fileRef.openStream(this
.getContext()), Charset.forName(fileRef
.getCharset()));
} else {
try {
r = new FileReader(fileRef.getFile());
} catch (FileNotFoundException e) {
throw new InvocationException(e);
}
}
} else {
r = new InputStreamReader(getAsStream(referenceService,
t2Reference));
}
try {
w = new OutputStreamWriter(new FileOutputStream(target), input
.getCharsetName());
} catch (UnsupportedEncodingException e) {
throw new InvocationException(e);
} catch (FileNotFoundException e) {
throw new InvocationException(e);
}
try {
IOUtils.copyLarge(r, w);
} catch (IOException e) {
throw new InvocationException(e);
}
try {
r.close();
w.close();
} catch (IOException e) {
throw new InvocationException(e);
}
return target;
} else {
String value = (String) referenceService.renderIdentifier(
t2Reference, String.class, this.getContext());
return value;
}
}