use of java.nio.file.spi.FileSystemProvider in project cryptofs by cryptomator.
the class MigratorsTest method setup.
@Before
public void setup() throws IOException {
keyFile = StandardCharsets.UTF_8.encode("{\"version\": 0000}");
pathToVault = Mockito.mock(Path.class);
Path pathToMasterkey = Mockito.mock(Path.class);
FileSystem fs = Mockito.mock(FileSystem.class);
FileSystemProvider provider = Mockito.mock(FileSystemProvider.class);
SeekableByteChannel sbc = Mockito.mock(SeekableByteChannel.class);
Mockito.when(pathToVault.resolve("masterkey.cryptomator")).thenReturn(pathToMasterkey);
Mockito.when(pathToMasterkey.getFileSystem()).thenReturn(fs);
Mockito.when(fs.provider()).thenReturn(provider);
Mockito.when(provider.newByteChannel(Mockito.eq(pathToMasterkey), Mockito.any(), Mockito.any())).thenReturn(sbc);
Mockito.when(sbc.size()).thenReturn((long) keyFile.remaining());
Mockito.when(sbc.read(Mockito.any())).then(invocation -> {
ByteBuffer dst = invocation.getArgument(0);
int n = Math.min(keyFile.remaining(), dst.remaining());
byte[] tmp = new byte[n];
keyFile.get(tmp);
dst.put(tmp);
return n;
});
}
use of java.nio.file.spi.FileSystemProvider in project cryptofs by cryptomator.
the class CryptoDirectoryStreamTest method setup.
@Before
@SuppressWarnings("unchecked")
public void setup() throws IOException {
filenameCryptor = CRYPTOR_PROVIDER.createNew().fileNameCryptor();
ciphertextDirPath = Mockito.mock(Path.class);
FileSystem fs = Mockito.mock(FileSystem.class);
Mockito.when(ciphertextDirPath.getFileSystem()).thenReturn(fs);
FileSystemProvider provider = Mockito.mock(FileSystemProvider.class);
Mockito.when(fs.provider()).thenReturn(provider);
dirStream = Mockito.mock(DirectoryStream.class);
Mockito.when(provider.newDirectoryStream(Mockito.same(ciphertextDirPath), Mockito.any())).thenReturn(dirStream);
longFileNameProvider = Mockito.mock(LongFileNameProvider.class);
conflictResolver = Mockito.mock(ConflictResolver.class);
finallyUtil = mock(FinallyUtil.class);
Mockito.when(longFileNameProvider.inflate(Mockito.anyString())).then(invocation -> {
String shortName = invocation.getArgument(0);
if (shortName.contains("invalid")) {
throw new IOException("invalid shortened name");
} else {
return StringUtils.removeEnd(shortName, ".lng");
}
});
cryptoPathMapper = Mockito.mock(CryptoPathMapper.class);
Mockito.when(cryptoPathMapper.resolveDirectory(Mockito.any())).then(invocation -> {
Path dirFilePath = invocation.getArgument(0);
if (dirFilePath.toString().contains("invalid")) {
throw new IOException("Invalid directory.");
}
Path dirPath = Mockito.mock(Path.class);
BasicFileAttributes attrs = Mockito.mock(BasicFileAttributes.class);
Mockito.when(dirPath.getFileSystem()).thenReturn(fs);
Mockito.when(provider.readAttributes(dirPath, BasicFileAttributes.class)).thenReturn(attrs);
Mockito.when(attrs.isDirectory()).thenReturn(!dirFilePath.toString().contains("noDirectory"));
return new Directory("asdf", dirPath);
});
Mockito.when(conflictResolver.resolveConflictsIfNecessary(Mockito.any(), Mockito.any())).then(returnsFirstArg());
doAnswer(invocation -> {
for (Object runnable : invocation.getArguments()) {
((RunnableThrowingException<?>) runnable).run();
}
return null;
}).when(finallyUtil).guaranteeInvocationOf(any(RunnableThrowingException.class), any(RunnableThrowingException.class), any(RunnableThrowingException.class));
}
use of java.nio.file.spi.FileSystemProvider in project cryptofs by cryptomator.
the class CryptoFileAttributeProviderTest method setup.
@Before
public void setup() throws IOException {
cryptor = Mockito.mock(Cryptor.class);
ciphertextFilePath = Mockito.mock(Path.class);
FileSystem fs = Mockito.mock(FileSystem.class);
Mockito.when(ciphertextFilePath.getFileSystem()).thenReturn(fs);
FileSystemProvider provider = Mockito.mock(FileSystemProvider.class);
Mockito.when(fs.provider()).thenReturn(provider);
BasicFileAttributes basicAttr = Mockito.mock(BasicFileAttributes.class);
PosixFileAttributes posixAttr = Mockito.mock(PosixFileAttributes.class);
DosFileAttributes dosAttr = Mockito.mock(DosFileAttributes.class);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextFilePath), Mockito.same(BasicFileAttributes.class), Mockito.any())).thenReturn(basicAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextFilePath), Mockito.same(PosixFileAttributes.class), Mockito.any())).thenReturn(posixAttr);
Mockito.when(provider.readAttributes(Mockito.same(ciphertextFilePath), Mockito.same(DosFileAttributes.class), Mockito.any())).thenReturn(dosAttr);
}
use of java.nio.file.spi.FileSystemProvider in project mycore by MyCoRe-Org.
the class MCRFileSystemPromoter method promoteFileSystemProvider.
private void promoteFileSystemProvider(List<FileSystemProvider> detectedProviders) {
if (detectedProviders.isEmpty()) {
return;
}
for (FileSystemProvider provider : detectedProviders) {
LOGGER.info("Promoting filesystem {}: {}", provider.getScheme(), provider.getClass().getCanonicalName());
MCRPaths.addFileSystemProvider(provider);
}
}
use of java.nio.file.spi.FileSystemProvider in project ceylon by eclipse.
the class CompileTest method isJarFileSystemAvailable.
boolean isJarFileSystemAvailable() {
boolean result = false;
for (FileSystemProvider fsp : FileSystemProvider.installedProviders()) {
String scheme = fsp.getScheme();
System.err.println("Provider: " + scheme + " " + fsp);
if (scheme.equalsIgnoreCase("jar") || scheme.equalsIgnoreCase("zip"))
result = true;
}
return result;
}
Aggregations