public PluginResult run(PipelinePluginInput input,
PipelinePluginOutput output,
PipelinePluginContext context) throws Exception {
logger = getDefaultLogger(context);
final InputFiles files = input.getInputFiles();
if ( files.isEmpty() )
return PluginResult.SUCCESS;
// Get the variables needed to determine the maximum file size.
int records_per_file = 1000;
String field_separator = ":", array_element_separator = ";";
int field_index = 2, array_index = 2;
String header_record_identifier = "MSH", key_record_identifier = "PID";
DataElements dataElements = context.getDataElements();
if ( dataElements.contains(HEADER_DE_NAME, DataType.STRING) ) {
header_record_identifier = dataElements.get(HEADER_DE_NAME, DataType.STRING).getValue();
}
if ( dataElements.contains(KEY_DE_NAME, DataType.STRING) ) {
key_record_identifier = dataElements.get(KEY_DE_NAME, DataType.STRING).getValue();
}
if ( dataElements.contains(FIELD_SEPARATOR, DataType.STRING) ) {
field_separator = dataElements.get(FIELD_SEPARATOR, DataType.STRING).getValue();
}
if ( dataElements.contains(ARRAY_ELEMENT_SEPARATOR, DataType.STRING) ) {
array_element_separator = dataElements.get(ARRAY_ELEMENT_SEPARATOR, DataType.STRING).getValue();
}
if ( dataElements.contains(FIELD_INDEX, DataType.INTEGER) ) {
// this is 0-based index
field_index = dataElements.get(FIELD_INDEX, DataType.INTEGER).getValue();
}
if ( dataElements.contains(ARRAY_INDEX, DataType.INTEGER) ) {
// this is 0-base index
array_index = dataElements.get(ARRAY_INDEX, DataType.INTEGER).getValue();
}
if ( dataElements.contains(RECORDS_PER_FILE_DE_NAME, DataType.INTEGER) ) {
records_per_file = dataElements.get(RECORDS_PER_FILE_DE_NAME, DataType.INTEGER).getValue();
}
if ( header_record_identifier.isEmpty() ) {
throw new PipelinePluginException("No segment header was specified. Not enough information to perform splitting.");
}
String header_segment = header_record_identifier+field_separator, key_segment = key_record_identifier+field_separator;
char delimiter=':', separator=';';
if(field_separator.length() == 1)delimiter = field_separator.charAt(0);
if(array_element_separator.length() == 1)separator = array_element_separator.charAt(0);
// Loop over input files.
for (InputFile plugin_input_file : files.getFiles()) {
final File input_file = plugin_input_file.getFile();
Date start_t = new Date();
RandomAccessFile raf = new RandomAccessFile(input_file, "r");
// System.out.println("read raf: "+input_file);