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());
}
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;
}
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();
}
}
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;
}
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;
}
Aggregations