}
private void convert(File aSource, File aDest) throws IOException, Exception {
File[] files = aSource.listFiles(new FileExtFileFilter(myExts));
File[] dirs = aSource.listFiles(new DirFileFilter());
PairtreeRoot ptRoot = new PairtreeRoot(myDest); // JP2 directory
int pathIndex = myDest.getAbsolutePath().length();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("INGEST_DIRS_FOUND", dirs.length, aSource);
}
// These are the directories into which we convert our JP2s
for (File nextSource : dirs) {
String fileName = nextSource.getName();
if (!fileName.startsWith(".")) {
File dest = new File(aDest, nextSource.getName());
if (dest.exists() && (!dest.canWrite() || !dest.isDirectory())) {
throw new IOException("Problem with destination directory: " + dest.getAbsolutePath());
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("INGEST_DESCENDING", dest);
}
if ((!dest.exists() && dest.mkdirs()) || (dest.exists() && dest.isDirectory())) {
convert(nextSource, dest); // go into a sub-directory
} else {
throw new IOException("Failed to create a new directory: " + dest.getAbsolutePath());
}
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("INGEST_FILES_FOUND", files.length, aSource);
}
// These are the actual image files that we're going to convert
for (File next : files) {
String fileName = FileUtils.stripExt(next.getName()) + JP2_EXT;
String sourceFileName = next.getAbsolutePath();
File nextDest = new File(aDest, fileName); // JP2 image file
if (next.length() > myMaxSize) {
if (LOGGER.isErrorEnabled()) {
long size = next.length() / 1048576;
LOGGER.error("INGEST_TOO_LARGE", sourceFileName, size);
}
continue; // We've written to the error log, move along...
}
if (!aDest.exists() && !aDest.mkdirs()) {
throw new IOException("Unable to create new directory: " + nextDest.getAbsolutePath());
}
if (!fileName.startsWith(".")) {
String destFileName = nextDest.getAbsolutePath();
// Check to see whether we've already converted this file!
String path = FileUtils.stripExt(nextDest.getAbsolutePath());
String id = "--" + path.substring(pathIndex);
PairtreeObject ptDir = ptRoot.getObject(id);
String ptFileName = PairtreeUtils.encodeID(id);
File jp2 = new File(ptDir, ptFileName);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("INGEST_EXISTS_CHECK", jp2);