Search in sources :

Example 1 with FileSystemProvider

use of java.nio.file.spi.FileSystemProvider in project jdk8u_jdk by JetBrains.

the class CustomOptions method main.

public static void main(String[] args) throws Exception {
    FileSystemProvider provider = new MyCustomProvider();
    Map<String, ?> env = Collections.emptyMap();
    URI uri = URI.create("pass:///");
    FileSystem fs = provider.newFileSystem(uri, env);
    // Create temp dir for testing
    Path dir = TestUtil.createTemporaryDirectory();
    try {
        // Create temp file for testing
        Path path = fs.getPath(dir.resolve("foo").toString());
        Files.createFile(path);
        // Test custom option
        Files.newInputStream(path, CustomOption.IGNORE).close();
        if (ignoreCount != 1)
            throw new RuntimeException("IGNORE option not passed through");
        // Test null option
        try {
            Files.newInputStream(path, new OpenOption[] { null }).close();
            throw new RuntimeException("NullPointerException expected");
        } catch (NullPointerException ignore) {
        }
        // Test unsupported options
        try {
            Files.newInputStream(path, StandardOpenOption.WRITE).close();
            throw new RuntimeException("UnsupportedOperationException expected");
        } catch (UnsupportedOperationException uoe) {
        }
        try {
            Files.newInputStream(path, StandardOpenOption.APPEND).close();
            throw new RuntimeException("UnsupportedOperationException expected");
        } catch (UnsupportedOperationException uoe) {
        }
    } finally {
        // Cleanup
        TestUtil.removeAll(dir);
    }
}
Also used : FileSystemProvider(java.nio.file.spi.FileSystemProvider) URI(java.net.URI)

Example 2 with FileSystemProvider

use of java.nio.file.spi.FileSystemProvider in project jdk8u_jdk by JetBrains.

the class PassThroughFileSystem method create.

/**
     * Creates a new "pass through" file system. Useful for test environments
     * where the provider might not be deployed.
     */
static FileSystem create() throws IOException {
    FileSystemProvider provider = new PassThroughProvider();
    Map<String, ?> env = Collections.emptyMap();
    URI uri = URI.create("pass:///");
    return provider.newFileSystem(uri, env);
}
Also used : FileSystemProvider(java.nio.file.spi.FileSystemProvider) URI(java.net.URI)

Example 3 with FileSystemProvider

use of java.nio.file.spi.FileSystemProvider in project Bytecoder by mirkosertic.

the class JrtFileSystemProvider method newFileSystem.

private FileSystem newFileSystem(String targetHome, URI uri, Map<String, ?> env) throws IOException {
    Objects.requireNonNull(targetHome);
    Path jrtfs = FileSystems.getDefault().getPath(targetHome, "lib", JRT_FS_JAR);
    if (Files.notExists(jrtfs)) {
        throw new IOException(jrtfs.toString() + " not exist");
    }
    Map<String, ?> newEnv = new HashMap<>(env);
    newEnv.remove("java.home");
    ClassLoader cl = newJrtFsLoader(jrtfs);
    try {
        Class<?> c = Class.forName(JrtFileSystemProvider.class.getName(), false, cl);
        @SuppressWarnings("deprecation") Object tmp = c.newInstance();
        return ((FileSystemProvider) tmp).newFileSystem(uri, newEnv);
    } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
        throw new IOException(e);
    }
}
Also used : HashMap(java.util.HashMap) FileSystemProvider(java.nio.file.spi.FileSystemProvider) URLClassLoader(java.net.URLClassLoader)

Example 4 with FileSystemProvider

use of java.nio.file.spi.FileSystemProvider in project cryptofs by cryptomator.

the class CryptoBasicFileAttributesTest method setup.

@Before
public void setup() throws IOException {
    cryptor = Mockito.mock(Cryptor.class);
    FileHeaderCryptor headerCryptor = Mockito.mock(FileHeaderCryptor.class);
    FileContentCryptor contentCryptor = Mockito.mock(FileContentCryptor.class);
    Mockito.when(cryptor.fileHeaderCryptor()).thenReturn(headerCryptor);
    Mockito.when(headerCryptor.headerSize()).thenReturn(88);
    Mockito.when(cryptor.fileContentCryptor()).thenReturn(contentCryptor);
    Mockito.when(contentCryptor.cleartextChunkSize()).thenReturn(32 * 1024);
    Mockito.when(contentCryptor.ciphertextChunkSize()).thenReturn(16 + 32 * 1024 + 32);
    ciphertextFilePath = Mockito.mock(Path.class);
    FileSystem fs = Mockito.mock(FileSystem.class);
    Mockito.when(ciphertextFilePath.getFileSystem()).thenReturn(fs);
    FileSystemProvider fsProvider = Mockito.mock(FileSystemProvider.class);
    Mockito.when(fs.provider()).thenReturn(fsProvider);
    delegateAttr = Mockito.mock(BasicFileAttributes.class);
}
Also used : Path(java.nio.file.Path) FileHeaderCryptor(org.cryptomator.cryptolib.api.FileHeaderCryptor) FileHeaderCryptor(org.cryptomator.cryptolib.api.FileHeaderCryptor) FileContentCryptor(org.cryptomator.cryptolib.api.FileContentCryptor) Cryptor(org.cryptomator.cryptolib.api.Cryptor) FileSystemProvider(java.nio.file.spi.FileSystemProvider) FileSystem(java.nio.file.FileSystem) FileContentCryptor(org.cryptomator.cryptolib.api.FileContentCryptor) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) Before(org.junit.Before)

Example 5 with FileSystemProvider

use of java.nio.file.spi.FileSystemProvider in project cryptofs by cryptomator.

the class CryptoPosixFileAttributeViewTest method setUp.

@Before
public void setUp() throws UnsupportedFileAttributeViewException {
    FileSystem fileSystem = mock(FileSystem.class);
    FileSystemProvider provider = mock(FileSystemProvider.class);
    when(path.getFileSystem()).thenReturn(fileSystem);
    when(fileSystem.provider()).thenReturn(provider);
    when(provider.getFileAttributeView(path, PosixFileAttributeView.class)).thenReturn(delegate);
    inTest = new CryptoPosixFileAttributeView(path, fileAttributeProvider);
}
Also used : FileSystemProvider(java.nio.file.spi.FileSystemProvider) FileSystem(java.nio.file.FileSystem) Before(org.junit.Before)

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