Skip to content

Commit

Permalink
Javadoc
Browse files Browse the repository at this point in the history
Better private instance variable names
  • Loading branch information
garydgregory committed Aug 12, 2024
1 parent c2f2714 commit c2845b9
Show file tree
Hide file tree
Showing 18 changed files with 175 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ public FileObject getFile(final FileSystem filesystem, final FileName name) {
return files.get(name); // or null
}

protected ConcurrentMap<FileName, FileObject> getOrCreateFilesystemCache(final FileSystem filesystem) {
ConcurrentMap<FileName, FileObject> files = fileSystemCache.get(filesystem);
/**
* Gets or creates a Map.
*
* @param fileSystem the key
* @return an existing or new Map.
*/
protected ConcurrentMap<FileName, FileObject> getOrCreateFilesystemCache(final FileSystem fileSystem) {
ConcurrentMap<FileName, FileObject> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,7 +46,7 @@ public class DefaultFileReplicator extends AbstractVfsComponent implements FileR
private static final char[] TMP_RESERVED_CHARS = {'?', '/', '\\', ' ', '&', '"', '\'', '*', '#', ';', ':', '<', '>', '|'};

private final ArrayList<Object> copies = new ArrayList<>();
private long filecount;
private long fileCount;
private File tempDir;
private boolean tempDirMessageLogged;

Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(':'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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() ? "/" : "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,21 +416,18 @@ 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
if (file.getType().hasChildren() && file.getChildren().length != 0) {
// Skip - as the selector forced us not to delete all files
continue;
}

// Delete the file
if (file.deleteSelf()) {
nuofDeleted++;
}
}

return nuofDeleted;
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public abstract class AbstractFileProvider extends AbstractVfsContainer implemen
*/
private final Map<FileSystemKey, FileSystem> fileSystemMap = new TreeMap<>(); // @GuardedBy("self")

private FileNameParser parser;
private FileNameParser fileNameParser;

/**
* Constructs a new instance.
*/
public AbstractFileProvider() {
parser = GenericFileNameParser.getInstance();
fileNameParser = GenericFileNameParser.getInstance();
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ protected String[] doListChildren() {
return children;
}

/**
* Gets the container.
*
* @return the container.
*/
protected FileObject getContainer() {
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -174,7 +188,7 @@ public String getReplyString() throws IOException {
* @return the root file name.
*/
public GenericFileName getRoot() {
return root;
return rootFileName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit c2845b9

Please sign in to comment.