Search in sources :

Example 1 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSTestUtils method deleteAllDescendantFiles.

/**
     * Deletes all the descendant files under the folder.
     * @param folderObject folder object
     * @throws FileSystemException if any file system exception occurs
     * @throws DataStoreException if any file system exception occurs
     */
static void deleteAllDescendantFiles(FileObject folderObject) throws FileSystemException, DataStoreException {
    List<FileObject> children = VFSUtils.getChildFileOrFolders(folderObject);
    FileType fileType;
    for (FileObject child : children) {
        fileType = child.getType();
        if (fileType == FileType.FILE) {
            boolean deleted = child.delete();
            if (!deleted) {
                LOG.warn("File not deleted: {}", child.getName().getFriendlyURI());
            }
        } else if (fileType == FileType.FOLDER) {
            deleteAllDescendantFiles(child);
        }
    }
}
Also used : FileType(org.apache.commons.vfs2.FileType) FileObject(org.apache.commons.vfs2.FileObject)

Example 2 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSBackend method getExistingFileObject.

/**
     * Returns the identified file object. If not existing, returns null.
     *
     * @param identifier data identifier
     * @return identified file object
     * @throws DataStoreException if any file system exception occurs
     */
protected FileObject getExistingFileObject(DataIdentifier identifier) throws DataStoreException {
    String relPath = resolveFileObjectRelPath(identifier);
    String[] segments = relPath.split("/");
    FileObject tempFileObject = getBaseFolderObject();
    try {
        for (int i = 0; i < segments.length; i++) {
            tempFileObject = tempFileObject.getChild(segments[i]);
            if (tempFileObject == null) {
                return null;
            }
        }
        return tempFileObject;
    } catch (FileSystemException e) {
        throw new DataStoreException("File object not resolved: " + identifier, e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject)

Example 3 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSBackend method getAllIdentifiers.

/**
     * {@inheritDoc}
     */
@Override
public Iterator<DataIdentifier> getAllIdentifiers() throws DataStoreException {
    List<DataIdentifier> identifiers = new LinkedList<DataIdentifier>();
    try {
        for (FileObject fileObject : VFSUtils.getChildFolders(getBaseFolderObject())) {
            // skip top-level files
            pushIdentifiersRecursively(identifiers, fileObject);
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("Object identifiers not resolved.", e);
    }
    LOG.debug("Found " + identifiers.size() + " identifiers.");
    return identifiers.iterator();
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) FileObject(org.apache.commons.vfs2.FileObject) LinkedList(java.util.LinkedList)

Example 4 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSBackend method updateLastModifiedTime.

/**
     * Set the last modified time of a fileObject, if the fileObject is writable.
     * @param fileObject the file object
     * @throws DataStoreException if the fileObject is writable but modifying the date fails
     */
private void updateLastModifiedTime(FileObject fileObject) throws DataStoreException {
    try {
        if (isTouchFilePreferred()) {
            getTouchFileObject(fileObject, true);
        } else {
            long time = System.currentTimeMillis() + ACCESS_TIME_RESOLUTION;
            fileObject.getContent().setLastModifiedTime(time);
        }
    } catch (FileSystemException e) {
        throw new DataStoreException("An IO Exception occurred while trying to set the last modified date: " + fileObject.getName().getFriendlyURI(), e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException)

Example 5 with FileSystemException

use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.

the class VFSDataStore method createFileSystemManager.

/**
     * Creates a {@link FileSystemManager} instance.
     * @return a {@link FileSystemManager} instance.
     * @throws RepositoryException if an error occurs creating the manager.
     */
protected FileSystemManager createFileSystemManager() throws RepositoryException {
    FileSystemManager fileSystemManager = null;
    try {
        if (getFileSystemManagerClassName() == null) {
            fileSystemManager = new StandardFileSystemManager();
        } else {
            final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
            fileSystemManager = (FileSystemManager) mgrClass.newInstance();
        }
        if (fileSystemManager instanceof DefaultFileSystemManager) {
            ((DefaultFileSystemManager) fileSystemManager).init();
        }
    } catch (final FileSystemException e) {
        throw new RepositoryException("Could not initialize file system manager of class: " + getFileSystemManagerClassName(), e);
    } catch (final Exception e) {
        throw new RepositoryException("Could not create file system manager of class: " + getFileSystemManagerClassName(), e);
    }
    return fileSystemManager;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) RepositoryException(javax.jcr.RepositoryException) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException)

Aggregations

FileSystemException (org.apache.commons.vfs2.FileSystemException)11 FileObject (org.apache.commons.vfs2.FileObject)8 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)8 RepositoryException (javax.jcr.RepositoryException)3 FileType (org.apache.commons.vfs2.FileType)3 LinkedList (java.util.LinkedList)2 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 FileName (org.apache.commons.vfs2.FileName)1 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)1 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)1 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)1 DelegatingFileSystemOptionsBuilder (org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder)1 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)1 Note (org.apache.zeppelin.notebook.Note)1 Message (org.apache.zeppelin.notebook.socket.Message)1 WatcherMessage (org.apache.zeppelin.notebook.socket.WatcherMessage)1