Search in sources :

Example 1 with VisorLogFile

use of org.apache.ignite.internal.visor.log.VisorLogFile in project ignite by apache.

the class VisorTaskUtils method fileTree.

/**
 * Finds all files in folder and in it's sub-tree of specified depth.
 *
 * @param file Starting folder
 * @param maxDepth Depth of the tree. If 1 - just look in the folder, no sub-folders.
 * @param filter file filter.
 * @return List of found files.
 * @throws IOException If failed to list files.
 */
public static List<VisorLogFile> fileTree(File file, int maxDepth, @Nullable FileFilter filter) throws IOException {
    file = resolveSymbolicLink(file);
    if (file.isDirectory()) {
        File[] files = (filter == null) ? file.listFiles() : file.listFiles(filter);
        if (files == null)
            return Collections.emptyList();
        List<VisorLogFile> res = new ArrayList<>(files.length);
        for (File f : files) {
            if (f.isFile() && f.length() > 0)
                res.add(new VisorLogFile(f));
            else if (maxDepth > 1)
                res.addAll(fileTree(f, maxDepth - 1, filter));
        }
        return res;
    }
    // Return ArrayList, because it could be sorted in matchedFiles() method.
    return new ArrayList<>(F.asList(new VisorLogFile(file)));
}
Also used : VisorLogFile(org.apache.ignite.internal.visor.log.VisorLogFile) ArrayList(java.util.ArrayList) RandomAccessFile(java.io.RandomAccessFile) VisorLogFile(org.apache.ignite.internal.visor.log.VisorLogFile) File(java.io.File)

Example 2 with VisorLogFile

use of org.apache.ignite.internal.visor.log.VisorLogFile in project ignite by apache.

the class VisorTaskUtils method matchedFiles.

/**
 * @param file Folder with files to match.
 * @param ptrn Pattern to match against file name.
 * @return Collection of matched files.
 * @throws IOException If failed to filter files.
 */
public static List<VisorLogFile> matchedFiles(File file, final String ptrn) throws IOException {
    List<VisorLogFile> files = fileTree(file, MAX_FOLDER_DEPTH, new FileFilter() {

        @Override
        public boolean accept(File f) {
            return !f.isHidden() && (f.isDirectory() || f.isFile() && f.getName().matches(ptrn));
        }
    });
    Collections.sort(files, LAST_MODIFIED);
    return files;
}
Also used : VisorLogFile(org.apache.ignite.internal.visor.log.VisorLogFile) FileFilter(java.io.FileFilter) RandomAccessFile(java.io.RandomAccessFile) VisorLogFile(org.apache.ignite.internal.visor.log.VisorLogFile) File(java.io.File)

Aggregations

File (java.io.File)2 RandomAccessFile (java.io.RandomAccessFile)2 VisorLogFile (org.apache.ignite.internal.visor.log.VisorLogFile)2 FileFilter (java.io.FileFilter)1 ArrayList (java.util.ArrayList)1