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 org.apache.commons.io.FileUtils;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 import java.io.IOException;
24 import java.nio.file.Files;
25 import java.nio.file.Path;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import java.util.stream.Stream;
31 import static java.nio.file.Files.walk;
33 public final class FileUtil {
34 private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
43 * @param file - Given file
44 * @param path - Given path
46 public static void deleteFile(File file, String path) {
47 boolean value = file.delete();
49 LOGGER.error("Failed to delete the file {} at the location {}", file, path);
54 * Extract files from the given path
56 * @param path where files reside.
57 * @return list of files.
59 public static List<File> getFilesFromDisk(Path path) {
61 try (Stream<Path> fileTree = walk(path)) {
62 // Get the list of files from the path
63 return fileTree.filter(Files::isRegularFile)
65 .collect(Collectors.toList());
66 } catch (IOException e) {
67 LOGGER.error("Failed to find the file due to", e);
69 return new ArrayList<>();