Search in sources :

Example 66 with VFS

use of org.apache.commons.vfs2.VFS in project ant-ivy by apache.

the class VfsRepository method createVFSManager.

private StandardFileSystemManager createVFSManager() throws IOException {
    StandardFileSystemManager result = null;
    try {
        /*
             * The DefaultFileSystemManager gets its configuration from the jakarta-vfs-common
             * implementation which includes the res and tmp schemes which are of no use to use
             * here. Using StandardFileSystemManager lets us specify which schemes to support as
             * well as providing a mechanism to change this support without recompilation.
             */
        result = new StandardFileSystemManager() {

            protected void configurePlugins() throws FileSystemException {
            // disable automatic loading potential unsupported extensions
            }
        };
        result.setConfiguration(getClass().getResource(IVY_VFS_CONFIG));
        result.init();
        // Generate and print a list of available schemes
        Message.verbose("Available VFS schemes...");
        String[] schemes = result.getSchemes();
        Arrays.sort(schemes);
        for (String scheme : schemes) {
            Message.verbose("VFS Supported Scheme: " + scheme);
        }
    } catch (FileSystemException e) {
        /*
             * If our attempt to initialize a VFS Repository fails we log the failure but continue
             * on. Given that an Ivy instance may involve numerous different repository types, it
             * seems overly cautious to throw a runtime exception on the initialization failure of
             * just one repository type.
             */
        Message.error("Unable to initialize VFS repository manager!");
        Message.error(e.getLocalizedMessage());
        throw new IOException(e.getLocalizedMessage(), e);
    }
    return result;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) IOException(java.io.IOException)

Example 67 with VFS

use of org.apache.commons.vfs2.VFS in project ant-ivy by apache.

the class VfsRepository method get.

/**
 * Transfer a VFS Resource from the repository to the local file system.
 *
 * @param srcVfsURI
 *            a <code>String</code> identifying the VFS resource to be fetched
 * @param destination
 *            a <code>File</code> identifying the destination file
 * @throws IOException on failure
 * @see "Supported File Systems in the jakarta-commons-vfs documentation"
 */
public void get(String srcVfsURI, File destination) throws IOException {
    VfsResource src = new VfsResource(srcVfsURI, getVFSManager());
    fireTransferInitiated(src, TransferEvent.REQUEST_GET);
    try {
        FileContent content = src.getContent();
        if (content == null) {
            throw new IllegalArgumentException("invalid vfs uri " + srcVfsURI + ": no content found");
        }
        FileUtil.copy(content.getInputStream(), destination, progress);
    } catch (IOException | RuntimeException ex) {
        fireTransferError(ex);
        throw ex;
    }
}
Also used : FileContent(org.apache.commons.vfs2.FileContent) IOException(java.io.IOException)

Example 68 with VFS

use of org.apache.commons.vfs2.VFS in project ant-ivy by apache.

the class VfsRepository method list.

/**
 * Return a listing of the contents of a parent directory. Listing is a set of strings
 * representing VFS URIs.
 *
 * @param vfsURI
 *            providing identifying a VFS provided resource
 * @return List
 * @throws IOException
 *             on failure.
 * @see "Supported File Systems in the jakarta-commons-vfs documentation"
 */
public List<String> list(String vfsURI) throws IOException {
    List<String> list = new ArrayList<>();
    Message.debug("list called for URI" + vfsURI);
    FileObject resourceImpl = getVFSManager().resolveFile(vfsURI);
    Message.debug("resourceImpl=" + resourceImpl.toString());
    Message.debug("resourceImpl.exists()" + resourceImpl.exists());
    Message.debug("resourceImpl.getType()" + resourceImpl.getType());
    Message.debug("FileType.FOLDER" + FileType.FOLDER);
    if (resourceImpl.exists() && resourceImpl.getType() == FileType.FOLDER) {
        List<FileObject> children = Arrays.asList(resourceImpl.getChildren());
        for (FileObject child : children) {
            Message.debug("child " + children.indexOf(child) + child.getName().getURI());
            list.add(VfsResource.normalize(child.getName().getURI()));
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)50 IOException (java.io.IOException)27 KettleException (org.pentaho.di.core.exception.KettleException)23 FileSystemException (org.apache.commons.vfs2.FileSystemException)22 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)20 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)20 Result (org.pentaho.di.core.Result)19 File (java.io.File)18 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)11 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)11 ResultFile (org.pentaho.di.core.ResultFile)11 VFSClassLoader (org.apache.commons.vfs2.impl.VFSClassLoader)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)7 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)6 URL (java.net.URL)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4