List of usage examples for org.apache.commons.vfs2 FileObject delete
boolean delete() throws FileSystemException;
From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java
public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init();/*from ww w .j a v a 2 s . c om*/ StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); Boolean delRes = currFile.delete(); Assert.assertTrue(delRes); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java
public static void deleteFile(String accntName, String accntHost, String accntKey, String containerName, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider()); currMan.init();/*from w w w . j av a 2s . com*/ StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, accntHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); Boolean delRes = currFile.delete(); Assert.assertTrue(delRes); }
From source file:com.yenlo.synapse.transport.vfs.VFSUtils.java
/** * Release a file item lock acquired either by the VFS listener or a sender * * @param fsManager which is used to resolve the processed file * @param fo representing the processed file *///from w w w. j ava 2s . c om public static void releaseLock(FileSystemManager fsManager, FileObject fo) { try { String fullPath = fo.getName().getURI(); int pos = fullPath.indexOf("?"); if (pos > -1) { fullPath = fullPath.substring(0, pos); } FileObject lockObject = fsManager.resolveFile(fullPath + ".lock"); if (lockObject.exists()) { lockObject.delete(); } } catch (FileSystemException e) { log.error("Couldn't release the lock for the file : " + fo.getName() + " after processing"); } }
From source file:it.geosolutions.geobatch.destination.common.utils.RemoteBrowserUtils.java
/** * Delete a remote file//from w w w .ja v a 2 s. c om * * @param protocol * @param user * @param password * @param host * @param port * @param timeout * @param filePath * @param fileName * @param connectMode only used for {@link RemoteBrowserProtocol#ftp} protocol * @throws FTPException * @throws IOException */ public static void deleteFile(RemoteBrowserProtocol protocol, String user, String password, String host, int port, int timeout, String filePath, String fileName, FTPConnectMode connectMode) throws FTPException, IOException { if (RemoteBrowserProtocol.ftp.equals(protocol)) { FTPHelperBare.deleteFileOrDirectory(host, fileName, false, cleanRoot(filePath), user, password, port, connectMode, timeout); } else { initFsManager(timeout); FileObject file = fsManager.resolveFile( getURI(protocol, user, password, host, port, filePath + SEPARATOR + fileName), fsOptions); file.delete(); } }
From source file:com.yenlo.synapse.transport.vfs.VFSUtils.java
/** * Acquires a file item lock before processing the item, guaranteing that the file is not * processed while it is being uploaded and/or the item is not processed by two listeners * * @param fsManager used to resolve the processing file * @param fo representing the processing file item * @return boolean true if the lock has been acquired or false if not */// w w w .j a v a 2 s. c om public synchronized static boolean acquireLock(FileSystemManager fsManager, FileObject fo) { // generate a random lock value to ensure that there are no two parties // processing the same file Random random = new Random(); byte[] lockValue = String.valueOf(random.nextLong()).getBytes(); try { // check whether there is an existing lock for this item, if so it is assumed // to be processed by an another listener (downloading) or a sender (uploading) // lock file is derived by attaching the ".lock" second extension to the file name String fullPath = fo.getName().getURI(); int pos = fullPath.indexOf("?"); if (pos != -1) { fullPath = fullPath.substring(0, pos); } FileObject lockObject = fsManager.resolveFile(fullPath + ".lock"); if (lockObject.exists()) { log.debug("There seems to be an external lock, aborting the processing of the file " + fo.getName() + ". This could possibly be due to some other party already " + "processing this file or the file is still being uploaded"); } else { // write a lock file before starting of the processing, to ensure that the // item is not processed by any other parties lockObject.createFile(); OutputStream stream = lockObject.getContent().getOutputStream(); try { stream.write(lockValue); stream.flush(); stream.close(); } catch (IOException e) { lockObject.delete(); log.error("Couldn't create the lock file before processing the file " + fullPath, e); return false; } finally { lockObject.close(); } // check whether the lock is in place and is it me who holds the lock. This is // required because it is possible to write the lock file simultaneously by // two processing parties. It checks whether the lock file content is the same // as the written random lock value. // NOTE: this may not be optimal but is sub optimal FileObject verifyingLockObject = fsManager.resolveFile(fullPath + ".lock"); if (verifyingLockObject.exists() && verifyLock(lockValue, verifyingLockObject)) { return true; } } } catch (FileSystemException fse) { log.error("Cannot get the lock for the file : " + maskURLPassword(fo.getName().getURI()) + " before processing"); } return false; }
From source file:com.collective.celos.ci.deploy.WorkflowFilesDeployer.java
private void undeployJSFile(URI dirUri) throws URISyntaxException, FileSystemException { if (dirUri != null) { FileObject file = jScpWorker.getFileObjectByUri(getTargetJsFileUri(dirUri)); file.delete(); }//w w w. ja va 2 s .c o m }
From source file:binky.reportrunner.engine.utils.impl.FileSystemHandlerImpl.java
public void deleteFile(String url) throws IOException { FileObject file = fsManager.resolveFile(url); file.delete(); }
From source file:net.sourceforge.fullsync.fs.connection.CommonsVfsConnection.java
@Override public final boolean delete(final File node) throws IOException { FileObject obj = base.resolveFile(node.getPath()); return obj.delete(); }
From source file:com.stehno.sanctuary.core.remote.FileSystemRemoteStore.java
@Override public void deleteFile(File rootDirectory, File file) { final FileObject remoteFile; try {/*from w w w. ja v a2 s . c om*/ remoteFile = findRemoteFile(rootDirectory, file); remoteFile.delete(); if (log.isDebugEnabled()) log.debug("Deleted: " + remoteFile); } catch (FileSystemException e) { // FIXME: error e.printStackTrace(); } }
From source file:com.msopentech.odatajclient.testservice.utils.FSManager.java
public FileObject putInMemory(final InputStream is, final String path) throws IOException { final FileObject memObject = fsManager.resolveFile(MEM_PREFIX + path); if (memObject.exists()) { memObject.delete(); }//from w w w .j a va 2 s . c o m // create in-memory file memObject.createFile(); // read in-memory content final OutputStream os = memObject.getContent().getOutputStream(); IOUtils.copy(is, os); IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); return memObject; }