|
@@ -5,6 +5,7 @@ import org.cryptomator.integrations.common.OperatingSystem;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Stream;
|
|
|
import java.util.stream.StreamSupport;
|
|
@@ -15,19 +16,14 @@ import static org.cryptomator.integrations.common.OperatingSystem.Value.LINUX;
|
|
|
public final class DropboxLinuxLocationPresetsProvider implements LocationPresetsProvider {
|
|
|
|
|
|
private static final Path USER_HOME = LocationPresetsProvider.resolveLocation("~/.").toAbsolutePath();
|
|
|
- private static final Pattern PATTERN = Pattern.compile("Dropbox \\(.+\\)");
|
|
|
+ private static final Predicate<String> PATTERN = Pattern.compile("Dropbox \\(.+\\)").asMatchPredicate();
|
|
|
|
|
|
@Override
|
|
|
public Stream<LocationPreset> getLocations() {
|
|
|
- try (var dirStream = Files.newDirectoryStream(USER_HOME,"Dropbox*")){
|
|
|
- return StreamSupport.stream(dirStream.spliterator(), false).flatMap(p -> {
|
|
|
- var matcher = PATTERN.matcher(p.getFileName().toString());
|
|
|
- if(matcher.matches() && Files.isDirectory(p)) {
|
|
|
- return Stream.of(new LocationPreset(matcher.group(), p));
|
|
|
- } else {
|
|
|
- return Stream.of();
|
|
|
- }
|
|
|
- });
|
|
|
+ try (var dirStream = Files.newDirectoryStream(USER_HOME, "Dropbox*")) {
|
|
|
+ return StreamSupport.stream(dirStream.spliterator(), false) //
|
|
|
+ .filter(p -> Files.isDirectory(p) && PATTERN.test(p.getFileName().toString())) //
|
|
|
+ .map(p -> new LocationPreset(p.getFileName().toString(), p));
|
|
|
} catch (IOException e) {
|
|
|
return Stream.of();
|
|
|
}
|