public RepositoryManager() { try { fsManager = VFS.getManager(); } catch (FileSystemException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
protected void writeToURL(URL url, String json) throws FileNotFoundException, IOException { if (url.toExternalForm().startsWith("vfs")) { FileObject to = VFS.getManager().resolveFile(url.toExternalForm()); File tmpFile = File.createTempFile("xxFilexx", ".json"); FileUtils.writeStringToFile(tmpFile, json); FileObject from = VFS.getManager().toFileObject(tmpFile); to.copyFrom(from, new AllFileSelector()); FileUtils.deleteQuietly(tmpFile); } else { FileUtils.writeStringToFile(FileUtils.toFile(url), json); } }
protected void writeToURL(URL url, String json) throws FileNotFoundException, IOException { if (url.toExternalForm().startsWith("vfs")) { FileObject to = VFS.getManager().resolveFile(url.toExternalForm()); File tmpFile = File.createTempFile("xxFilexx", ".json"); FileUtils.writeStringToFile(tmpFile, json); FileObject from = VFS.getManager().toFileObject(tmpFile); to.copyFrom(from, new AllFileSelector()); FileUtils.deleteQuietly(tmpFile); } else { FileUtils.writeStringToFile(FileUtils.toFile(url), json); } }
protected String readURL(URL url) throws FileNotFoundException, IOException { if (url.toExternalForm().startsWith("vfs")) { FileObject from = VFS.getManager().resolveFile(url.toExternalForm()); return IOUtils.toString(from.getContent().getInputStream()); } else { return FileUtils.readFileToString(FileUtils.toFile(url)); } } }
protected String readURL(URL url) throws FileNotFoundException, IOException { if (url.toExternalForm().startsWith("vfs")) { FileObject from = VFS.getManager().resolveFile(url.toExternalForm()); return IOUtils.toString(from.getContent().getInputStream()); } else { return FileUtils.readFileToString(FileUtils.toFile(url)); } } }
protected void logout() throws TinkException, IOException { VFS.getManager().closeFileSystem(remote.getFileSystem()); }
/** * Constructor, creates instance of class. * * @param location location to resolve * @param parameters protocol specific parameters * @throws FileSystemException if an error occurs */ public CommonsVFSSource(final String location, final Map parameters) throws FileSystemException { m_location = location; m_manager = VFS.getManager(); m_fileObject = m_manager.resolveFile(location); // REVISIT: parameters m_fileContent = m_fileObject.getContent(); }
private void setupLocation() throws FileSystemException { ConfigLocation configLocation = coreConfigurationService.getConfigLocation(); monitoredDir = VFS.getManager().resolveFile(configLocation.getLocation()); fileMonitor.addFile(monitoredDir); LOGGER.info(String.format("Setting up monitoring for location: %s", monitoredDir)); }
/** * Private constructor to init the singleton. * * @throws FileManipulatorException in <code>FileManipulator</code> init failed. */ public FileManipulator() throws FileManipulatorException { try { LOGGER.debug( "Creating VFS file system manager ..." ); this.fileSystemManager = VFS.getManager(); // this.fileSystemManager = new StandardFileSystemManager(); // fileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL); ( (StandardFileSystemManager) this.fileSystemManager ).setReplicator( new KalumetFileReplicator() ); // fileSystemManager.init(); } catch ( Exception e ) { throw new FileManipulatorException( e ); } }
/** * Creates a VFS file handler with the default file system manager. */ public VFSFileHandler() { try { this.fileSystemManager = VFS.getManager(); } catch (FileSystemException e) { throw new CargoException("Failed to get VFS system manager", e); } }
/** * Constructor * * @param rootFileUrl */ public WebDAVRepository(String rootFileUrl) { try { this.setFsManager(VFS.getManager()); this.root = this.fsManager.resolveFile(rootFileUrl); this.fsManager.createFileSystem(root); } catch (FileSystemException e) { e.printStackTrace(); } }
public static URI extractResourceDir(String dirname, boolean overwrite) throws FileSystemException, URISyntaxException { URL dir_url = EmbeddedJettyServer.class.getClassLoader().getResource(dirname); FileObject dir_jar = VFS.getManager().resolveFile(dir_url.toString()); String tempDir = FileUtils.getTempDirectory() + File.separator + System.getProperty("user.name").replace(" ", ""); FileObject tmpF = VFS.getManager().resolveFile(tempDir); FileObject localDir = tmpF.resolveFile(dirname); if (!localDir.exists()) { logger.info("Extracting directory " + dirname + " to " + tmpF.getName()); localDir.createFolder(); localDir.copyFrom(dir_jar, new AllFileSelector()); } else { if (overwrite) { logger.info("Overwritting directory " + dirname + " in " + tmpF.getName()); localDir.delete(new FileDepthSelector(0, 5)); localDir.createFolder(); localDir.copyFrom(dir_jar, new AllFileSelector()); } } resourceURI = localDir.getURL().toURI(); return resourceURI; }
/** * Constructor * * @param rootFileUrl * The root directory of the repository. */ public LocalRepository(String rootFileUrl) { try { this.setFsManager(VFS.getManager()); this.root = this.fsManager.resolveFile(rootFileUrl); this.fsManager.createFileSystem(root); } catch (FileSystemException e) { e.printStackTrace(); } }
public static URI extractResourceDir(String dirname, boolean overwrite) throws FileSystemException, URISyntaxException { URL dir_url = EmbeddedJettyServer.class.getClassLoader().getResource(dirname); FileObject dir_jar = VFS.getManager().resolveFile(dir_url.toString()); String tempDir = FileUtils.getTempDirectory() + File.separator + System.getProperty("user.name").replace(" ", ""); FileObject tmpF = VFS.getManager().resolveFile(tempDir); FileObject localDir = tmpF.resolveFile(dirname); if (!localDir.exists()) { logger.info("Extracting directory " + dirname + " to " + tmpF.getName()); localDir.createFolder(); localDir.copyFrom(dir_jar, new AllFileSelector()); } else { if (overwrite) { logger.info("Overwritting directory " + dirname + " in " + tmpF.getName()); localDir.delete(new FileDepthSelector(0, 5)); localDir.createFolder(); localDir.copyFrom(dir_jar, new AllFileSelector()); } } resourceURI = localDir.getURL().toURI(); return resourceURI; }
protected void login() throws TinkException, IOException { URI location = getConfig().getRemote(); StaticUserAuthenticator auth = new StaticUserAuthenticator(null, getConfig().getUser(), getConfig().getPassword()); FileSystemOptions opts = new FileSystemOptions(); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); remote = VFS.getManager().resolveFile(location.toString(), opts); }
/** * Extracts the archive file {@code archiveFile} to {@code targetFolder}; both shall previously * exist. */ public void extractTo(File archiveFile, File targetFolder) throws IOException { FileSystemManager manager = VFS.getManager(); String sourceURI = resolveArchiveURI(archiveFile); // String targetURI = resolveArchiveURI(targetFolder); FileObject source = manager.resolveFile(sourceURI); if (manager.canCreateFileSystem(source)) { source = manager.createFileSystem(source); } FileObject target = manager.createVirtualFileSystem(manager.resolveFile(targetFolder .getAbsolutePath())); FileSelector selector = new AllFileSelector() { @Override public boolean includeFile(FileSelectInfo fileInfo) { LOGGER.fine("Uncompressing " + fileInfo.getFile().getName().getFriendlyURI()); return true; } }; target.copyFrom(source, selector); source.close(); manager.closeFileSystem(source.getFileSystem()); }
/** * Attaches this file object to its file resource. */ protected void doAttach() throws Exception { if (file == null) { LayeredFileName layeredFileName = (LayeredFileName) getName(); String fileName = layeredFileName.getOuterName().getRootURI() + layeredFileName.getOuterName().getPathDecoded(); FileObject outer = getFileSystem().resolveFile(fileName); if (outer instanceof TruezipFileObject) { fileName = layeredFileName.getOuterName().getPathDecoded() + getName().getPathDecoded(); file = new File(fileName, ArchiveDetector.ALL); } else { fileObject = outer; DefaultFileSystemManager dfsMgr = (DefaultFileSystemManager) VFS.getManager(); file = new File(dfsMgr.getTemporaryFileStore().allocateFile(getName().getBaseName())); } } }
/** * Test the creation of a config directory when the target directory exists and is empty. * @throws Exception If anything goes wrong. */ public void testCreateConfigDirWhenDirectoryExistButIsEmpty() throws Exception { String configDir = "ram:///cargo/testCreateConfigDirWhenDirectoryExistButIsEmpty"; FileObject configDirObject = VFS.getManager().resolveFile(configDir); FileObject timestampFileObject = configDirObject.resolveFile(".cargo"); configDirObject.createFolder(); TestableAbstractStandaloneConfiguration configuration = new TestableAbstractStandaloneConfiguration(configDir); configuration.setFileHandler(new VFSFileHandler()); configuration.setupConfigurationDir(); assertTrue("Cargo timestamp should have existed", timestampFileObject.exists()); }
/** * Test the creation of a config directory when the target directory exists and is not empty. * @throws Exception If anything goes wrong. */ public void testCreateConfigDirWhenDirectoryNotEmpty() throws Exception { String configDir = "ram:///cargo/testCreateConfigDirWhenDirectoryNotEmpty"; FileObject configDirObject = VFS.getManager().resolveFile(configDir); configDirObject.resolveFile("somefile").createFile(); TestableAbstractStandaloneConfiguration configuration = new TestableAbstractStandaloneConfiguration(configDir); configuration.setFileHandler(new VFSFileHandler()); try { configuration.setupConfigurationDir(); fail("Should have thrown a ContainerException as the directory is not empty"); } catch (ContainerException expected) { assertEquals("Invalid configuration dir " + "[ram:///cargo/testCreateConfigDirWhenDirectoryNotEmpty]. When using standalone " + "configurations, the configuration dir must point to an empty directory. Note " + "that everything in that dir will get deleted by Cargo.", expected.getMessage()); } }
/** * Test the creation of a config directory when the target directory does not exist yet. * @throws Exception If anything goes wrong. */ public void testCreateConfigDirWhenDirectoryDoesNotExist() throws Exception { String configDir = "ram:///cargo/testCreateConfigDirWhenDirectoryDoesNotExist"; FileObject configDirObject = VFS.getManager().resolveFile(configDir); FileObject timestampFileObject = configDirObject.resolveFile(".cargo"); configDirObject.delete(new AllFileSelector()); TestableAbstractStandaloneConfiguration configuration = new TestableAbstractStandaloneConfiguration(configDir); configuration.setFileHandler(new VFSFileHandler()); configuration.setupConfigurationDir(); assertTrue("Config dir should have been created", configDirObject.exists()); assertTrue("Cargo timestamp should have existed", timestampFileObject.exists()); }