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);
}
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations