Search in sources :

Example 1 with SourceFile

use of org.onebusaway.admin.bundle.model.SourceFile in project onebusaway-application-modules by camsys.

the class BundleBuildingUtil method getSourceFilesWithSumsForDirectory.

public List<SourceFile> getSourceFilesWithSumsForDirectory(File baseDir, File dir, File rootDir) throws IllegalArgumentException {
    List<SourceFile> files = new ArrayList<SourceFile>();
    if (!dir.isDirectory()) {
        throw new IllegalArgumentException(dir.getPath() + " is not a directory");
    } else {
        for (String filePath : dir.list()) {
            File listEntry = new File(dir, filePath);
            String listEntryFilename = null;
            try {
                listEntryFilename = listEntry.getCanonicalPath();
            } catch (Exception e) {
            // bury
            }
            // prevent lock files from insertion into json, they change
            if (listEntry.isFile() && listEntryFilename != null && !listEntryFilename.endsWith(".lck")) {
                SourceFile file = new SourceFile();
                file.setCreatedDate(getCreatedDate(listEntry));
                String relPathToBase = rootDir.toURI().relativize(listEntry.toURI()).getPath();
                file.setUri(relPathToBase);
                file.setFilename(relPathToBase);
                String sum = getMd5ForFile(listEntry);
                file.setMd5(sum);
                files.add(file);
                _log.debug("file:" + listEntry + " has Md5=" + sum + " and createdDate=" + file.getCreatedDate());
            } else if (listEntry.isDirectory()) {
                files.addAll(getSourceFilesWithSumsForDirectory(baseDir, listEntry, rootDir));
            }
        }
    }
    return files;
}
Also used : ArrayList(java.util.ArrayList) SourceFile(org.onebusaway.admin.bundle.model.SourceFile) File(java.io.File) BundleFile(org.onebusaway.admin.bundle.model.BundleFile) SourceFile(org.onebusaway.admin.bundle.model.SourceFile) IOException(java.io.IOException)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BundleFile (org.onebusaway.admin.bundle.model.BundleFile)1 SourceFile (org.onebusaway.admin.bundle.model.SourceFile)1