Search in sources :

Example 41 with FileObject

use of org.apache.commons.vfs2.FileObject in project motech by motech.

the class ConfigFileMonitorTest method shouldDeleteConfigWhenFileIsDeleted.

@Test
public void shouldDeleteConfigWhenFileIsDeleted() throws FileSystemException {
    final String fileName = "res:config/org.motechproject.motech-module1/somemodule.properties";
    FileObject fileObject = VFS.getManager().resolveFile(fileName);
    configFileMonitor.fileDeleted(new FileChangeEvent(fileObject));
    verify(configurationService).deleteByBundle(new File(fileObject.getName().getPath()).getParentFile().getName());
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) FileChangeEvent(org.apache.commons.vfs2.FileChangeEvent) File(java.io.File) Test(org.junit.Test)

Example 42 with FileObject

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

the class VfsResource method getChildren.

/**
 * Get a list of direct descendants of the given resource. Note that attempts to get a list of
 * children does <em>not</em> result in an error. Instead an error message is
 * logged and an empty ArrayList returned.
 *
 * @return A <code>ArrayList</code> of VFSResources
 */
public List<String> getChildren() {
    init();
    List<String> list = new ArrayList<>();
    try {
        if (resourceImpl != null && resourceImpl.exists() && resourceImpl.getType() == FileType.FOLDER) {
            for (FileObject child : resourceImpl.getChildren()) {
                list.add(normalize(child.getName().getURI()));
            }
        }
    } catch (IOException e) {
        Message.debug(e);
        Message.verbose(e.getLocalizedMessage());
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException)

Example 43 with FileObject

use of org.apache.commons.vfs2.FileObject in project artisynth_core by artisynth.

the class ZipUtility method unzip.

public static void unzip(URIx src, final File dest) throws IOException {
    dest.mkdirs();
    final FileSystemManager fileSystemManager = VFS.getManager();
    final FileObject zipFileObject = fileSystemManager.resolveFile(src.toString());
    try {
        final FileObject fileSystem = fileSystemManager.createFileSystem(zipFileObject);
        try {
            fileSystemManager.toFileObject(dest).copyFrom(fileSystem, new AllFileSelector());
        } finally {
            fileSystem.close();
        }
    } finally {
        zipFileObject.close();
    }
}
Also used : AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 44 with FileObject

use of org.apache.commons.vfs2.FileObject in project artisynth_core by artisynth.

the class FileCacher method getInputStream.

public InputStream getInputStream(URIx uri) throws FileSystemException {
    // will resolve next
    FileObject remoteFile = null;
    // loop through authenticators until we either succeed or cancel
    boolean cancel = false;
    while (remoteFile == null && cancel == false) {
        remoteFile = resolveRemote(uri);
    }
    if (remoteFile == null || !remoteFile.exists()) {
        throw new FileSystemException("Cannot find remote file <" + uri.toString() + ">", new FileNotFoundException("<" + uri.toString() + ">"));
    }
    // open stream content
    InputStream stream = null;
    try {
        stream = remoteFile.getContent().getInputStream();
    } catch (Exception e) {
        remoteFile.close();
        throw new RuntimeException("Failed to open " + remoteFile.getURL(), e);
    } finally {
    }
    return stream;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) JSchException(com.jcraft.jsch.JSchException)

Example 45 with FileObject

use of org.apache.commons.vfs2.FileObject in project artisynth_core by artisynth.

the class FileCacher method copy.

public boolean copy(URIx from, URIx to, FileTransferMonitor monitor) throws FileSystemException {
    FileObject fromFile = null;
    FileObject toFile = null;
    // clear authenticators
    setAuthenticator(fsOpts, null);
    setIdentityFactory(fsOpts, null);
    // loop through authenticators until we either succeed or cancel
    boolean cancel = false;
    while (toFile == null && cancel == false) {
        toFile = resolveRemote(to);
    }
    cancel = false;
    while (fromFile == null && cancel == false) {
        fromFile = resolveRemote(from);
    }
    if (fromFile == null || !fromFile.exists()) {
        throw new FileSystemException("Cannot find source file <" + from.toString() + ">", new FileNotFoundException("<" + from.toString() + ">"));
    }
    if (toFile == null) {
        throw new FileSystemException("Cannot find destination <" + to.toString() + ">", new FileNotFoundException("<" + to.toString() + ">"));
    }
    // monitor the file transfer progress
    if (monitor != null) {
        monitor.monitor(fromFile, toFile, -1, fromFile.getName().getBaseName());
        monitor.start();
        monitor.fireStartEvent(toFile);
    }
    // transfer content
    try {
        if (fromFile.isFile()) {
            toFile.copyFrom(fromFile, Selectors.SELECT_SELF);
        } else if (fromFile.isFolder()) {
            // final FileObject fileSystem = manager.createFileSystem(remoteFile);
            toFile.copyFrom(fromFile, new AllFileSelector());
        // fileSystem.close();
        }
        if (monitor != null) {
            monitor.fireCompleteEvent(toFile);
        }
    } catch (Exception e) {
        throw new FileTransferException("Failed to complete transfer of " + fromFile.getURL() + " to " + toFile.getURL(), e);
    } finally {
        // close files if we need to
        fromFile.close();
        toFile.close();
        if (monitor != null) {
            monitor.release(toFile);
            monitor.stop();
        }
    }
    return true;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileNotFoundException(java.io.FileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileNotFoundException(java.io.FileNotFoundException) JSchException(com.jcraft.jsch.JSchException)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)670 IOException (java.io.IOException)207 KettleException (org.pentaho.di.core.exception.KettleException)206 FileSystemException (org.apache.commons.vfs2.FileSystemException)180 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)104 KettleFileException (org.pentaho.di.core.exception.KettleFileException)97 Test (org.junit.Test)83 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)68 File (java.io.File)64 InputStream (java.io.InputStream)48 ArrayList (java.util.ArrayList)37 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)37 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)36 KettleStepException (org.pentaho.di.core.exception.KettleStepException)36 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)34 ResultFile (org.pentaho.di.core.ResultFile)33 MetaborgException (org.metaborg.core.MetaborgException)32 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)32 Result (org.pentaho.di.core.Result)32 OutputStream (java.io.OutputStream)30