下面列出了怎么用java.nio.file.FileSystemAlreadyExistsException的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
/**
* Get the URI of the specified configuration file from its resolved URL.
*
* @param path configuration file path (absolute, relative, or simple filename)
* @param url resolved configuration file URL
* @return resolved configuration file URI
* @throws URISyntaxException if specified URL is invalid
* @throws IOException on failure to construct file system or extract configuration file
*/
private static URI getConfigUri(final String path, final URL url) throws URISyntaxException, IOException {
URI uri = url.toURI();
if ("jar".equals(uri.getScheme())) {
try {
FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());
} catch (FileSystemAlreadyExistsException eaten) { //NOSONAR
LOGGER.warn("Specified file system already exists: {}", eaten.getMessage());
}
String outputDir = PathUtils.getBaseDir();
File outputFile = new File(outputDir, path);
Path outputPath = outputFile.toPath();
if (!outputPath.toFile().exists()) {
Files.copy(Paths.get(uri), outputPath);
}
uri = outputPath.toUri();
}
return uri;
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
public static FileSystem getFileSystem(Path iviewFile) throws IOException {
URI uri = URI.create("jar:" + iviewFile.toUri());
try {
return FileSystems.newFileSystem(uri, Collections.emptyMap(), MCRClassTools.getClassLoader());
} catch (FileSystemAlreadyExistsException exc) {
// block until file system is closed
try {
FileSystem fileSystem = FileSystems.getFileSystem(uri);
while (fileSystem.isOpen()) {
try {
Thread.sleep(10);
} catch (InterruptedException ie) {
// get out of here
throw new IOException(ie);
}
}
} catch (FileSystemNotFoundException fsnfe) {
// seems closed now -> do nothing and try to return the file system again
LOGGER.debug("Filesystem not found", fsnfe);
}
return getFileSystem(iviewFile);
}
}
/**
* Constructs a new {@code FileSystem} object identified by a URI.
* <p>
* The URI must have a {@link URI#getScheme() scheme} equal to {@link #getScheme()}, and no {@link URI#getUserInfo() user information},
* {@link URI#getPath() path}, {@link URI#getQuery() query} or {@link URI#getFragment() fragment}. Authentication credentials must be set through
* the given environment map, preferably through {@link SFTPEnvironment}.
* <p>
* This provider allows multiple file systems per host, but only one file system per user on a host.
* Once a file system is {@link FileSystem#close() closed}, this provider allows a new file system to be created with the same URI and credentials
* as the closed file system.
*/
@Override
@SuppressWarnings("resource")
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
// user info must come from the environment map
checkURI(uri, false, false);
SFTPEnvironment environment = wrapEnvironment(env);
String username = environment.getUsername();
URI normalizedURI = normalizeWithUsername(uri, username);
synchronized (fileSystems) {
if (fileSystems.containsKey(normalizedURI)) {
throw new FileSystemAlreadyExistsException(normalizedURI.toString());
}
SFTPFileSystem fs = new SFTPFileSystem(this, normalizedURI, environment);
fileSystems.put(normalizedURI, fs);
return fs;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
/**
* Lists all children resources.
*
* @param parent the root path represented in {@link URI} format
* @param consumer consumer for children resources
* @throws java.io.IOException if any i/o error occur
* @throws ProviderNotFoundException if a provider supporting the URI scheme is not installed
*/
public static void listResources(URI parent, Consumer<Path> consumer) throws IOException {
FileSystem fileSystem = null;
try {
if (!"file".equals(parent.getScheme())) {
try {
fileSystem = FileSystems.newFileSystem(parent, Collections.emptyMap());
} catch (FileSystemAlreadyExistsException ignore) {
}
}
Path root = Paths.get(parent);
Files.list(root).forEach(consumer);
} finally {
// close FS only if only it has been initialized here
if (fileSystem != null) {
fileSystem.close();
}
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
delegate = result;
return result;
}
}
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
throws IOException
{
if (env != null && env.keySet().contains("IOException")) {
triggerEx("IOException");
}
checkUri(uri);
synchronized (FaultyFSProvider.class) {
if (delegate != null && delegate.isOpen())
throw new FileSystemAlreadyExistsException();
FaultyFileSystem result = new FaultyFileSystem(null);
delegate = result;
return result;
}
}