List of usage examples for org.apache.commons.vfs2 FileSystemManager toFileObject
FileObject toFileObject(File file) throws FileSystemException;
From source file:org.fuin.vfs2.filter.examples.PrefixFileFilterExample.java
public static void main(String[] args) throws Exception { // Example, to print all files and directories in the current directory // whose name starts with a <code>.</code> FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(new PrefixFileFilter("."))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }//from w ww. j a v a 2 s . co m }
From source file:org.fuin.vfs2.filter.examples.RegexFileFilterExample.java
public static void main(String[] args) throws Exception { // Example, to retrieve and print all java files where the name matched // the regular expression in the current directory FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir//from ww w.j ava2 s .co m .findFiles(new FileFilterSelector(new RegexFileFilter(".*[tT]est(-\\d+)?\\.java$"))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } }
From source file:org.fuin.vfs2.filter.examples.SizeFileFilterExample.java
public static void main(String[] args) throws Exception { // Example, to print all files and directories in the current directory // whose size is greater than 1 MB FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); SizeFileFilter filter = new SizeFileFilter(1024 * 1024); FileObject[] files = dir.findFiles(new FileFilterSelector(filter)); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }/* ww w . j av a 2 s .c o m*/ }
From source file:org.fuin.vfs2.filter.examples.SuffixFileFilterExample.java
public static void main(String[] args) throws Exception { // Example, to retrieve and print all *.java files in the current // directory/*from ww w. j ava 2 s.c o m*/ FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(new SuffixFileFilter(".java"))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); } }
From source file:org.fuin.vfs2.filter.examples.WildcardFileFilterExample.java
public static void main(String[] args) throws Exception { // Example, to retrieve and print all java files that have the // expression test in the name in the current directory FileSystemManager fsManager = VFS.getManager(); FileObject dir = fsManager.toFileObject(new File(".")); FileObject[] files = dir.findFiles(new FileFilterSelector(new WildcardFileFilter("*test*.java"))); for (int i = 0; i < files.length; i++) { System.out.println(files[i]); }// ww w.j a v a2s . c om }
From source file:org.kalypso.commons.io.VFSUtilities.java
/** * Moves the complete content of one directory into another. * * @throws IOException/*from w ww .j a v a2 s. c o m*/ * If the move failed. */ public static void moveContents(final File sourceDir, final File dest) throws IOException { final FileSystemManager vfsManager = VFSUtilities.getManager(); final FileObject source = vfsManager.toFileObject(sourceDir); final FileObject destDir = vfsManager.toFileObject(dest); final FileObject[] findFiles = source.findFiles(new AllFileSelector()); // Might happen, if source does not exists... shouldn't we check this? if (findFiles == null) return; for (final FileObject fileObject : findFiles) { if (FileType.FILE.equals(fileObject.getType())) { final String relPath = source.getName().getRelativeName(fileObject.getName()); final FileObject destFile = destDir.resolveFile(relPath, NameScope.DESCENDENT_OR_SELF); final FileObject folder = destFile.getParent(); folder.createFolder(); fileObject.moveTo(destFile); } } }
From source file:org.kalypso.service.wps.client.simulation.SimulationDelegate.java
/** * This function creates the inputs for the server. It will also copy the data to the right place, if needed and * ajdust the references according to it. * * @param description//from w w w .ja v a 2 s . co m * The process description type. * @param monitor * A progress monitor. * @return The inputs. */ public Map<String, Object> createInputs(final ProcessDescriptionType description, IProgressMonitor monitor) throws CoreException { /* Monitor. */ if (monitor == null) { monitor = new NullProgressMonitor(); } try { /* Monitor. */ monitor.beginTask(Messages.getString("org.kalypso.service.wps.client.simulation.SimulationDelegate.7"), //$NON-NLS-1$ 500); KalypsoServiceWPSDebug.DEBUG.printf("Collecting data ...\n"); //$NON-NLS-1$ /* Need the filesystem manager. */ final FileSystemManager fsManager = m_fsManager; /* Get the list with the input. */ final Map<String, Object> wpsInputs = new HashMap<>(); /* Get the input list. */ final DataInputs dataInputs = description.getDataInputs(); final List<InputDescriptionType> inputDescriptions = dataInputs.getInput(); /* Create a resource visitor. */ final CollectFilesVisitor visitor = new CollectFilesVisitor(); /* Get the inputs. */ final List<Input> inputList = m_data.getInput(); /* Iterate over all inputs and build the data inputs for the execute request. */ for (final InputDescriptionType inputDescription : inputDescriptions) { final CodeType identifier = inputDescription.getIdentifier(); /* Check if the input is in our model data, too. */ final Input input = SimulationUtilities.findInput(identifier.getValue(), inputList); if (input == null) { /* Check, if it is an optional one. */ if (inputDescription.getMinimumOccurs().intValue() == 1) { /* Ooops, it is a mandatory one, but it is missing in our model data. */ final IStatus status = StatusUtilities.createStatus(IStatus.ERROR, Messages.getString("org.kalypso.service.wps.client.simulation.SimulationDelegate.8", //$NON-NLS-1$ identifier.getValue()), null); throw new CoreException(status); } continue; } /* Input is here. */ final String inputPath = input.getPath(); /* Supported complex data type. */ final SupportedComplexDataType complexData = inputDescription.getComplexData(); if (complexData != null) { /* Get the protocol if it is one. */ final String protocol = SimulationUtilities.getProtocol(inputPath); /* If the protocol is null, it is a local file resource, otherwise it is a remote resource, */ /* which is not allowed to be copied or it is a complex value type (file-protocol). */ if ("file".equals(protocol)) //$NON-NLS-1$ { // TODO: Why do we need this? final URL localFileUrl = new URL(inputPath); final byte[] bytes = UrlUtilities.toByteArray(localFileUrl); final String hexString = DatatypeConverter.printHexBinary(bytes); wpsInputs.put(identifier.getValue(), hexString); continue; } else if (protocol == null || protocol.equals("project") || protocol.equals("platform")) //$NON-NLS-1$ //$NON-NLS-2$ { /* If protocol is null or protocol is "project", it is a local file resource. */ /* * If protocol is "platform", it is a resource from another project, but the same platform (i.e. same * eclipse workspace). */ if (m_calcCaseFolder == null) { throw new WPSException(Messages .getString("org.kalypso.service.wps.client.simulation.SimulationDelegate.9")); //$NON-NLS-1$ } final IProject project = m_calcCaseFolder.getProject(); final IResource inputResource; if (protocol != null && protocol.equals(PlatformURLHandler.PROTOCOL)) { final IContainer baseresource = project.getWorkspace().getRoot(); final String path = ResourceUtilities.findPathFromURL(new URL(inputPath)) .toPortableString(); inputResource = baseresource.findMember(path); } else { final IContainer baseresource = input.isRelativeToCalcCase() ? m_calcCaseFolder : project; inputResource = baseresource.findMember(inputPath); } if (inputResource == null) { if (inputDescription.getMinimumOccurs().intValue() == 0) { continue; } throw new CoreException(StatusUtilities.createErrorStatus(Messages.getString( "org.kalypso.service.wps.client.simulation.SimulationDelegate.10", inputPath))); //$NON-NLS-1$ } /* Collect all files. */ inputResource.accept(visitor); /* Initialize the temporary directory. */ initServerTmpDirectory(); /* Build the URL for this input. */ /* Resource will be copied to server later (for example see SimulationDelegate.copyInputFiles). */ final String relativePathTo = inputResource.getFullPath().makeRelative().toString(); /** * just put the existing resource to the inputs and DO NOT copy it in case of local calculation!! also * prevent the creation of redundant data in base project folder */ FileObject destination = fsManager.toFileObject(inputResource.getLocation().toFile()); if (!SERVER_INPUT_LOCAL.equals(m_input)) { destination = fsManager.resolveFile(m_serverTmpDirectory, relativePathTo); } final String serverUrl = WPSUtilities .convertInternalToServer(destination.getURL().toExternalForm(), m_input); wpsInputs.put(identifier.getValue(), new URI(URIUtil.encodePath(serverUrl))); } else // maybe check the protocols? { // Remote resource, will be passed to the service as reference final URL clientUrl = new URL(inputPath); final String serverUrl = WPSUtilities.convertInternalToServer(clientUrl.toExternalForm(), m_input); wpsInputs.put(identifier.getValue(), new URI(serverUrl)); } } /* Literal input type */ final LiteralInputType literalInput = inputDescription.getLiteralData(); if (literalInput != null) { /* Add the input. */ // TODO: normally we should marshall the string to the requested type // (the WPS-Client will unmarshall it again). // For the moment this works, as the WPS-Client just forwards any strings. wpsInputs.put(identifier.getValue(), inputPath); continue; } /* Supported CRSs type. */ final SupportedCRSsType supportedCRSsType = inputDescription.getBoundingBoxData(); if (supportedCRSsType != null) { // TODO Add supported CRSs type (bounding boxes). continue; } } /* Monitor. */ monitor.worked(200); monitor.setTaskName( Messages.getString("org.kalypso.service.wps.client.simulation.SimulationDelegate.11")); //$NON-NLS-1$ KalypsoServiceWPSDebug.DEBUG.printf("Copy to the server ...\n"); //$NON-NLS-1$ /* Copy all collected files. */ final IFile[] files = visitor.getFiles(); if (files.length > 0) copyInputFiles(files); /* Monitor. */ monitor.worked(300); return wpsInputs; } catch (final CoreException ex) { throw ex; } catch (final Exception ex) { throw new CoreException(StatusUtilities.createStatus(IStatus.ERROR, Messages.getString("org.kalypso.service.wps.client.simulation.SimulationDelegate.12"), ex)); //$NON-NLS-1$ } finally { /* Monitor. */ monitor.done(); } }
From source file:org.pentaho.reporting.engine.classic.extensions.datasources.mondrian.SchemaResolver.java
public static String resolveSchema(final ResourceManager resourceManager, final ResourceKey contextKey, String catalogUrl) throws FileSystemException { final FileSystemManager fsManager = VFS.getManager(); if (fsManager == null) { throw Util.newError("Cannot get virtual file system manager"); }//from ww w .j a v a2 s .c o m // Workaround VFS bug. if (catalogUrl.startsWith("file://localhost")) { catalogUrl = catalogUrl.substring("file://localhost".length()); } if (catalogUrl.startsWith("file:")) { catalogUrl = catalogUrl.substring("file:".length()); } try { final File catalogFile = new File(catalogUrl).getCanonicalFile(); final FileObject file = fsManager.toFileObject(catalogFile); if (file.isReadable()) { return catalogFile.getPath(); } } catch (FileSystemException fse) { logger.info("Failed to resolve schema file '" + catalogUrl + "' as local file. Treating file as non-readable.", fse); } catch (IOException e) { logger.info("Failed to resolve schema file '" + catalogUrl + "' as local file. Treating file as non-readable.", e); } if (contextKey == null) { return catalogUrl; } final File contextAsFile = getContextAsFile(contextKey); if (contextAsFile == null) { return catalogUrl; } final File resolvedFile = new File(contextAsFile.getParentFile(), catalogUrl); if (resolvedFile.isFile() && resolvedFile.canRead()) { return resolvedFile.getAbsolutePath(); } return catalogUrl; }
From source file:org.renjin.packaging.InitializingPackage.java
@Override public FileObject resolvePackageRoot(FileSystemManager fileSystemManager) throws FileSystemException { return fileSystemManager.toFileObject(packageRoot); }