min = "5";
}
try {
m_uploadStorageMinutes = Integer.parseInt(min);
if (m_uploadStorageMinutes < 1) {
throw new ModuleInitializationException("uploadStorageMinutes "
+ "must be 1 or more, if specified.", getRole());
}
} catch (NumberFormatException nfe) {
throw new ModuleInitializationException("uploadStorageMinutes must "
+ "be an integer, if specified.",
getRole());
}
// initialize storage area by 1) ensuring the directory is there
// and 2) reading in the existing files, if any, and setting their
// startTime to the current time.
try {
m_tempDir = getServer().getUploadDir();
if (!m_tempDir.isDirectory()) {
m_tempDir.mkdirs();
if (!m_tempDir.isDirectory()) {
throw new ModuleInitializationException(
"Failed to create temp dir at " +
m_tempDir.toString(), getRole());
}
}
// put leftovers in hash, while saving highest id as m_lastId
m_uploadStartTime = new Hashtable<String, Long>();
String[] fNames = m_tempDir.list();
Long leftoverStartTime = new Long(System.currentTimeMillis());
m_lastId = 0;
for (String element : fNames) {
try {
int id = Integer.parseInt(element);
if (id > m_lastId) {
m_lastId = id;
}
m_uploadStartTime.put(element, leftoverStartTime);
} catch (NumberFormatException nfe) {
// skip files that aren't named numerically
}
}
} catch (Exception e) {
throw new ModuleInitializationException("Error while initializing "
+ "temporary storage area: " + e.getClass().getName()
+ ": " + e.getMessage(), getRole(), e);
}
// initialize variables pertaining to checksumming datastreams.
String auto = getParameter("autoChecksum");
logger.debug("Got Parameter: autoChecksum = " + auto);
if (auto != null && auto.equalsIgnoreCase("true")) {
Datastream.autoChecksum = true;
Datastream.defaultChecksumType = getParameter("checksumAlgorithm");
}
logger.debug("autoChecksum is " + auto);
logger.debug("defaultChecksumType is " + Datastream.defaultChecksumType);
// get delay between purge of two uploaded files (default 1 minute)
String purgeDelayInMillis = getParameter("purgeDelayInMillis");
if (purgeDelayInMillis == null) {
purgeDelayInMillis = "60000";
}
try {
this.m_purgeDelayInMillis = Integer.parseInt(purgeDelayInMillis);
} catch (NumberFormatException nfe) {
throw new ModuleInitializationException(
"purgeDelayInMillis must be an integer, if specified.",
getRole());
}
}