Java Code Examples for org.apache.commons.vfs2.FileSystemException#getMessage()

The following examples show how to use org.apache.commons.vfs2.FileSystemException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFileSystemManagerProvider.java    From spoofax with Apache License 2.0 6 votes vote down vote up
@Override public FileSystemManager get() {
    try {
        final DefaultFileSystemManager manager = new DefaultFileSystemManager();

        manager.setFilesCache(new DefaultFilesCache());
        manager.setCacheStrategy(CacheStrategy.ON_RESOLVE);

        final String baseTmpDir = System.getProperty("java.io.tmpdir");
        final File tempDir = new File(baseTmpDir, "vfs_cache" + new Random().nextLong()).getAbsoluteFile();
        final DefaultFileReplicator replicator = new DefaultFileReplicator(tempDir);
        manager.setTemporaryFileStore(replicator);
        manager.setReplicator(replicator);

        addDefaultProvider(manager);
        addProviders(manager);
        setBaseFile(manager);

        manager.init();

        return manager;
    } catch(FileSystemException e) {
        throw new RuntimeException("Cannot initialize resource service: " + e.getMessage(), e);
    }
}
 
Example 2
Source File: FTPRemoteConnector.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyAndReconnect() throws StageException {
  boolean done = false;
  int retryCounter = 0;
  boolean reconnect = false;
  while (!done && retryCounter < MAX_RETRIES) {
    try {
      if (reconnect) {
        remoteDir = VFS.getManager().resolveFile(remoteURI.toString(), options);
        reconnect = false;
      }
      remoteDir.refresh();
      // A call to getChildren() and then refresh() is needed in order to properly refresh if files were updated
      // A possible bug in VFS?
      remoteDir.getChildren();
      remoteDir.refresh();
      done = true;
    } catch (FileSystemException fse) {
      // Refresh can fail due to session is down, a timeout, etc; so try getting a new connection
      if (retryCounter < MAX_RETRIES - 1) {
        LOG.info("Got FileSystemException when trying to refresh remote directory. '{}'", fse.getMessage(), fse);
        LOG.warn("Retrying connection to remote directory");
        reconnect = true;
      } else {
        throw new StageException(Errors.REMOTE_09, fse.getMessage(), fse);
      }
    }
    retryCounter++;
  }
}
 
Example 3
Source File: FtpFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the children of this file change.
 */
@Override
protected void onChildrenChanged(final FileName child, final FileType newType) {
    if (children != null && newType.equals(FileType.IMAGINARY)) {
        try {
            children.remove(UriParser.decode(child.getBaseName()));
        } catch (final FileSystemException e) {
            throw new RuntimeException(e.getMessage());
        }
    } else {
        // if child was added we have to rescan the children
        // TODO - get rid of this
        children = null;
    }
}
 
Example 4
Source File: DefaultURLStreamHandler.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
protected void parseURL(final URL u, final String spec, final int start, final int limit) {
    try {
        final FileObject old = context.resolveFile(u.toExternalForm(), fileSystemOptions);

        FileObject newURL;
        if (start > 0 && spec.charAt(start - 1) == ':') {
            newURL = context.resolveFile(old, spec, fileSystemOptions);
        } else {
            if (old.isFile() && old.getParent() != null) {
                // for files we have to resolve relative
                newURL = old.getParent().resolveFile(spec);
            } else {
                newURL = old.resolveFile(spec);
            }
        }

        final String url = newURL.getName().getURI();
        final StringBuilder filePart = new StringBuilder();
        final String protocolPart = UriParser.extractScheme(context.getFileSystemManager().getSchemes(), url, filePart);

        setURL(u, protocolPart, "", -1, null, null, filePart.toString(), null, null);
    } catch (final FileSystemException fse) {
        // This is rethrown to MalformedURLException in URL anyway
        throw new RuntimeException(fse.getMessage());
    }
}
 
Example 5
Source File: DefaultURLConnection.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
public String getContentType() {
    try {
        return content.getContentInfo().getContentType();
    } catch (final FileSystemException e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
Example 6
Source File: DefaultURLConnection.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
public String getContentEncoding() {
    try {
        return content.getContentInfo().getContentEncoding();
    } catch (final FileSystemException e) {
        throw new RuntimeException(e.getMessage());
    }
}
 
Example 7
Source File: AbstractFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private void setFileType(final FileType type) {
    if (type != null && type != FileType.IMAGINARY) {
        try {
            fileName.setType(type);
        } catch (final FileSystemException e) {
            throw new RuntimeException(e.getMessage());
        }
    }
    this.type = type;
}
 
Example 8
Source File: VFSClassLoader.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Calls super.getPermissions both for the code source and also adds the permissions granted to the parent layers.
 *
 * @param cs the CodeSource.
 * @return The PermissionCollections.
 */
@Override
protected PermissionCollection getPermissions(final CodeSource cs) {
    try {
        final String url = cs.getLocation().toString();
        final FileObject file = lookupFileObject(url);
        if (file == null) {
            return super.getPermissions(cs);
        }

        final FileObject parentLayer = file.getFileSystem().getParentLayer();
        if (parentLayer == null) {
            return super.getPermissions(cs);
        }

        final Permissions combi = new Permissions();
        PermissionCollection permCollect = super.getPermissions(cs);
        copyPermissions(permCollect, combi);

        for (FileObject parent = parentLayer; parent != null; parent = parent.getFileSystem().getParentLayer()) {
            final CodeSource parentcs = new CodeSource(parent.getURL(), parent.getContent().getCertificates());
            permCollect = super.getPermissions(parentcs);
            copyPermissions(permCollect, combi);
        }

        return combi;
    } catch (final FileSystemException fse) {
        throw new SecurityException(fse.getMessage());
    }
}
 
Example 9
Source File: GoogleDrivePluginLifecycleListener.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void onEnvironmentInit() throws LifecycleException {
  try {
    boolean proceed = true;
    if ( !new File(
        GoogleDriveFileObject.resolveCredentialsPath() + "/" + resourceBundle.getString( "client.secrets" ) )
        .exists() ) {
      proceed = false;
      log.warn(
          "The Google Authorization secrets security token file (" + resourceBundle.getString( "client.secrets" )
              + ") is not present in the credentials folder. This file is necessary to activate the Google Drive VFS plugin." );
    }

    if ( !new File(
        GoogleDriveFileObject.resolveCredentialsPath() + "/" + resourceBundle.getString( "stored.credential" ) )
        .exists() ) {
      DefaultCapabilityManager capabilityManager = DefaultCapabilityManager.getInstance();
      if ( capabilityManager.capabilityExist( "pentaho-server" ) ) {
        proceed = false;
        log.warn( "The Google Authorization Code Flow security token file (" + resourceBundle
            .getString( "stored.credential" ) + ") is not present in the credentials folder.  This file is necessary to activate the Google Drive VFS plugin." );

      }
    }

    /**
     * Registers the GoogleDrive VFS File Provider dynamically since it is bundled with our plugin and will not automatically
     * be registered through the normal class path search the default FileSystemManager performs.
     */
    if ( proceed ) {
      FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager();
      if ( fsm instanceof DefaultFileSystemManager ) {
        if ( !Arrays.asList( fsm.getSchemes() ).contains( GoogleDriveFileProvider.SCHEME ) ) {
          ( (DefaultFileSystemManager) fsm )
              .addProvider( GoogleDriveFileProvider.SCHEME, new GoogleDriveFileProvider() );
        }
      }
    }
  } catch ( FileSystemException e ) {
    throw new LifecycleException( e.getMessage(), false );
  }
}