2 * Copyright (C) 2019 Bell Canada. All rights reserved.
4 * NOTICE: All the intellectual and technical concepts contained herein are
5 * proprietary to Bell Canada and are protected by trade secret or copyright law.
6 * Unauthorized copying of this file, via any medium is strictly prohibited.
9 package org.onap.ccsdk.cds.sdclistener.util;
11 import static java.nio.file.Files.walk;
13 import java.io.IOException;
14 import java.nio.file.Files;
15 import java.nio.file.Path;
16 import java.util.List;
17 import java.util.Optional;
18 import java.util.stream.Collectors;
19 import java.util.stream.Stream;
20 import org.apache.commons.io.FileUtils;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
24 public final class FileUtil {
25 private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
34 * @param file - Given file
35 * @param path - Given path
37 public static void deleteFile(File file, String path) {
38 boolean value = file.delete();
40 LOGGER.error("Failed to delete the file {} at the location {}", file, path);
45 * Extract files from the given path
47 * @param path where files reside.
48 * @return list of files.
50 public static Optional<List<File>> getFilesFromDisk(Path path) {
51 try (Stream<Path> fileTree = walk(path)) {
52 // Get the list of files from the path
53 return Optional.of(fileTree.filter(Files::isRegularFile)
55 .collect(Collectors.toList()));
56 } catch (IOException e) {
57 LOGGER.error("Failed to find the file due to", e);
59 return Optional.empty();