Search in sources :

Example 16 with LocalFile

use of org.apache.commons.vfs2.provider.local.LocalFile in project spoofax by metaborg.

the class ResourceService method localFile.

@Override
public File localFile(FileObject resource, FileObject dir) {
    if (resource instanceof LocalFile) {
        return FileUtils.toFile(resource);
    }
    final File localDir = localPath(dir);
    if (localDir == null) {
        throw new MetaborgRuntimeException("Replication directory " + dir + " is not on the local filesystem, cannot get local file for " + resource);
    }
    try {
        dir.createFolder();
        final FileObject copyLoc;
        if (resource.getType() == FileType.FOLDER) {
            copyLoc = dir;
        } else {
            copyLoc = dir.resolveFile(resource.getName().getBaseName());
        }
        copyLoc.copyFrom(resource, new AllFileSelector());
        return localDir;
    } catch (FileSystemException e) {
        throw new MetaborgRuntimeException("Could not get local file for " + resource, e);
    }
}
Also used : MetaborgRuntimeException(org.metaborg.core.MetaborgRuntimeException) LocalFile(org.apache.commons.vfs2.provider.local.LocalFile) FileSystemException(org.apache.commons.vfs2.FileSystemException) AllFileSelector(org.apache.commons.vfs2.AllFileSelector) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) LocalFile(org.apache.commons.vfs2.provider.local.LocalFile)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)16 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)10 File (java.io.File)9 IOException (java.io.IOException)6 KettleException (org.pentaho.di.core.exception.KettleException)6 KettleFileException (org.pentaho.di.core.exception.KettleFileException)4 KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 FileInputStream (java.io.FileInputStream)3 FileOutputStream (java.io.FileOutputStream)3 FileContent (org.apache.commons.vfs2.FileContent)3 ResultFile (org.pentaho.di.core.ResultFile)3 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 DecimalFormat (java.text.DecimalFormat)2 CheckedInputStream (java.util.zip.CheckedInputStream)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Result (org.pentaho.di.core.Result)2 Database (org.pentaho.di.core.database.Database)2