blob: d037e75f1d202fa34854f84bf08460590f363550 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*******************************************************************************
* Copyright (c) 2016 AT&T Intellectual Property. All rights reserved.
*******************************************************************************/
package com.att.authz;
import java.io.File;
import java.io.IOException;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import com.att.authz.env.AuthzTrans;
import com.att.inno.env.APIException;
public abstract class FileCassBatch extends CassBatch {
public FileCassBatch(AuthzTrans trans, String log4jName) throws APIException, IOException {
super(trans, log4jName);
}
protected List<File> findAllFiles(String regex) {
List<File> files = new ArrayList<File>();
FileSystem fileSystem = FileSystems.getDefault();
PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + regex);
Path path = Paths.get(System.getProperty("user.dir"), "data");
try {
DirectoryStream<Path> directoryStream = Files.newDirectoryStream(
path, regex);
for (Path file : directoryStream) {
if (pathMatcher.matches(file.getFileName())) {
files.add(file.toFile());
}
}
} catch (IOException ex) {
ex.printStackTrace();
} catch (DirectoryIteratorException ex) {
ex.printStackTrace();
}
return files;
}
}
|