src/jdk.jpackage/share/classes/jdk/jpackage/internal/PathGroup.java
branchJDK-8200758-branch
changeset 58670 6fb9e12d5595
parent 58302 718bd56695b3
child 58696 61c44899b4eb
equal deleted inserted replaced
58648:3bf53ffa9ae7 58670:6fb9e12d5595
    34 import java.util.HashMap;
    34 import java.util.HashMap;
    35 import java.util.List;
    35 import java.util.List;
    36 import java.util.Map;
    36 import java.util.Map;
    37 import java.util.function.BiFunction;
    37 import java.util.function.BiFunction;
    38 import java.util.stream.Collectors;
    38 import java.util.stream.Collectors;
       
    39 import java.util.stream.Stream;
    39 
    40 
    40 
    41 
    41 /**
    42 /**
    42  * Group of paths.
    43  * Group of paths.
    43  * Each path in the group is assigned a unique id.
    44  * Each path in the group is assigned a unique id.
    80 
    81 
    81     long sizeInBytes() throws IOException {
    82     long sizeInBytes() throws IOException {
    82         long reply = 0;
    83         long reply = 0;
    83         for (Path dir : roots().stream().filter(f -> Files.isDirectory(f)).collect(
    84         for (Path dir : roots().stream().filter(f -> Files.isDirectory(f)).collect(
    84                 Collectors.toList())) {
    85                 Collectors.toList())) {
    85             reply += Files.walk(dir).filter(p -> Files.isRegularFile(p)).mapToLong(
    86             try (Stream<Path> stream = Files.walk(dir)) {
    86                     f -> f.toFile().length()).sum();
    87                 reply += stream.filter(p -> Files.isRegularFile(p)).mapToLong(
       
    88                         f -> f.toFile().length()).sum();
       
    89             }
    87         }
    90         }
    88         return reply;
    91         return reply;
    89     }
    92     }
    90 
    93 
    91     PathGroup resolveAt(Path root) {
    94     PathGroup resolveAt(Path root) {
   143         Map<Path, Path> actions = new HashMap<>();
   146         Map<Path, Path> actions = new HashMap<>();
   144         for (var action: entries) {
   147         for (var action: entries) {
   145             Path src = action.getKey();
   148             Path src = action.getKey();
   146             Path dst = action.getValue();
   149             Path dst = action.getValue();
   147             if (src.toFile().isDirectory()) {
   150             if (src.toFile().isDirectory()) {
   148                 Files.walk(src).forEach(path -> actions.put(dst.resolve(
   151                try (Stream<Path> stream = Files.walk(src)) {
   149                         src.relativize(path)).toAbsolutePath().normalize(), path));
   152                    stream.forEach(path -> actions.put(dst.resolve(
       
   153                            src.relativize(path)).toAbsolutePath().normalize(),
       
   154                            path));
       
   155                }
   150             } else {
   156             } else {
   151                 actions.put(dst.toAbsolutePath().normalize(), src);
   157                 actions.put(dst.toAbsolutePath().normalize(), src);
   152             }
   158             }
   153         }
   159         }
   154 
   160