/** * Check if filename starts with one of the known protocols like file: zip: ram: smb: jar: etc. * If yes, return true otherwise return false * @param vfsFileName * @return boolean */ public static boolean startsWithScheme( String vfsFileName ) { FileSystemManager fsManager = getInstance().getFileSystemManager(); boolean found = false; String[] schemes = fsManager.getSchemes(); for ( int i = 0; i < schemes.length; i++ ) { if ( vfsFileName.startsWith( schemes[ i ] + ":" ) ) { found = true; break; } } return found; }
String[] schemes = fsManager.getSchemes(); for ( int i = 0; i < schemes.length && relativeFilename; i++ ) { if ( vfsFilename.startsWith( schemes[i] + ":" ) ) {
FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager(); if ( fsm instanceof DefaultFileSystemManager ) { if ( !Arrays.asList( fsm.getSchemes() ).contains( GoogleDriveFileProvider.SCHEME ) ) { ( (DefaultFileSystemManager) fsm ) .addProvider( GoogleDriveFileProvider.SCHEME, new GoogleDriveFileProvider() );
private VFSWrapper() throws FileSystemException { fsManager = VFS.getManager(); prefixes = new HashSet<>(Arrays.asList(fsManager.getSchemes())); }
private void info(final String[] cmd) throws Exception { if (cmd.length > 1) { info(cmd[1]); } else { System.out.println( "Default manager: \"" + mgr.getClass().getName() + "\" " + "version " + getVersion(mgr.getClass())); final String[] schemes = mgr.getSchemes(); final List<String> virtual = new ArrayList<>(); final List<String> physical = new ArrayList<>(); for (String scheme : schemes) { final Collection<Capability> caps = mgr.getProviderCapabilities(scheme); if (caps != null) { if (caps.contains(Capability.VIRTUAL) || caps.contains(Capability.COMPRESS) || caps.contains(Capability.DISPATCHER)) { virtual.add(scheme); } else { physical.add(scheme); } } } if (!physical.isEmpty()) { System.out.println(" Provider Schemes: " + physical); } if (!virtual.isEmpty()) { System.out.println(" Virtual Schemes: " + virtual); } } }
@Override public URL run() throws MalformedURLException, FileSystemException { final StringBuilder buf = new StringBuilder(); final String scheme = UriParser.extractScheme(VFS.getManager().getSchemes(), fileName.getURI(), buf); return new URL(scheme, "", -1, buf.toString(), new DefaultURLStreamHandler(fileSystem.getContext(), fileSystem.getFileSystemOptions())); } });
@Override public void onEnvironmentInit() throws LifecycleException { try { // Register S3 as a file system type with VFS FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager(); if ( fsm instanceof DefaultFileSystemManager ) { if ( !Arrays.asList( fsm.getSchemes() ).contains( S3FileProvider.SCHEME ) ) { ( (DefaultFileSystemManager) fsm ).addProvider( S3FileProvider.SCHEME, new S3FileProvider() ); } } } catch ( FileSystemException e ) { log.logError( BaseMessages.getString( PKG, "AmazonSpoonPlugin.StartupError.FailedToLoadS3Driver" ) ); } }
/** * Locates a file object, by absolute URI. * * @param baseFile The base FileObject. * @param uri The file to find. * @param fileSystemOptions The options for the FileSystem. * @return A FileObject for the located file. * @throws FileSystemException if an error occurs. */ @Override public FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions) throws FileSystemException { final StringBuilder buf = new StringBuilder(INITIAL_BUFSZ); UriParser.extractScheme(VFS.getManager().getSchemes(), uri, buf); final String[] schemes = getSchemes(); for (final String scheme : schemes) { buf.insert(0, ":"); buf.insert(0, scheme); } final FileObject fo = getContext().getFileSystemManager().resolveFile(buf.toString(), fileSystemOptions); return fo; } }
@Override public void onEnvironmentInit() throws LifecycleException { try { // Register S3 as a file system type with VFS FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager(); if ( fsm instanceof DefaultFileSystemManager ) { if ( !Arrays.asList( fsm.getSchemes() ).contains( S3NFileProvider.SCHEME ) ) { ( (DefaultFileSystemManager) fsm ).addProvider( S3NFileProvider.SCHEME, new S3NFileProvider() ); } } } catch ( FileSystemException e ) { log.logError( BaseMessages.getString( PKG, "AmazonSpoonPlugin.StartupError.FailedToLoadS3Driver" ) ); } }
/** * Locates a file object, by absolute URI. * * @param baseFile The base file. * @param uri The URI of the file to locate. * @param fileSystemOptions The FileSystem options. * @return the FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions) throws FileSystemException { final StringBuilder buf = new StringBuilder(BUFFER_SIZE); UriParser.extractScheme(VFS.getManager().getSchemes(), uri, buf); final String resourceName = buf.toString(); ClassLoader classLoader = ResourceFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions); if (classLoader == null) { classLoader = getClass().getClassLoader(); } FileSystemException.requireNonNull(classLoader, "vfs.provider.url/badly-formed-uri.error", uri); final URL url = classLoader.getResource(resourceName); FileSystemException.requireNonNull(url, "vfs.provider.url/badly-formed-uri.error", uri); return getContext().getFileSystemManager().resolveFile(url.toExternalForm()); }
@Override public FileName parseUri(final VfsComponentContext context, final FileName base, final String uri) throws FileSystemException { final StringBuilder name = new StringBuilder(); // Extract the scheme String scheme = UriParser.extractScheme(context.getFileSystemManager().getSchemes(), uri, name); if (scheme == null) { scheme = "file"; } // Remove encoding, and adjust the separators UriParser.canonicalizePath(name, 0, name.length(), this); UriParser.fixSeparators(name); // Extract the root prefix final String rootFile = extractRootPrefix(uri, name); // Normalise the path final FileType fileType = UriParser.normalisePath(name); final String path = name.toString(); return createFileName(scheme, rootFile, path, fileType); }
auth.scheme = UriParser.extractScheme(VFS.getManager().getSchemes(), uri, name);
/** * Parse the base and name into a FileName. * * @param context The component context. * @param base The base FileName. * @param filename The target file name. * @return The constructed FileName. * @throws FileSystemException if an error occurs. */ @Override public FileName parseUri(final VfsComponentContext context, final FileName base, final String filename) throws FileSystemException { final StringBuilder name = new StringBuilder(); // Extract the scheme final String scheme = UriParser.extractScheme(VFS.getManager().getSchemes(), filename, name); // Extract the Layered file URI final String rootUriName = extractRootName(name); FileName rootUri = null; if (rootUriName != null) { rootUri = context.parseURI(rootUriName); } // Decode and normalise the path UriParser.canonicalizePath(name, 0, name.length(), this); UriParser.fixSeparators(name); final FileType fileType = UriParser.normalisePath(name); final String path = name.toString(); return new LayeredFileName(scheme, rootUri, path, fileType); }
@Override protected void parseURL(final URL u, final String spec, final int start, final int limit) { try { final FileObject old = context.resolveFile(u.toExternalForm(), fileSystemOptions); FileObject newURL; if (start > 0 && spec.charAt(start - 1) == ':') { newURL = context.resolveFile(old, spec, fileSystemOptions); } else { if (old.isFile() && old.getParent() != null) { // for files we have to resolve relative newURL = old.getParent().resolveFile(spec); } else { newURL = old.resolveFile(spec); } } final String url = newURL.getName().getURI(); final StringBuilder filePart = new StringBuilder(); final String protocolPart = UriParser.extractScheme(VFS.getManager().getSchemes(), url, filePart); setURL(u, protocolPart, "", -1, null, null, filePart.toString(), null, null); } catch (final FileSystemException fse) { // This is rethrown to MalformedURLException in URL anyway throw new RuntimeException(fse.getMessage()); } }
final String scheme = UriParser.extractScheme(VFS.getManager().getSchemes(), uri, buffer); UriParser.fixSeparators(buffer); UriParser.normalisePath(buffer);