org.apache.commons.vfs2.provider.AbstractFileSystem Java Examples

The following examples show how to use org.apache.commons.vfs2.provider.AbstractFileSystem. 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: WebSolutionFileObject.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
public WebSolutionFileObject( final AbstractFileName name,
                              final AbstractFileSystem fileSystem,
                              final SolutionFileModel fs )
{
  super( name, fileSystem );
  this.fs = fs;
}
 
Example #2
Source File: DefaultFileMonitor.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Recursively fires create events for all children if recursive descent is enabled. Otherwise the create event
 * is only fired for the initial FileObject.
 *
 * @param child The child to add.
 */
private void fireAllCreate(final FileObject child) {
    // Add listener so that it can be triggered
    if (this.fm.getFileListener() != null) {
        child.getFileSystem().addListener(child, this.fm.getFileListener());
    }

    ((AbstractFileSystem) child.getFileSystem()).fireFileCreated(child);

    // Remove it because a listener is added in the queueAddFile
    if (this.fm.getFileListener() != null) {
        child.getFileSystem().removeListener(child, this.fm.getFileListener());
    }

    this.fm.queueAddFile(child); // Add

    try {
        if (this.fm.isRecursive() && child.getType().hasChildren()) {
            final FileObject[] newChildren = child.getChildren();
            for (final FileObject element : newChildren) {
                fireAllCreate(element);
            }
        }
    } catch (final FileSystemException fse) {
        LOG.error(fse.getLocalizedMessage(), fse);
    }
}
 
Example #3
Source File: AbstractProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Runs the test. This implementation short-circuits the test if the provider being tested does not have the
 * capabilities required by this test.
 * <p>
 * TODO - Handle negative caps as well - ie, only run a test if the provider does not have certain caps.
 * </p>
 * <p>
 * TODO - Figure out how to remove the test from the TestResult if the test is skipped.
 * </p>
 */
@Override
protected void runTest() throws Throwable {
    // Check the capabilities
    final Capability[] caps = getRequiredCaps();
    if (caps != null) {
        for (final Capability cap2 : caps) {
            final Capability cap = cap2;
            final FileSystem fs = getFileSystem();
            if (!fs.hasCapability(cap)) {
                // String name = fs.getClass().getName();
                // int index = name.lastIndexOf('.');
                // String fsName = (index > 0) ? name.substring(index + 1) : name;
                // System.out.println("skipping " + getName() + " because " +
                // fsName + " does not have capability " + cap);
                return;
            }
        }
    }

    // Provider has all the capabilities - execute the test
    if (method != null) {
        try {
            method.invoke(this, (Object[]) null);
        } catch (final InvocationTargetException e) {
            throw e.getTargetException();
        }
    } else {
        super.runTest();
    }

    if (((AbstractFileSystem) readFolder.getFileSystem()).isOpen()) {
        String name = "unknown";
        if (method != null) {
            name = method.getName();
        }

        throw new IllegalStateException(getClass().getName() + ": filesystem has open streams after: " + name);
    }
}
 
Example #4
Source File: DefaultFileMonitor.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
private void check() {
    this.refresh();

    try {
        // If the file existed and now doesn't
        if (this.exists && !this.file.exists()) {
            this.exists = this.file.exists();
            this.timestamp = -1;

            // Fire delete event

            ((AbstractFileSystem) this.file.getFileSystem()).fireFileDeleted(this.file);

            // Remove listener in case file is re-created. Don't want to fire twice.
            if (this.fm.getFileListener() != null) {
                this.file.getFileSystem().removeListener(this.file, this.fm.getFileListener());
            }

            // Remove from map
            this.fm.queueRemoveFile(this.file);
        } else if (this.exists && this.file.exists()) {

            // Check the timestamp to see if it has been modified
            if (this.timestamp != this.file.getContent().getLastModifiedTime()) {
                this.timestamp = this.file.getContent().getLastModifiedTime();
                // Fire change event

                // Don't fire if it's a folder because new file children
                // and deleted files in a folder have their own event triggered.
                if (!this.file.getType().hasChildren()) {
                    ((AbstractFileSystem) this.file.getFileSystem()).fireFileChanged(this.file);
                }
            }

        } else if (!this.exists && this.file.exists()) {
            this.exists = this.file.exists();
            this.timestamp = this.file.getContent().getLastModifiedTime();
            // Don't fire if it's a folder because new file children
            // and deleted files in a folder have their own event triggered.
            if (!this.file.getType().hasChildren()) {
                ((AbstractFileSystem) this.file.getFileSystem()).fireFileCreated(this.file);
            }
        }

        this.checkForNewChildren();

    } catch (final FileSystemException fse) {
        LOG.error(fse.getLocalizedMessage(), fse);
    }
}
 
Example #5
Source File: VirtualFileProvider.java    From commons-vfs with Apache License 2.0 3 votes vote down vote up
/**
 * Close a VirtualFileSystem by removing it from the {@code #components} list of this provider.
 * <p>
 * This gets called from DefaultFileManager#_closeFileSystem.
 * </p>
 *
 * @param fileSystem the file system remembered by this provider.
 */
void closeFileSystem(final FileSystem fileSystem) {
    final AbstractFileSystem fs = (AbstractFileSystem) fileSystem;

    removeComponent(fs);
    fs.close();
}