Very good question. You are correct, QIE ignores empty files since they don't actually contain a message. For your situation, I would use a scheduled script to monitor the directory for empty files.
Select the green source node, and select the Scheduled Scripts tab.
Click Insert to create a new Scheduled Script. Set the following fields:
Name:
Error Empty Files
CRON String:
0 0 * * * *
Script:
var srcDirectoryPath = "C:\\Qvera\\In\\";
var extension = "txt";
File = java.io.File;
var FileUtils = org.apache.commons.io.FileUtils;
function isFileEmpty(fileName) {
var FileInputStream = java.io.FileInputStream;
var fis;
var empty = false;
try {
fis = new FileInputStream(new File(fileName));
empty = fis.read() == -1;
} finally {
try {
fis.close();
} catch (err) {
qie.info('Failed to close file: ' + fileName);
}
}
return empty;
}
var timeThreshhold = new java.util.Date().getTime() - (3 * 60 * 1000); // 3 minutes old
var extensions = java.lang.reflect.Array.newInstance(java.lang.String, 1);
extensions[0] = new java.lang.String(extension);
var srcDirectory = new File(srcDirectoryPath);
qie.debug('Script looking in ' + srcDirectoryPath + ', for extension \'txt\', and threshhold of ' + timeThreshhold);
var listFiles = FileUtils.convertFileCollectionToFileArray(FileUtils.listFiles(srcDirectory, extensions, false));
qie.debug('found ' + listFiles.length + ' files!');
for (var i = 0; i < listFiles.length; i++) {
var currentFile = listFiles[i];
qie.debug(currentFile + ', older?' + FileUtils.isFileOlder(currentFile, timeThreshhold) + ', empty?' + isFileEmpty(currentFile.getAbsolutePath()));
if (FileUtils.isFileOlder(currentFile, timeThreshhold) && isFileEmpty(currentFile.getAbsolutePath())) {
var fileName = currentFile.getName();
qie.warn('Empty File Found: ' + fileName);
qie.addInboundMessage('Empty File Found: ' + fileName, fileName);
if (!FileUtils.deleteQuietly(currentFile)) {
qie.error('Failed to delete empty file: ' + fileName);
}
}
}
It should look something like this:
My test channel is looking in for files C:\Qvera\In\*.txt. In your script, you will need to change the values for srcDirectoryPath, and the extension.
This script will do the following:
1. Run at the top of the hour (based on the CRON String)
2. Find files in the srcDirectoryPath, with the extension which are at least 3 minutes old
3. Add a new message of "Empty File Found: " followed by the fileName
4. Remove the empty file from the directory
This was a lot of fun making this solution. :) I hope you enjoy it.