2 * Copyright © 2019 Bell Canada
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.ccsdk.cds.sdclistener.util;
18 import static java.nio.file.Files.walk;
20 import java.io.IOException;
21 import java.nio.file.Files;
22 import java.nio.file.Path;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.stream.Collectors;
26 import java.util.stream.Stream;
27 import org.apache.commons.io.FileUtils;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 public final class FileUtil {
32 private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
41 * @param file - Given file
42 * @param path - Given path
44 public static void deleteFile(File file, String path) {
45 boolean value = file.delete();
47 LOGGER.error("Failed to delete the file {} at the location {}", file, path);
52 * Extract files from the given path
54 * @param path where files reside.
55 * @return list of files.
57 public static List<File> getFilesFromDisk(Path path) {
59 try (Stream<Path> fileTree = walk(path)) {
60 // Get the list of files from the path
61 return fileTree.filter(Files::isRegularFile)
63 .collect(Collectors.toList());
64 } catch (IOException e) {
65 LOGGER.error("Failed to find the file due to", e);
67 return new ArrayList<>();