Created
February 6, 2014 23:29
-
-
Save mariogarcia/8854690 to your computer and use it in GitHub Desktop.
GroovyConsole example of Apache Commons VFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grapes([ | |
@Grab(group='org.apache.commons', module='commons-vfs2', version='2.0'), | |
@Grab(group='commons-httpclient', module='commons-httpclient', version='3.1') | |
]) | |
import org.apache.commons.vfs2.VFS | |
import org.apache.commons.vfs2.FileUtil | |
import org.apache.commons.vfs2.FileListener | |
import org.apache.commons.vfs2.FileObject | |
import org.apache.commons.vfs2.FileSystemManager | |
/** | |
* Using Apache Commons VFS2 (http://commons.apache.org/proper/commons-vfs/index.html). | |
* The script copies Groovy distribution zip file in memory and then | |
* it makes three copies in our local file system. | |
*/ | |
class FS { | |
static FileObject mount(String uri) { | |
return VFS.manager.resolveFile(uri) | |
} | |
static FileObject path(FileObject object, relative) { | |
return object.resolveFile(relative) | |
} | |
static void replicate(FileObject source, FileObject... replicas) { | |
replicas.each { replica -> | |
FileUtil.copyContent(source, replica) | |
} | |
} | |
} | |
// 'Mounting' 3 different types of FS | |
FileObject web = FS.mount("http://dist.groovy.codehaus.org/") | |
FileObject tmp = FS.mount("file:/tmp") | |
FileObject ram = FS.mount("ram:/tmp") | |
// Copying the web site content to RAM | |
FileObject src = FS.path(web, 'distributions/groovy-binary-2.2.1.zip') | |
FileObject replica = FS.path(ram, "something.txt") | |
FS.replicate(src, replica) | |
FileObject des1 = FS.path(tmp,'binary1.zip') | |
FileObject des2 = FS.path(tmp,'binary2.zip') | |
FileObject des3 = FS.path(tmp,'binary3.zip') | |
// Here replicating the replica file to all the rest | |
FS.replicate(replica, des1, des2, des3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment