From c2845b9e4b10bc53f3b7200b497edaeeaf87c9fa Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 12 Aug 2024 08:43:16 -0400 Subject: [PATCH] Javadoc Better private instance variable names --- .../commons/vfs2/cache/DefaultFilesCache.java | 12 +++++-- .../vfs2/impl/DefaultFileReplicator.java | 29 +++++++++++++---- .../vfs2/impl/DefaultFileSystemManager.java | 5 +++ .../vfs2/provider/AbstractFileName.java | 10 ++++++ .../vfs2/provider/AbstractFileObject.java | 8 +++-- .../vfs2/provider/AbstractFileProvider.java | 18 ++++++++--- .../vfs2/provider/AbstractFileSystem.java | 7 ++++ .../provider/AbstractRandomAccessContent.java | 5 +++ .../AbstractRandomAccessStreamContent.java | 11 +++++++ .../compressed/CompressedFileFileObject.java | 5 +++ .../CompressedFileFileProvider.java | 9 ++++++ .../vfs2/provider/ftp/FTPClientWrapper.java | 32 +++++++++++++------ .../vfs2/provider/ftp/FtpClientFactory.java | 14 ++++++++ .../vfs2/provider/http/HttpFileSystem.java | 5 +++ .../provider/local/LocalFileNameParser.java | 11 ++++++- .../vfs2/provider/zip/ZipFileSystem.java | 4 +-- .../commons/vfs2/util/CombinedResources.java | 14 +++++++- .../DelegatingFileSystemOptionsBuilder.java | 5 +++ 18 files changed, 175 insertions(+), 29 deletions(-) diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java index 19db612b17..00fe303a4b 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/DefaultFilesCache.java @@ -76,11 +76,17 @@ public FileObject getFile(final FileSystem filesystem, final FileName name) { return files.get(name); // or null } - protected ConcurrentMap getOrCreateFilesystemCache(final FileSystem filesystem) { - ConcurrentMap files = fileSystemCache.get(filesystem); + /** + * Gets or creates a Map. + * + * @param fileSystem the key + * @return an existing or new Map. + */ + protected ConcurrentMap getOrCreateFilesystemCache(final FileSystem fileSystem) { + ConcurrentMap files = fileSystemCache.get(fileSystem); // we loop to make sure we never return null even when concurrent clean is called while (files == null) { - files = fileSystemCache.computeIfAbsent(filesystem, + files = fileSystemCache.computeIfAbsent(fileSystem, k -> new ConcurrentHashMap<>(INITIAL_CAPACITY, LOAD_FACTOR, Math.max(2, Runtime.getRuntime().availableProcessors()) / 2)); } return files; diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileReplicator.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileReplicator.java index 1dc2e942c2..ac25cf4d9f 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileReplicator.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileReplicator.java @@ -37,6 +37,7 @@ * A simple file replicator and temporary file store. */ public class DefaultFileReplicator extends AbstractVfsComponent implements FileReplicator, TemporaryFileStore { + private static final Log log = LogFactory.getLog(DefaultFileReplicator.class); private static final int MASK = 0xffff; @@ -45,7 +46,7 @@ public class DefaultFileReplicator extends AbstractVfsComponent implements FileR private static final char[] TMP_RESERVED_CHARS = {'?', '/', '\\', ' ', '&', '"', '\'', '*', '#', ';', ':', '<', '>', '|'}; private final ArrayList copies = new ArrayList<>(); - private long filecount; + private long fileCount; private File tempDir; private boolean tempDirMessageLogged; @@ -64,6 +65,11 @@ public DefaultFileReplicator(final File tempDir) { this.tempDir = tempDir; } + /** + * Adds a file. + * + * @param file the file to add. + */ protected void addFile(final Object file) { synchronized (copies) { copies.add(file); @@ -82,7 +88,7 @@ public File allocateFile(final String baseName) throws FileSystemException { // Create a unique-ish file name final String actualBaseName = createFilename(baseName); synchronized (this) { - filecount++; + fileCount++; } return createAndAddFile(tempDir, actualBaseName); @@ -110,12 +116,18 @@ public void close() { } } + /** + * Adds a file. + * + * @param parent ignored. + * @param baseName the base file name. + * @return a File. + * @throws FileSystemException if a file system error occurs. + */ protected File createAndAddFile(final File parent, final String baseName) throws FileSystemException { final File file = createFile(tempDir, baseName); - // Keep track to delete later addFile(file); - return file; } @@ -162,8 +174,13 @@ protected void deleteFile(final File file) { } } + /** + * Gets the file count. + * + * @return the file count. + */ protected long getFilecount() { - return filecount; + return fileCount; } /** @@ -177,7 +194,7 @@ public void init() throws FileSystemException { tempDir = new File(FileUtils.getTempDirectoryPath(), "vfs_cache").getAbsoluteFile(); } - filecount = RANDOM.nextInt() & MASK; + fileCount = RANDOM.nextInt() & MASK; if (!tempDirMessageLogged) { final String message = Messages.getString("vfs.impl/temp-dir.debug", tempDir); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java index dd6e5e0ab5..ae3b92db87 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java @@ -295,6 +295,11 @@ public void addProvider(final String[] urlSchemes, final FileProvider provider) } } + /** + * Adds a scheme. + * + * @param rootUri the URI containing the scheme to add. + */ protected void addVirtualFileSystemScheme(String rootUri) { if (rootUri.indexOf(':') != -1) { rootUri = rootUri.substring(0, rootUri.indexOf(':')); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java index ccef4ac835..45e1b9cfa4 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java @@ -141,6 +141,11 @@ public int compareTo(final FileName obj) { */ public abstract FileName createName(String absolutePath, FileType fileType); + /** + * Creates a URI. + * + * @return a URI. + */ protected String createURI() { return createURI(false, true); } @@ -429,6 +434,11 @@ public String getURI() { return uriString; } + /** + * Gets the string to end a URI. + * + * @return the string to end a URI + */ protected String getUriTrailer() { return getType().hasChildren() ? "/" : ""; } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java index 6a65d46041..a8da6c0430 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java @@ -416,7 +416,6 @@ public int delete(final FileSelector selector) throws FileSystemException { for (final FileObject fileObject : files) { final AbstractFileObject file = FileObjectUtils.getAbstractFileObject(fileObject); // file.attach(); - // VFS-210: It seems impossible to me that findFiles will return a list with hidden files/directories // in it, else it would not be hidden. Checking for the file-type seems ok in this case // If the file is a folder, make sure all its children have been deleted @@ -424,13 +423,11 @@ public int delete(final FileSelector selector) throws FileSystemException { // Skip - as the selector forced us not to delete all files continue; } - // Delete the file if (file.deleteSelf()) { nuofDeleted++; } } - return nuofDeleted; } @@ -1491,6 +1488,11 @@ public void holdObject(final Object strongRef) { objects.add(strongRef); } + /** + * Sets the file type. + * + * @param fileType the file type. + */ protected void injectType(final FileType fileType) { setFileType(fileType); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileProvider.java index c7996d2aac..b1e1553b47 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileProvider.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileProvider.java @@ -43,13 +43,13 @@ public abstract class AbstractFileProvider extends AbstractVfsContainer implemen */ private final Map fileSystemMap = new TreeMap<>(); // @GuardedBy("self") - private FileNameParser parser; + private FileNameParser fileNameParser; /** * Constructs a new instance. */ public AbstractFileProvider() { - parser = GenericFileNameParser.getInstance(); + fileNameParser = GenericFileNameParser.getInstance(); } /** @@ -158,8 +158,13 @@ public FileSystemConfigBuilder getConfigBuilder() { return null; } + /** + * Gets the file name parser. + * + * @return the file name parser. + */ protected FileNameParser getFileNameParser() { - return parser; + return fileNameParser; } /** @@ -179,7 +184,12 @@ public FileName parseUri(final FileName base, final String uri) throws FileSyste throw new FileSystemException("vfs.provider/filename-parser-missing.error"); } + /** + * Sets the file name parser. + * + * @param parser a file name parser. + */ protected void setFileNameParser(final FileNameParser parser) { - this.parser = parser; + this.fileNameParser = parser; } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java index e988a4cbc9..bd9ba7e482 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java @@ -183,6 +183,13 @@ public void closeCommunicationLink() { */ protected abstract FileObject createFile(AbstractFileName name) throws Exception; + /** + * Decorates the given file object. + * + * @param file the file object. + * @return the decorated file object. + * @throws FileSystemException if a file system error occurs. + */ protected FileObject decorateFileObject(FileObject file) throws FileSystemException { if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_CALL)) { file = new OnCallRefreshFileObject(file); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessContent.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessContent.java index 8453601682..645fe9a811 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessContent.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessContent.java @@ -31,6 +31,11 @@ */ public abstract class AbstractRandomAccessContent implements RandomAccessContent { + /** + * Constructs a new instance. + * + * @param mode the RandomAccessMode. + */ protected AbstractRandomAccessContent(final RandomAccessMode mode) { Objects.requireNonNull(mode, "mode"); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessStreamContent.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessStreamContent.java index 0928fc4aba..b32621b6b5 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessStreamContent.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractRandomAccessStreamContent.java @@ -27,10 +27,21 @@ */ public abstract class AbstractRandomAccessStreamContent extends AbstractRandomAccessContent { + /** + * Constructs a new instance. + * + * @param mode the RandomAccessMode. + */ protected AbstractRandomAccessStreamContent(final RandomAccessMode mode) { super(mode); } + /** + * Gets a DataInputStream. + * + * @return a DataInputStream. + * @throws IOException if an IO error occurs. + */ protected abstract DataInputStream getDataInputStream() throws IOException; @Override diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java index a5665de6c0..6b34938936 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileObject.java @@ -105,6 +105,11 @@ protected String[] doListChildren() { return children; } + /** + * Gets the container. + * + * @return the container. + */ protected FileObject getContainer() { return container; } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java index dd770368a7..5a14a2cc38 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/compressed/CompressedFileFileProvider.java @@ -39,6 +39,15 @@ public abstract class CompressedFileFileProvider extends AbstractLayeredFileProv public CompressedFileFileProvider() { } + /** + * Create a FileSystem. + * + * @param name a file name. + * @param file a file object. + * @param fileSystemOptions the file system options. + * @return a FileSystem. + * @throws FileSystemException if a file system error occurs. + */ protected abstract FileSystem createFileSystem(FileName name, FileObject file, FileSystemOptions fileSystemOptions) throws FileSystemException; /** diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java index 2d23246184..62d9f6ff8f 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FTPClientWrapper.java @@ -47,11 +47,18 @@ public class FTPClientWrapper implements FtpClient { */ protected final FileSystemOptions fileSystemOptions; private FTPClient ftpClient; - private final GenericFileName root; + private final GenericFileName rootFileName; - protected FTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions) + /** + * Constructs a new instance. + * + * @param rootFileName the root file name. + * @param fileSystemOptions the file system options. + * @throws FileSystemException if a file system error occurs. + */ + protected FTPClientWrapper(final GenericFileName rootFileName, final FileSystemOptions fileSystemOptions) throws FileSystemException { - this.root = root; + this.rootFileName = rootFileName; this.fileSystemOptions = fileSystemOptions; getFtpClient(); // fail-fast } @@ -104,14 +111,21 @@ private FTPClient createClient() throws FileSystemException { } } - protected FTPClient createClient(final GenericFileName rootName, final UserAuthenticationData authData) + /** + * Creates an FTPClient. + * @param rootFileName the root file name. + * @param authData authentication data. + * @return an FTPClient. + * @throws FileSystemException if a file system error occurs. + */ + protected FTPClient createClient(final GenericFileName rootFileName, final UserAuthenticationData authData) throws FileSystemException { - return FtpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), + return FtpClientFactory.createConnection(rootFileName.getHostName(), rootFileName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, - UserAuthenticatorUtils.toChar(rootName.getUserName())), + UserAuthenticatorUtils.toChar(rootFileName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, - UserAuthenticatorUtils.toChar(rootName.getPassword())), - rootName.getPath(), getFileSystemOptions()); + UserAuthenticatorUtils.toChar(rootFileName.getPassword())), + rootFileName.getPath(), getFileSystemOptions()); } @Override @@ -174,7 +188,7 @@ public String getReplyString() throws IOException { * @return the root file name. */ public GenericFileName getRoot() { - return root; + return rootFileName; } /** diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java index ffd6d45894..dcc5f214f2 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpClientFactory.java @@ -106,6 +106,13 @@ private void configureClient(final FileSystemOptions fileSystemOptions, final C } } + /** + * Creates a new client. + * + * @param fileSystemOptions the file system options. + * @return a new client. + * @throws FileSystemException if a file system error occurs. + */ protected abstract C createClient(FileSystemOptions fileSystemOptions) throws FileSystemException; /** @@ -259,6 +266,13 @@ public void flush() { } } + /** + * Sets up a new client. + * + * @param client the client. + * @param fileSystemOptions the file system options. + * @throws IOException if an IO error occurs. + */ protected abstract void setupOpenConnection(C client, FileSystemOptions fileSystemOptions) throws IOException; } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java index c59a587619..d497ede90a 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileSystem.java @@ -78,6 +78,11 @@ protected FileObject createFile(final AbstractFileName name) throws Exception { return new HttpFileObject<>(name, this); } + /** + * Gets the HTTP client. + * + * @return the HttpClient. + */ protected HttpClient getClient() { return httpClient; } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java index bdb67dcd08..40fa9ff391 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java @@ -30,7 +30,16 @@ */ public abstract class LocalFileNameParser extends AbstractFileNameParser { - protected abstract FileName createFileName(String scheme, String rootFile, String path, FileType type); + /** + * Creates a FileName. + * + * @param scheme The scheme. + * @param rootFile the root file. + * @param path the path. + * @param fileType the file type. + * @return a FileName. + */ + protected abstract FileName createFileName(String scheme, String rootFile, String path, FileType fileType); /** * Pops the root prefix off a URI, which has had the scheme removed. diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java index 73fe4cda11..1b5489d2dc 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileSystem.java @@ -101,7 +101,7 @@ protected FileObject createFile(final AbstractFileName name) throws FileSystemEx /** * Creates a Zip file. * - * @param file the underlying file. + * @param file the underlying file. * @return a Zip file. * @throws FileSystemException if a file system error occurs. */ @@ -116,7 +116,7 @@ protected ZipFile createZipFile(final File file) throws FileSystemException { /** * Creates a new Zip file object. * - * @param fileName the underlying file. + * @param fileName the underlying file. * @param entry the Zip entry. * @return a new ZipFileObject. * @throws FileSystemException if a file system error occurs. diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CombinedResources.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CombinedResources.java index d3e2d66daf..47d4775934 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CombinedResources.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/CombinedResources.java @@ -78,17 +78,24 @@ protected Object handleGetObject(final String key) { return properties.get(key); } + /** + * Initializes this instance. + */ protected void init() { if (inited) { return; } - loadResources(getResourceName()); loadResources(Locale.getDefault()); loadResources(getLocale()); inited = true; } + /** + * Loads resources. + * + * @param locale a Locale. + */ protected void loadResources(final Locale locale) { if (locale == null) { return; @@ -108,6 +115,11 @@ protected void loadResources(final Locale locale) { } } + /** + * Loads a resource. + * + * @param resourceName the resource to load. + */ protected void loadResources(String resourceName) { ClassLoader loader = getClass().getClassLoader(); if (loader == null) { diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java index b73393e17f..4f6ab3e314 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DelegatingFileSystemOptionsBuilder.java @@ -238,6 +238,11 @@ private boolean fillConfigSetters(final Context ctx) throws FileSystemException return true; } + /** + * Gets the FileSystemManager. + * + * @return the FileSystemManager. + */ protected FileSystemManager getManager() { return manager; }