-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanFileRunner.java
More file actions
50 lines (41 loc) · 1.76 KB
/
ScanFileRunner.java
File metadata and controls
50 lines (41 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package com.xeriou.plugins.pluginx;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.*;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class ScanFileRunner implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
URI templates = this.getClass().getResource("/templates").toURI();
System.out.println("ScanFileRunner " + templates);
Path myPath;
if (templates.getScheme().equals("jar")) {
FileSystem fileSystem = FileSystems.newFileSystem(templates, Collections.<String, Object>emptyMap());
myPath = fileSystem.getPath("/templates");
} else {
myPath = ResourceUtils.getFile(templates).toPath();
}
// Files.copy()
Files.list(myPath).forEach(System.out::println);
Path rootTemplatePath = Paths.get("templates");
System.out.println("rootTemplatePath " + rootTemplatePath.toAbsolutePath());
Files.list(rootTemplatePath).forEach(System.out::println);
List<Path> c = Files.list(myPath).collect(Collectors.toList());
for (Path f : c) {
try(InputStream ins = Files.newInputStream(f)) {
System.out.print("Copy " + f.getFileName());
Path toCopy = rootTemplatePath.resolve(f.getFileName().toString());
System.out.println(" to " + toCopy);
Files.copy(ins, toCopy, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}