}
if ( segmentSet.isEmpty() ) {
throw new PipelinePluginException("No segments were defined. Segment variable was '" + segments + ",");
}
OutputFiles outputFiles = output.getOutputFiles();
for (InputFile plugin_input_file : files.getFiles()) {
final File input_file = plugin_input_file.getFile();
final File output_file = new File( input_file.getCanonicalPath() + "-line-break-plugin" );
BufferedReader br = null;
BufferedWriter bw = null;
try {
br = new BufferedReader(new FileReader(input_file));
bw = new BufferedWriter(new FileWriter(output_file));
String line = null;
StringBuilder current_line = new StringBuilder();
while (( line = br.readLine()) != null) {
if ( line.isEmpty() ) {
// Ignore empty lines.
continue;
}
// Find the segment identifier
int ipos = line.indexOf(separator);
String seg;
if ( ipos == -1 ) {
seg = line;
}
else if ( ipos == 0 ) {
seg = "";
}
else {
seg = line.substring(0, ipos);
}
if (segmentSet.contains(seg) ) {
// A new segment is found so we can write out the last line and start a new.
if ( current_line.length() > 0 ) {
bw.write(current_line.toString());
bw.newLine();
}
current_line = new StringBuilder(line);
}
else {
// The line does not start with a segment identifier so we need to skip the line break.
current_line.append(line);
}
}
if ( current_line.length() > 0 ) {
bw.write(current_line.toString());
bw.newLine();
}
}
finally {
closeIgnoreException(br);
closeIgnoreException(bw);
}
outputFiles.add(output_file, plugin_input_file);
}
return PluginResult.SUCCESS;
}