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