Remove proxy docker buildArg
[ccsdk/cds.git] / ms / sdclistener / application / src / main / java / org / onap / ccsdk / cds / sdclistener / util / FileUtil.java
1 /*
2  * Copyright (C) 2019 Bell Canada. All rights reserved.
3  *
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.
7  */
8
9 package org.onap.ccsdk.cds.sdclistener.util;
10
11 import static java.nio.file.Files.walk;
12 import java.io.File;
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;
23
24 public final class FileUtil {
25     private static final Logger LOGGER = LoggerFactory.getLogger(FileUtils.class);
26
27     private FileUtil() {
28
29     }
30
31     /**
32      * Delete the file.
33      *
34      * @param file - Given file
35      * @param path - Given path
36      */
37     public static void deleteFile(File file, String path) {
38         boolean value = file.delete();
39         if (!value) {
40             LOGGER.error("Failed to delete the file {} at the location {}", file, path);
41         }
42     }
43
44     /**
45      * Extract files from the given path
46      *
47      * @param path where files reside.
48      * @return list of files.
49      */
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)
54                 .map(Path::toFile)
55                 .collect(Collectors.toList()));
56         } catch (IOException e) {
57             LOGGER.error("Failed to find the file due to", e);
58         }
59         return Optional.empty();
60     }
61 }