/** * Locates the local file provider. * <p> * The local file provider is the first {@linkplain #addProvider(String[], FileProvider) provider added} * implementing {@link LocalFileProvider}. * * @return The LocalFileProvider. * @throws FileSystemException if no local file provider was set. */ private LocalFileProvider getLocalFileProvider() throws FileSystemException { return FileSystemException.requireNonNull(localFileProvider, "vfs.impl/no-local-file-provider.error"); }
/** * Returns the file replicator. * * @return The file replicator. Never returns null. * @throws FileSystemException if there is no FileReplicator. */ public FileReplicator getReplicator() throws FileSystemException { return FileSystemException.requireNonNull(fileReplicator, "vfs.impl/no-replicator.error"); }
/** * Returns the temporary file store. * * @return The file store. Never returns null. * @throws FileSystemException if there is no TemporaryFileStore. */ public TemporaryFileStore getTemporaryFileStore() throws FileSystemException { return FileSystemException.requireNonNull(tempFileStore, "vfs.impl/no-temp-file-store.error"); }
/** * Get the capabilities for a given scheme. * * @param scheme The scheme to located. * @return A Collection of capabilities. * @throws FileSystemException if the given scheme is not konwn */ @Override public Collection<Capability> getProviderCapabilities(final String scheme) throws FileSystemException { final FileProvider provider = providers.get(scheme); FileSystemException.requireNonNull(provider, "vfs.impl/unknown-scheme.error", scheme); return provider.getCapabilities(); }
/** * Get the configuration builder for the given scheme. * * @param scheme The scheme to locate. * @return The FileSystemConfigBuilder for the scheme. * @throws FileSystemException if the given scheme is not konwn */ @Override public FileSystemConfigBuilder getFileSystemConfigBuilder(final String scheme) throws FileSystemException { final FileProvider provider = providers.get(scheme); FileSystemException.requireNonNull(provider, "vfs.impl/unknown-scheme.error", scheme); return provider.getConfigBuilder(); }
@Override protected long doGetLastModifiedTime() throws Exception { FileSystemException.requireNonNull(lastHeadResponse, "vfs.provider.http/last-modified.error", getName()); final Header header = lastHeadResponse.getFirstHeader("Last-Modified"); FileSystemException.requireNonNull(header, "vfs.provider.http/last-modified.error", getName()); return DateUtils.parseDate(header.getValue()).getTime(); }
/** * @param operationClass The Class that performs the operation. * @return The FileOperation. * @throws FileSystemException if an error occurs. */ @Override public FileOperation getOperation(final Class<? extends FileOperation> operationClass) throws FileSystemException { final String scheme = fileObject.getURL().getProtocol(); final FileOperationProvider[] providers = fsmanager.getOperationProviders(scheme); FileSystemException.requireNonNull(providers, "vfs.operation/operation-not-supported.error", operationClass); FileOperation resultOperation = null; for (final FileOperationProvider provider : providers) { resultOperation = provider.getOperation(fileObject, operationClass); if (resultOperation != null) { break; } } return FileSystemException.requireNonNull(resultOperation, "vfs.operation/operation-not-supported.error", operationClass); }
/** * Creates a layered file system. * * @param file The FileObject to use. * @return The layered FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject createFileSystem(final FileObject file) throws FileSystemException { final String scheme = typeMap.getScheme(file); FileSystemException.requireNonNull(scheme, "vfs.impl/no-provider-for-file.error", file); return createFileSystem(scheme, file); }
FileSystemException.requireNonNull(fscb, "vfs.provider/no-config-builder.error", scheme);
/** * Returns the last modified time of this file. * <p> * This implementation throws an exception. */ @Override protected long doGetLastModifiedTime() throws Exception { final Header header = method.getResponseHeader("last-modified"); FileSystemException.requireNonNull(header, "vfs.provider.http/last-modified.error", getName()); return DateUtil.parseDate(header.getValue()).getTime(); }
/** * Creates a layered file system. * * @param scheme The scheme to use. * @param file The FileObject. * @return The layered FileObject. * @throws FileSystemException if an error occurs. */ @Override public FileObject createFileSystem(final String scheme, final FileObject file) throws FileSystemException { final FileProvider provider = providers.get(scheme); FileSystemException.requireNonNull(provider, "vfs.impl/unknown-provider.error", scheme, file); return provider.createFileSystem(scheme, file, file.getFileSystem().getFileSystemOptions()); }
/** * 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()); }
/** * Add a child. * * @param data The file data. * @throws FileSystemException if an error occurs. */ void addChild(final RamFileData data) throws FileSystemException { if (!this.getType().hasChildren()) { throw new FileSystemException("A child can only be added in a folder"); } FileSystemException.requireNonNull(data, "No child can be null"); if (this.children.contains(data)) { throw new FileSystemException("Child already exists. " + data); } this.children.add(data); updateLastModified(); }
/** * Initializes this manager. Adds the providers and replicator. * * @throws FileSystemException if an error occurs. */ @Override public void init() throws FileSystemException { // Set the replicator and temporary file store (use the same component) final DefaultFileReplicator replicator = createDefaultFileReplicator(); setReplicator(new PrivilegedFileReplicator(replicator)); setTemporaryFileStore(replicator); if (configUri == null) { // Use default config final URL url = getClass().getResource(CONFIG_RESOURCE); FileSystemException.requireNonNull(url, "vfs.impl/find-config-file.error", CONFIG_RESOURCE); configUri = url; } configure(configUri); configurePlugins(); // Initialise super-class super.init(); }
FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri); return defaultProvider.parseUri(null, uri); FileSystemException.requireNonNull(baseFile, "vfs.impl/find-rel-file.error", uri);
public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException { FileSystemException.requireNonNull(base, "Invalid base FileName."); FileSystemException.requireNonNull(name, "Invalid name FileName."); final FileName realBase; if (VFS.isUriStyle() && base.isFile()) {
FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri); return defaultProvider.findFile(realBaseFile, uri, fileSystemOptions); FileSystemException.requireNonNull(realBaseFile, "vfs.impl/find-rel-file.error", uri);
FtpInputStream getInputStream(final long filePointer) throws IOException { final FtpClient client = getAbstractFileSystem().getClient(); try { final InputStream instr = client.retrieveFileStream(relPath, filePointer); FileSystemException.requireNonNull(instr, "vfs.provider.ftp/input-error.debug", this.getName(), client.getReplyString()); return new FtpInputStream(client, instr); } catch (final IOException e) { getAbstractFileSystem().putClient(client); throw e; } }
/** * Delete a file * * @param file * @throws FileSystemException */ void delete(final RamFileObject file) throws FileSystemException { // root is read only check FileSystemException.requireNonNull(file.getParent(), "unable to delete root"); // Remove reference from cache this.cache.remove(file.getName()); // Notify the parent final RamFileObject parent = (RamFileObject) this.resolveFile(file.getParent().getName()); parent.getData().removeChild(file.getData()); parent.close(); // Close the file file.getData().clear(); file.close(); }
/** * Creates an output stream to write the file content to. */ @Override protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { final FtpClient client = getAbstractFileSystem().getClient(); try { OutputStream out = null; if (bAppend) { out = client.appendFileStream(relPath); } else { out = client.storeFileStream(relPath); } FileSystemException.requireNonNull(out, "vfs.provider.ftp/output-error.debug", this.getName(), client.getReplyString()); return new FtpOutputStream(client, out); } catch (final Exception e) { getAbstractFileSystem().putClient(client); throw e; } }