Search in sources :

Example 11 with FileSystemProvider

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;
    });
}
Also used : Path(java.nio.file.Path) SeekableByteChannel(java.nio.channels.SeekableByteChannel) FileSystemProvider(java.nio.file.spi.FileSystemProvider) FileSystem(java.nio.file.FileSystem) ByteBuffer(java.nio.ByteBuffer) Before(org.junit.Before)

Example 12 with FileSystemProvider

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));
}
Also used : Path(java.nio.file.Path) DirectoryStream(java.nio.file.DirectoryStream) IOException(java.io.IOException) FileSystemProvider(java.nio.file.spi.FileSystemProvider) FileSystem(java.nio.file.FileSystem) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Directory(org.cryptomator.cryptofs.CryptoPathMapper.Directory) Before(org.junit.Before)

Example 13 with FileSystemProvider

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);
}
Also used : Path(java.nio.file.Path) Cryptor(org.cryptomator.cryptolib.api.Cryptor) FileSystemProvider(java.nio.file.spi.FileSystemProvider) DosFileAttributes(java.nio.file.attribute.DosFileAttributes) FileSystem(java.nio.file.FileSystem) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Before(org.junit.Before)

Example 14 with FileSystemProvider

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);
    }
}
Also used : FileSystemProvider(java.nio.file.spi.FileSystemProvider)

Example 15 with FileSystemProvider

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;
}
Also used : FileSystemProvider(java.nio.file.spi.FileSystemProvider)

Aggregations

FileSystemProvider (java.nio.file.spi.FileSystemProvider)17 Path (java.nio.file.Path)7 FileSystem (java.nio.file.FileSystem)6 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)5 Before (org.junit.Before)5 IOException (java.io.IOException)4 URI (java.net.URI)4 SeekableByteChannel (java.nio.channels.SeekableByteChannel)2 DirectoryStream (java.nio.file.DirectoryStream)2 NoSuchFileException (java.nio.file.NoSuchFileException)2 PosixFileAttributes (java.nio.file.attribute.PosixFileAttributes)2 HashMap (java.util.HashMap)2 Cryptor (org.cryptomator.cryptolib.api.Cryptor)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URISyntaxException (java.net.URISyntaxException)1 URLClassLoader (java.net.URLClassLoader)1 ByteBuffer (java.nio.ByteBuffer)1 AccessMode (java.nio.file.AccessMode)1