List of usage examples for org.apache.commons.vfs2 FileObject exists
boolean exists() throws FileSystemException;
From source file:hadoopInstaller.installation.Installer.java
private void analyzeBundles() throws InstallationFatalError { getLog().trace("HadoopInstaller.InstallationBundles.Start"); //$NON-NLS-1$ FileObject folder; try {/*from w w w . jav a 2s . c o m*/ folder = getLocalDirectory().resolveFile(InstallerConstants.TGZ_BUNDLES_FOLDER); if (!folder.exists()) { folder.createFolder(); getLog().warn("HadoopInstaller.InstallationBundles.FolderDoesntExist", //$NON-NLS-1$ InstallerConstants.TGZ_BUNDLES_FOLDER, InstallerConstants.CONFIGURATION_FILE); } } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.InstallationBundles.FolderCouldNotOpen", //$NON-NLS-1$ InstallerConstants.TGZ_BUNDLES_FOLDER); } for (String resource : getConfig().getFiles().keySet()) { String fileName = getConfig().getFiles().get(resource); try { getLog().trace("HadoopInstaller.InstallationBundles.From", resource, //$NON-NLS-1$ fileName); FileObject bundle = folder.resolveFile(fileName); if (!bundle.exists()) { throw new InstallationFatalError("HadoopInstaller.InstallationBundles.Missing", //$NON-NLS-1$ fileName, folder.getName().getBaseName()); } if (doDeploy()) { getBundleHashes(bundle); } getBundleInstallDirectory(resource, bundle); try { bundle.close(); } catch (FileSystemException ex) { getLog().warn(ex, "HadoopInstaller.CouldNotClose", //$NON-NLS-1$ fileName); } } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.InstallationBundles.Error", //$NON-NLS-1$ resource, fileName); } getLog().trace("HadoopInstaller.InstallationBundles.Success", //$NON-NLS-1$ resource, fileName); } try { folder.close(); } catch (FileSystemException e) { getLog().warn(e, "HadoopInstaller.CouldNotClose", //$NON-NLS-1$ InstallerConstants.TGZ_BUNDLES_FOLDER); } }
From source file:com.seeburger.vfs2.util.VFSClassLoader.java
/** * Returns an Enumeration of all the resources in the search path * with the specified name./* w w w . j a v a 2 s.com*/ * @param name The resources to find. * @return An Enumeration of the resources associated with the name. */ @Override protected Enumeration<URL> findResources(final String name) throws IOException { ArrayList<URL> result = new ArrayList<URL>(2); final Iterator<FileObject> it = resources.iterator(); while (it.hasNext()) { final FileObject baseFile = it.next(); final FileObject file = baseFile.resolveFile(name, NameScope.DESCENDENT_OR_SELF); if (file.exists()) { result.add(new Resource(name, baseFile, file).getURL()); } } return Collections.enumeration(result); }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A003_exist() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net String currFileNameStr;//from w ww. ja va 2 s.c om DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); Boolean existRes = currFile.exists(); Assert.assertTrue(existRes); currFileNameStr = "non-existant-file-8632857264.tmp"; currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currAccountStr, currContainerStr, currFileNameStr); currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); existRes = currFile.exists(); Assert.assertFalse(existRes); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * By default FileObject.getChildren() will use doListChildrenResolved() if available * // w ww .j av a 2 s.co m * @throws Exception */ @Test public void A007_listChildren() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); SS3FileProvider currSS3 = new SS3FileProvider(); // Optional set endpoint //currSS3.setEndpoint(currHost); // Optional set region //currSS3.setRegion(currRegion); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currFileNameStr = "uploadFile02"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject[] currObjs = currFile.getChildren(); for (FileObject obj : currObjs) { FileName currName = obj.getName(); Boolean res = obj.exists(); FileType ft = obj.getType(); log.info(String.format("\nNAME.PATH : '%s'\nEXISTS : %b\nTYPE : %s\n\n", currName.getPath(), res, ft)); } }
From source file:com.flicklib.folderscanner.AdvancedFolderScanner.java
/** * Scans the folders/*from ww w . j ava2s .co m*/ * * @param folders * @return a List of MovieInfo * * TODO get rid of the synchronized and create a factory or pass all state data */ @Override public synchronized List<FileGroup> scan(final Set<FileObject> folders, AsyncMonitor monitor) { movies = new ArrayList<FileGroup>(); if (monitor != null) { monitor.start(); } for (FileObject folder : folders) { try { URL url = folder.getURL(); if (folder.exists()) { currentLabel = folder.getName().getBaseName(); LOGGER.info("scanning " + url); try { browse(folder, monitor); } catch (InterruptedException ie) { LOGGER.info("task is cancelled!" + ie.getMessage()); return null; } } else { LOGGER.warn("folder " + folder.getURL() + " does not exist!"); } } catch (FileSystemException e) { LOGGER.error("error during checking " + folder + ", " + e.getMessage(), e); } } if (monitor != null) { monitor.finish(); } return movies; }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java
public WGADesign getDesign(final String name) throws WGADesignRetrievalException { try {// w w w . j a v a2 s . com // Design archive (obsolete) if (name.startsWith(DESIGNNAMEPREFIX_ARCHIVE)) { String designName = name.substring(DESIGNNAMEPREFIX_ARCHIVE.length()); FileObject designFile = _dir.resolveFile(designName + ARCHIVED_DESIGN_EXTENSION); if (!designFile.exists()) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(name); design.setTitle(designFile.getName().getBaseName()); design.setDescription("Design at location " + designFile.getURL().toString()); return design; } // Additional directory else if (name.startsWith(DESIGNNAMEPREFIX_ADDITIONALDIR)) { String designName = name.substring(DESIGNNAMEPREFIX_ADDITIONALDIR.length()); String dirPath = _additionalDirs.get(designName); if (dirPath == null) { return null; } FileObject dir = VFS.getManager().resolveFile((String) dirPath); if (!dir.exists() || !dir.getType().equals(FileType.FOLDER)) { return null; } FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(dir); // Non-empty directories without syncinfo may not be used as design directories if (syncInfo == null && dir.getChildren().length != 0) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(DESIGNNAMEPREFIX_ADDITIONALDIR + name); design.setTitle(dir.getName().getBaseName()); design.setDescription("Design at location " + dir.getURL().toString()); design.setConfig(loadConfig(syncInfo)); design.setOverlayData(loadOverlayData(syncInfo)); return design; } // Regular design in configured directory else { _dir.refresh(); FileObject child = _dir.resolveFile(name); if (!child.exists()) { return null; } FileObject resolvedChild = WGUtils.resolveDirLink(child); if (!resolvedChild.getType().equals(FileType.FOLDER)) { return null; } FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(resolvedChild); // Non-empty directories without syncinfo may not be used as design directories if (syncInfo == null && child.getChildren().length != 0) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(child.getName().getBaseName()); design.setTitle(child.getName().getBaseName()); design.setDescription("Design at location " + child.getURL().toString()); design.setConfig(loadConfig(syncInfo)); design.setOverlayData(loadOverlayData(syncInfo)); return design; } } catch (FileSystemException e) { throw new WGADesignRetrievalException("Exception retrieving file system designs", e); } }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
private static void determineChangedResources(int resourceType, FileObject categoryFolder, FileObject source, FileObject target, FileObject baseFolder, String sourceEncoding, String targetEncoding, OverlayStatus status, Logger log, DesignFileValidator validator) throws WGDesignSyncException, NoSuchAlgorithmException, IOException { for (FileObject sourceFile : source.getChildren()) { if (!isValidDesignFile(sourceFile, validator)) { continue; }//w w w.j av a 2 s. c om FileObject targetFile = target.resolveFile(sourceFile.getName().getBaseName()); String resourcePath = baseFolder.getName().getRelativeName(targetFile.getName()); if (sourceFile.getType().equals(FileType.FOLDER)) { if (!targetFile.exists()) { status.getNewFolders().add(targetFile.getName().getPath()); } else if (targetFile.getType().equals(FileType.FILE)) { throw new WGDesignSyncException("Unable to apply overlay. Folder '" + baseFolder.getName().getRelativeName(targetFile.getName()) + " already exists as file. Delete it to enable overlay management again"); } determineChangedResources(resourceType, categoryFolder, sourceFile, targetFile, baseFolder, sourceEncoding, targetEncoding, status, log, validator); } else if (sourceFile.getType().equals(FileType.FILE)) { // File does not exist. if (!targetFile.exists()) { // Was it once deployed? ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { // No, so it must be new in base status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.NEW, resourcePath, null); } else { // Yes, Check if the base file changed since deployment String newHash = MD5HashingInputStream .getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { // Nope. So this is no change. The overlay just chose not to use the file continue; } else { // Yes, so it is indeed a conflict status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } } } // File does exist: Determine if is updated in base since the overlay file was deployed else { ResourceData originalHash = status.getOverlayData().getOverlayResources().get(resourcePath); if (originalHash == null) { if (!status.isUpdatedBaseDesign()) { log.info("There is no information about the original deployment state of resource " + resourcePath + ". Setting original deployment state now to the current base version."); OverlayData.ResourceData resource = new OverlayData.ResourceData(); resource.setMd5Hash( MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream())); status.getOverlayData().setOverlayResource(resourcePath, resource); } else { log.info("Cannot update overlay resource " + resourcePath + " as there is no information of its original deployment state."); } continue; } // First determine if the resource really changed from what was distributed String newHash = MD5HashingInputStream.getStreamHash(sourceFile.getContent().getInputStream()); if (newHash.equals(originalHash.getMd5Hash())) { continue; } // Determine if the target file is the same as was distributed. If not then it was user modified, so it is a conflict String currentHash = MD5HashingInputStream .getStreamHash(targetFile.getContent().getInputStream()); if (!currentHash.equals(originalHash.getMd5Hash())) { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CONFLICT, resourcePath, null); } // It is a normal change else { status.addChangedResource(resourceType, sourceFile, targetFile, categoryFolder, OverlayStatus.ChangeType.CHANGED, resourcePath, null); } } } } }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A003_exist() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;//from ww w . ja v a2 s .c o m SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); Boolean existRes = currFile.exists(); Assert.assertTrue(existRes); currFileNameStr = "non-existant-file-8632857264.tmp"; currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); existRes = currFile.exists(); Assert.assertFalse(existRes); }
From source file:fi.mystes.synapse.mediator.vfs.VfsFileTransferUtility.java
/** * Helper method to create lock file for multithreading. * /*from ww w . j av a 2s.com*/ * @param targetPath * Target file path * @return URI of lock file * @throws FileSystemException * If lock file creation fails */ private String createLockFile(String targetPath) throws FileSystemException { FileObject lockFile = resolveFile(lockFilePath(targetPath)); log.debug("About to create lock file: " + fileObjectNameForDebug(lockFile)); if (lockFile.exists()) { throw new FileSystemException("Lock file " + fileObjectNameForDebug(lockFile) + " already exists, refusing to create lock file"); } lockFile.createFile(); log.debug("Created lock file " + fileObjectNameForDebug(lockFile)); String uri = lockFile.getName().getURI(); lockFile.close(); return uri; }
From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java
@Override public boolean test() throws PublishException { FileObject root = null; try {//from www .j av a 2 s .c om root = getRootFileObject(); } catch (FileSystemException e) { logger.error("Test is fail:{}", e.toString()); throw new PublishException("error.output.notconnect"); } try { if (!root.exists()) { throw new PublishException("error.output.nodir"); } if (!root.isWriteable()) { throw new PublishException("error.output.notwrite"); } root.close(); return true; } catch (FileSystemException e) { logger.error("Test is fail:{}", e.toString()); return false; } }