fixes coverity issue 141860

This commit is contained in:
Sebastian Stenzel
2016-08-14 14:16:59 +02:00
parent 3f0373b08f
commit f6ebbb23d1

View File

@@ -9,11 +9,11 @@
package org.cryptomator.frontend.webdav.mount;
import static java.util.stream.Collectors.toSet;
import static java.util.stream.IntStream.rangeClosed;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Set;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;
import javax.inject.Inject;
@@ -24,16 +24,21 @@ import org.apache.commons.lang3.SystemUtils;
import com.google.common.collect.Sets;
@Singleton
public final class WindowsDriveLetters {
private static final Set<Character> A_TO_Z = rangeClosed('A', 'Z').mapToObj(i -> (char) i).collect(toSet());
private static final Set<Character> A_TO_Z;
static {
try (IntStream stream = IntStream.rangeClosed('A', 'Z')) {
A_TO_Z = stream.mapToObj(i -> (char) i).collect(toSet());
}
}
@Inject
public WindowsDriveLetters() {
}
public Set<Character> getOccupiedDriveLetters() {
if (!SystemUtils.IS_OS_WINDOWS) {
throw new UnsupportedOperationException("This method is only defined for Windows file systems");
@@ -41,7 +46,7 @@ public final class WindowsDriveLetters {
Iterable<Path> rootDirs = FileSystems.getDefault().getRootDirectories();
return StreamSupport.stream(rootDirs.spliterator(), false).map(Path::toString).map(CharUtils::toChar).map(Character::toUpperCase).collect(toSet());
}
public Set<Character> getAvailableDriveLetters() {
return Sets.difference(A_TO_Z, getOccupiedDriveLetters());
}