Concatenate files - multiple files
Created: 2010-10-28 14:44:17
The workflow splits the string 'a,b,c,d,e' into its five elements and saves the individual strings to five temporary files. The file paths to those files are then output by the create_and_populate_temporary_file beanshell.
The create_temporary_file beanshell creates a file to which the concatentation can be written.
The concatenate_files service concatenates the five files and writes the result to the temporary output file. Because the displayresults port has no value, the results are not output by the service.
The temporary file to which the results were written is read by the read_text_file service and its contents output.
The workflow output contains 'a
b
c
d
e' i.e. the contents of the concatenated files separated by a newline.
Preview
Run
Run this Workflow in the Taverna Workbench...
Workflow Components
Authors (1)
Titles (3)
Concatenate files - multiple files |
Concatenate files - multiple files |
Concatenate files - multiple files |
Descriptions (1)
The workflow splits the string 'a,b,c,d,e' into its five elements and saves the individual strings to five temporary files. The file paths to those files are then output by the create_and_populate_temporary_file beanshell.
The create_temporary_file beanshell creates a file to which the concatentation can be written.
The concatenate_files service concatenates the five files and writes the result to the temporary output file. Because the displayresults port has no value, the results are not output by the service.
The temporary file to which the results were written is read by the read_text_file service and its contents output.
The workflow output contains 'a
b
c
d
e' i.e. the contents of the concatenated files separated by a newline. |
Dependencies (0)
Processors (6)
Name |
Type |
Description |
Create_and_populate_temporary_file |
beanshell |
ScriptFile f = File.createTempFile("taverna", ".tmp");
BufferedWriter writer = new BufferedWriter(new FileWriter(f));
writer.write(content);
writer.close();
filepath = f.getCanonicalPath(); |
Create_temporary_file |
beanshell |
ScriptFile f = File.createTempFile("taverna", ".tmp");
filepath = f.getCanonicalPath(); |
string_list |
stringconstant |
Valuea,b,c,d,e |
Split_string_into_string_list_by_regular_expression |
localworker |
ScriptList split = new ArrayList();
if (!string.equals("")) {
String regexString = ",";
if (regex != void) {
regexString = regex;
}
String[] result = string.split(regexString);
for (int i = 0; i < result.length; i++) {
split.add(result[i]);
}
}
|
Concatenate_Files |
localworker |
ScriptBufferedReader getReader (String fileUrl) throws IOException {
InputStreamReader reader;
try {
reader = new FileReader(fileUrl);
}
catch (FileNotFoundException e) {
// try a real URL instead
URL url = new URL(fileUrl);
reader = new InputStreamReader (url.openStream());
}
return new BufferedReader(reader);
}
String NEWLINE = System.getProperty("line.separator");
boolean displayResults = false;
if (displayresults != void) {
displayResults = Boolean.valueOf(displayresults).booleanValue();
}
StringBuffer sb = new StringBuffer(2000);
if (outputfile == void) {
throw new RuntimeException("The 'outputfile' parameter cannot be null");
}
if (filelist == null) {
throw new RuntimeException("The 'filelist' parameter cannot be null");
}
String str = null;
Writer writer = new FileWriter(outputfile);
for (int i = 0; i < filelist.size(); i++) {
BufferedReader reader = getReader(filelist.get(i));
while ((str = reader.readLine()) != null) {
writer.write(str);
writer.write(NEWLINE);
if (displayResults) {
sb.append(str);
sb.append(NEWLINE);
}
}
reader.close();
}
writer.flush();
writer.close();
if (displayResults) {
results= sb.toString();
}
|
Read_Text_File |
localworker |
ScriptBufferedReader getReader (String fileUrl) throws IOException {
InputStreamReader reader;
try {
reader = new FileReader(fileUrl);
}
catch (FileNotFoundException e) {
// try a real URL instead
URL url = new URL(fileUrl);
reader = new InputStreamReader (url.openStream());
}
return new BufferedReader(reader);
}
StringBuffer sb = new StringBuffer(4000);
BufferedReader in = getReader(fileurl);
String str;
String lineEnding = System.getProperty("line.separator");
while ((str = in.readLine()) != null) {
sb.append(str);
sb.append(lineEnding);
}
in.close();
filecontents = sb.toString();
|
Beanshells (2)
Name |
Description |
Inputs |
Outputs |
Create_and_populate_temporary_file |
|
content
|
filepath
|
Create_temporary_file |
|
|
filepath
|
Outputs (1)
Name |
Description |
content_of_outputfile |
|
Datalinks (6)
Source |
Sink |
Split_string_into_string_list_by_regular_expression:split |
Create_and_populate_temporary_file:content |
string_list:value |
Split_string_into_string_list_by_regular_expression:string |
Create_and_populate_temporary_file:filepath |
Concatenate_Files:filelist |
Create_temporary_file:filepath |
Concatenate_Files:outputfile |
Create_temporary_file:filepath |
Read_Text_File:fileurl |
Read_Text_File:filecontents |
content_of_outputfile |
Coordinations (1)
Controller |
Target |
Concatenate_Files |
Read_Text_File |
Uploader
License
All versions of this Workflow are
licensed under:
Version 1
(of 1)
Credits (0)
(People/Groups)
None
Attributions (0)
(Workflows/Files)
None
Shared with Groups (1)
Featured In Packs (0)
None
Log in to add to one of your Packs
Attributed By (0)
(Workflows/Files)
None
Favourited By (0)
No one
Statistics
Other workflows that use similar services
(0)
There are no workflows in myExperiment that use similar services to this Workflow.
Comments (0)
No comments yet
Log in to make a comment