Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor Improvements #152

Merged
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void info(final String[] cmd) throws Exception {

private void info(final String scheme) throws Exception {
System.out.println("Provider Info for scheme \"" + scheme + "\":");
Collection<Capability> caps;
final Collection<Capability> caps;
caps = mgr.getProviderCapabilities(scheme);
if (caps != null && !caps.isEmpty()) {
System.out.println(" capabilities: " + caps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.apache.commons.vfs2.libcheck;

import java.util.Iterator;
import java.util.Properties;
import java.util.Vector;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class WebdavFileObject extends HttpFileObject<WebdavFileSystem> {
/**
* An empty immutable {@code WebdavFileObject} array.
*/
private static WebdavFileObject[] EMPTY_ARRAY = new WebdavFileObject[0];
private static final WebdavFileObject[] EMPTY_ARRAY = new WebdavFileObject[0];

/**
* An OutputStream that writes to a Webdav resource.
Expand Down Expand Up @@ -565,7 +565,7 @@ private boolean isCurrentFile(final String href, final URLFileName fileName) {
private boolean isDirectory(final URLFileName name) throws IOException {
try {
final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
Node node;
final Node node;
if (property != null && (node = (Node) property.getValue()) != null) {
return node.getLocalName().equals(DavConstants.XML_COLLECTION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.vfs2.Capability;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystem;
import org.apache.commons.vfs2.FileSystemConfigBuilder;
import org.apache.commons.vfs2.FileSystemException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class WebdavProviderTestCase extends AbstractProviderTestConfig {

private static File RepoDirectory;

private static boolean DEBUG = Boolean.getBoolean("WebdavProviderTestCase.Debug");
private static final boolean DEBUG = Boolean.getBoolean("WebdavProviderTestCase.Debug");

static File createTempDirectory() throws IOException {
// create base folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.commons.vfs2.provider.webdav.test;

import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import org.apache.commons.vfs2.FileObject;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void testVersioning() throws Exception {
final String content = "Here is some sample content for the file. Blah Blah Blah.";

try (OutputStream os = file.getContent().getOutputStream()) {
os.write(content.getBytes("utf-8"));
os.write(content.getBytes(StandardCharsets.UTF_8));
}
assertSameContent(content, file);
map = file.getContent().getAttributes();
Expand Down Expand Up @@ -118,7 +119,7 @@ public void testVersioningWithCreator() throws Exception {
final String content = "Here is some sample content for the file. Blah Blah Blah.";

try (OutputStream os = file.getContent().getOutputStream()) {
os.write(content.getBytes("utf-8"));
os.write(content.getBytes(StandardCharsets.UTF_8));
}
assertSameContent(content, file);
map = file.getContent().getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class Webdav4FileObject extends Http4FileObject<Webdav4FileSystem> {
/**
* An empty immutable {@code Webdav4FileObject} array.
*/
private static Webdav4FileObject[] EMPTY_ARRAY = new Webdav4FileObject[0];
private static final Webdav4FileObject[] EMPTY_ARRAY = new Webdav4FileObject[0];

/**
* An OutputStream that writes to a Webdav resource.
Expand Down Expand Up @@ -458,7 +458,7 @@ protected void doSetAttribute(final String attrName, final Object value) throws
}

private HttpResponse executeRequest(final HttpUriRequest request) throws FileSystemException {
HttpResponse response = null;
final HttpResponse response;

try {
response = executeHttpUriRequest(request);
Expand Down Expand Up @@ -569,7 +569,7 @@ private boolean isCurrentFile(final String href, final GenericURLFileName fileNa
private boolean isDirectory(final GenericURLFileName name) throws IOException {
try {
final DavProperty property = getProperty(name, DavConstants.PROPERTY_RESOURCETYPE);
Node node;
final Node node;
if (property != null && (node = (Node) property.getValue()) != null) {
return node.getLocalName().equals(DavConstants.XML_COLLECTION);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOpt
final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;

UserAuthenticationData authData = null;
HttpClient httpClient = null;
HttpClientContext httpClientContext = null;
final HttpClient httpClient;
final HttpClientContext httpClientContext;

try {
final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOpt
final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;

UserAuthenticationData authData = null;
HttpClient httpClient = null;
HttpClientContext httpClientContext = null;
final HttpClient httpClient;
final HttpClientContext httpClientContext;

try {
final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Webdav4ProviderTestCase extends AbstractProviderTestConfig {

private static File RepoDirectory;

private static boolean DEBUG = Boolean.getBoolean("Webdav4ProviderTestCase.Debug");
private static final boolean DEBUG = Boolean.getBoolean("Webdav4ProviderTestCase.Debug");

static File createTempDirectory() throws IOException {
// create base folder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.commons.vfs2.provider.webdav4.test;

import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Map;

import org.apache.commons.vfs2.FileObject;
Expand Down Expand Up @@ -71,7 +72,7 @@ public void testVersioning() throws Exception {
final String content = "Here is some sample content for the file. Blah Blah Blah.";

try (OutputStream os = file.getContent().getOutputStream()) {
os.write(content.getBytes("utf-8"));
os.write(content.getBytes(StandardCharsets.UTF_8));
}
assertSameContent(content, file);
map = file.getContent().getAttributes();
Expand Down Expand Up @@ -120,7 +121,7 @@ public void testVersioningWithCreator() throws Exception {
final String content = "Here is some sample content for the file. Blah Blah Blah.";

try (OutputStream os = file.getContent().getOutputStream()) {
os.write(content.getBytes("utf-8"));
os.write(content.getBytes(StandardCharsets.UTF_8));
}
assertSameContent(content, file);
map = file.getContent().getAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,5 @@ public enum Capability {
*
* @since 2.0
*/
DIRECTORY_READ_CONTENT;
DIRECTORY_READ_CONTENT
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ public boolean equals(final Object o) {
if (!fileSystemClass.equals(that.fileSystemClass)) {
return false;
}
if (!name.equals(that.name)) {
return false;
}

return true;
return name.equals(that.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public interface FilesCache {
*/
void removeFile(final FileSystem fileSystem, final FileName name);

/**
* If the cache uses timestamps it could use this method to handle updates of them.
*
* @param file file name
/*
If the cache uses timestamps it could use this method to handle updates of them.

@param file file name
*/
// public void touchFile(final FileObject file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ private int compareStringOrNull(final String thisString, final String otherStrin
}

final int result = thisString.compareTo(otherString);
if (result != 0) {
return result;
}
return result;
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException
final FileObject[] files = file.getChildren();
return files == null || files.length == 0;
}
try (final FileContent content = file.getContent();) {
try (final FileContent content = file.getContent()) {
return content.isEmpty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public boolean accept(final FileSelectInfo fileInfo) throws FileSystemException
if (!file.exists()) {
return false;
}
try (final FileContent content = file.getContent();) {
try (final FileContent content = file.getContent()) {
final long length = content.getSize();
final boolean smaller = length < size;
return acceptLarger ? !smaller : smaller;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ public void stop() {
public void run() {
mainloop: while (!monitorThread.isInterrupted() && this.shouldRun) {
// For each entry in the map
Object[] fileNames;
final Object[] fileNames;
synchronized (this.monitorMap) {
fileNames = this.monitorMap.keySet().toArray();
}
for (int iterFileNames = 0; iterFileNames < fileNames.length; iterFileNames++) {
final FileName fileName = (FileName) fileNames[iterFileNames];
FileMonitorAgent agent;
final FileMonitorAgent agent;
synchronized (this.monitorMap) {
agent = this.monitorMap.get(fileName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ public FileName resolveName(final FileName base, final String name, final NameSc
throw new FileSystemException("vfs.provider/invalid-descendent-name.error", name);
}

String fullPath;
final String fullPath;
if (scheme != null) {
fullPath = resolvedPath;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void init() throws FileSystemException {
* @throws FileSystemException if an error occurs.
*/
protected void configurePlugins() throws FileSystemException {
Enumeration<URL> enumResources;
final Enumeration<URL> enumResources;
try {
enumResources = loadResources(PLUGIN_CONFIG_RESOURCE);
} catch (final IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum VcsStatus {
7), UNVERSIONED(8), MISSING(9), OBSTRUCTED(10), REVERTED(11), RESOLVED(12), COPIED(
13), MOVED(14), RESTORED(15), UPDATED(16), EXTERNAL(18), CORRUPTED(19), NOT_REVERTED(20);

private int status;
private final int status;

VcsStatus(final int status) {
this.status = status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,18 +510,12 @@ public static boolean checkName(final String basePath, final String path, final
}

if (scope == NameScope.CHILD) {
if (path.length() == baseLen || baseLen > 1 && path.charAt(baseLen) != SEPARATOR_CHAR
|| path.indexOf(SEPARATOR_CHAR, baseLen + 1) != -1) {
return false;
}
return path.length() != baseLen && (baseLen <= 1 || path.charAt(baseLen) == SEPARATOR_CHAR)
&& path.indexOf(SEPARATOR_CHAR, baseLen + 1) == -1;
} else if (scope == NameScope.DESCENDENT) {
if (path.length() == baseLen || baseLen > 1 && path.charAt(baseLen) != SEPARATOR_CHAR) {
return false;
}
return path.length() != baseLen && (baseLen <= 1 || path.charAt(baseLen) == SEPARATOR_CHAR);
} else if (scope == NameScope.DESCENDENT_OR_SELF) {
if (baseLen > 1 && path.length() > baseLen && path.charAt(baseLen) != SEPARATOR_CHAR) {
return false;
}
return baseLen <= 1 || path.length() <= baseLen || path.charAt(baseLen) == SEPARATOR_CHAR;
} else if (scope != NameScope.FILE_SYSTEM) {
throw new IllegalArgumentException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ public FileObject[] getChildren() throws FileSystemException {
}

// allow the filesystem to return resolved children. e.g. prefill type for webdav
FileObject[] childrenObjects;
final FileObject[] childrenObjects;
try {
childrenObjects = doListChildrenResolved();
children = extractNames(childrenObjects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public FileSystemConfigBuilder getConfigBuilder() {
* Free unused resources.
*/
public void freeUnusedResources() {
AbstractFileSystem[] abstractFileSystems;
final AbstractFileSystem[] abstractFileSystems;
synchronized (fileSystems) {
// create snapshot under lock
abstractFileSystems = fileSystems.values().toArray(EMPTY_ABSTRACTFILESYSTEMS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ private synchronized FileObject resolveFile(final FileName name, final boolean u
}
}

/**
* resync the file information if requested
/*
resync the file information if requested
*/
if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
file.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ private InputStream buildInputStream(final int bufferSize) throws FileSystemExce
// ? new FileContentInputStream(fileObject, inputStream)
// : new FileContentInputStream(fileObject, inputStream, bufferSize);

InputStream wrappedInputStream;
final InputStream wrappedInputStream;
if (inputStream instanceof BufferedInputStream) {
// Don't double buffer.
wrappedInputStream = new RawFileContentInputStream(fileObject, inputStream);
Expand Down Expand Up @@ -861,7 +861,7 @@ public long write(final OutputStream output, final int bufferSize) throws IOExce
try {
// This read/write code from Apache Commons IO
final byte[] buffer = new byte[bufferSize];
int n = 0;
int n;
while (-1 != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected void parseURL(final URL u, final String spec, final int start, final i
try {
final FileObject old = context.resolveFile(u.toExternalForm(), fileSystemOptions);

FileObject newURL;
final FileObject newURL;
if (start > 0 && spec.charAt(start - 1) == ':') {
newURL = context.resolveFile(old, spec, fileSystemOptions);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected long doGetLastModifiedTime() throws Exception {
protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception {
final FtpClient client = getAbstractFileSystem().getClient();
try {
OutputStream out = null;
final OutputStream out;
if (bAppend) {
out = client.appendFileStream(relPath);
} else {
Expand Down Expand Up @@ -606,7 +606,7 @@ public void refresh() throws FileSystemException {
private void setFTPFile(final boolean flush) throws IOException {
synchronized (getFileSystem()) {
final FtpFileObject parent = (FtpFileObject) FileObjectUtils.getAbstractFileObject(getParent());
FTPFile newFileInfo;
final FTPFile newFileInfo;
if (parent != null) {
newFileInfo = parent.getChildFile(UriParser.decode(getName().getBaseName()), flush);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ public enum HdfsFileAttributes {
/**
* Modification time.
*/
MODIFICATION_TIME;
MODIFICATION_TIME
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public FileObject resolveFile(final FileName name) throws FileSystemException {
fileObject = null;
}
if (null == fileObject) {
String path = null;
String path;
try {
path = URLDecoder.decode(name.getPath(), "UTF-8");
} catch (final UnsupportedEncodingException e) {
Expand All @@ -171,8 +171,8 @@ public FileObject resolveFile(final FileName name) throws FileSystemException {
this.putFileToCache(fileObject);
}
}
/**
* resync the file information if requested
/*
resync the file information if requested
*/
if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
fileObject.refresh();
Expand Down
Loading