This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push: new 2f1239e Start reusing Apache Commons Lang. 2f1239e is described below commit 2f1239e6509c88bad4aefc6df99c651eed8ff6bb Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Tue Mar 2 12:35:34 2021 -0500 Start reusing Apache Commons Lang. --- .../org/apache/commons/vfs2/example/Shell.java | 4 +-- commons-vfs2/pom.xml | 1 - .../org/apache/commons/vfs2/FileDepthSelector.java | 20 ++++--------- .../commons/vfs2/FileSystemConfigBuilder.java | 5 ++-- .../apache/commons/vfs2/FileSystemException.java | 5 ++-- .../apache/commons/vfs2/filter/AgeFileFilter.java | 3 +- .../apache/commons/vfs2/filter/AndFileFilter.java | 3 +- .../commons/vfs2/filter/WildcardFileFilter.java | 7 +++-- .../vfs2/impl/DefaultFileSystemManager.java | 3 +- .../vfs2/impl/StandardFileSystemManager.java | 9 +++--- .../commons/vfs2/provider/AbstractFileName.java | 9 +++--- .../commons/vfs2/provider/DefaultFileContent.java | 2 +- .../commons/vfs2/provider/DelegateFileObject.java | 2 +- .../commons/vfs2/provider/GenericFileName.java | 3 +- .../apache/commons/vfs2/provider/UriParser.java | 4 +-- .../vfs2/provider/ftp/FtpClientFactory.java | 5 ++-- .../commons/vfs2/provider/ftp/FtpFileObject.java | 3 +- .../provider/hdfs/HdfsFileSystemConfigBuilder.java | 13 +++++---- .../vfs2/provider/http/HttpClientFactory.java | 5 ++-- .../provider/http/HttpFileContentInfoFactory.java | 3 +- .../vfs2/provider/http4/Http4FileProvider.java | 9 +++--- .../vfs2/provider/http5/Http5FileProvider.java | 7 +++-- .../provider/local/DefaultLocalFileProvider.java | 3 +- .../vfs2/provider/local/GenericFileNameParser.java | 3 +- .../commons/vfs2/provider/ram/RamFileData.java | 5 ++-- .../commons/vfs2/provider/ram/RamFileObject.java | 3 +- .../vfs2/provider/res/ResourceFileNameParser.java | 3 +- .../vfs2/provider/sftp/SftpClientFactory.java | 5 ++-- .../commons/vfs2/provider/sftp/SftpFileSystem.java | 2 +- .../commons/vfs2/provider/tar/TarFileObject.java | 2 +- .../commons/vfs2/provider/zip/ZipFileObject.java | 2 +- .../org/apache/commons/vfs2/util/ArrayUtils.java | 33 ---------------------- .../apache/commons/vfs2/util/DurationUtils.java | 31 -------------------- .../org/apache/commons/vfs2/util/Messages.java | 6 ++-- .../main/java/org/apache/commons/vfs2/util/Os.java | 5 ++++ .../org/apache/commons/vfs2/util/OsFamily.java | 5 ++++ .../org/apache/commons/vfs2/util/URIUtils.java | 3 +- .../vfs2/provider/hdfs/HdfsFileProviderTest.java | 3 +- .../vfs2/provider/local/LocalProviderTestCase.java | 3 +- .../vfs2/provider/zip/FileLockTestCase.java | 5 ++-- 40 files changed, 101 insertions(+), 146 deletions(-) diff --git a/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java b/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java index 9fdc3a4..9283cf5 100644 --- a/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java +++ b/commons-vfs2-examples/src/main/java/org/apache/commons/vfs2/example/Shell.java @@ -30,6 +30,7 @@ import java.util.Date; import java.util.List; import java.util.StringTokenizer; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileContent; import org.apache.commons.vfs2.FileObject; @@ -49,7 +50,6 @@ import org.apache.commons.vfs2.util.FileObjectUtils; */ public final class Shell { - private static final String[] EMPTY_STRING_ARRAY = new String[0]; private final FileSystemManager mgr; private FileObject cwd; private final BufferedReader reader; @@ -358,7 +358,7 @@ public final class Shell { while (tokens.hasMoreTokens()) { cmd.add(tokens.nextToken()); } - return cmd.toArray(EMPTY_STRING_ARRAY); + return cmd.toArray(ArrayUtils.EMPTY_STRING_ARRAY); } private static String getVersion(final Class<?> cls) { diff --git a/commons-vfs2/pom.xml b/commons-vfs2/pom.xml index f37eba4..ea7d6a1 100644 --- a/commons-vfs2/pom.xml +++ b/commons-vfs2/pom.xml @@ -108,7 +108,6 @@ <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> - <scope>test</scope> </dependency> <!-- Test FTP with Apache FTP Server (MINA) --> <dependency> diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileDepthSelector.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileDepthSelector.java index 2a25112..dd81c97 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileDepthSelector.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileDepthSelector.java @@ -16,20 +16,14 @@ */ package org.apache.commons.vfs2; +import org.apache.commons.lang3.Range; + /** * A {@link FileSelector} that selects all files in a particular depth range. */ public class FileDepthSelector implements FileSelector { - /** - * The minimum depth - */ - private final int minDepth; - - /** - * The maximum depth - */ - private final int maxDepth; + private final Range<Integer> range; /** * Creates a selector with the given minimum and maximum depths. @@ -38,8 +32,7 @@ public class FileDepthSelector implements FileSelector { * @param maxDepth maximum depth */ public FileDepthSelector(final int minDepth, final int maxDepth) { - this.minDepth = minDepth; - this.maxDepth = maxDepth; + this.range = Range.between(minDepth, maxDepth); } /** @@ -69,8 +62,7 @@ public class FileDepthSelector implements FileSelector { */ @Override public boolean includeFile(final FileSelectInfo fileInfo) throws Exception { - final int depth = fileInfo.getDepth(); - return minDepth <= depth && depth <= maxDepth; + return range.contains(fileInfo.getDepth()); } /** @@ -81,6 +73,6 @@ public class FileDepthSelector implements FileSelector { */ @Override public boolean traverseDescendents(final FileSelectInfo fileInfo) throws Exception { - return fileInfo.getDepth() < maxDepth; + return fileInfo.getDepth() < range.getMaximum(); } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java index ad7dcb4..e7e2ee6 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemConfigBuilder.java @@ -20,7 +20,8 @@ import java.time.Duration; import java.util.Objects; import java.util.function.Function; -import org.apache.commons.vfs2.util.DurationUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DurationUtils; /** * Abstract class which has the right to fill FileSystemOptions. @@ -189,7 +190,7 @@ public abstract class FileSystemConfigBuilder { Character value = getParam(fileSystemOptions, name); if (value == null) { final String str = getProperty(name); - if (str == null || str.isEmpty()) { + if (StringUtils.isEmpty(str)) { return defaultValue; } value = Character.valueOf(str.charAt(0)); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemException.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemException.java index b64cb5e..64a5ac4 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemException.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/FileSystemException.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.vfs2.util.ArrayUtils; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.util.Messages; /** @@ -172,8 +172,7 @@ public class FileSystemException extends IOException { // mask passwords (VFS-169) final Matcher urlMatcher = URL_PATTERN.matcher(value); if (urlMatcher.find()) { - final Matcher pwdMatcher = PASSWORD_PATTERN.matcher(value); - value = pwdMatcher.replaceFirst(":***@"); + value = PASSWORD_PATTERN.matcher(value).replaceFirst(":***@"); } this.info[i] = value; } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AgeFileFilter.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AgeFileFilter.java index 285a2ad..2352194 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AgeFileFilter.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AgeFileFilter.java @@ -79,8 +79,7 @@ public class AgeFileFilter implements FileFilter, Serializable { return false; } try (final FileContent content = fileObject.getContent()) { - final long lastModified = content.getLastModifiedTime(); - return lastModified > timeMillis; + return content.getLastModifiedTime() > timeMillis; } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AndFileFilter.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AndFileFilter.java index ad7ef48..b0fd2b0 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AndFileFilter.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/AndFileFilter.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileFilter; import org.apache.commons.vfs2.FileSelectInfo; import org.apache.commons.vfs2.FileSystemException; @@ -56,7 +57,7 @@ public class AndFileFilter implements FileFilter, ConditionalFileFilter, Seriali * @param filters array of filters, must not be null or empty */ public AndFileFilter(final FileFilter... filters) { - if (filters == null || filters.length == 0) { + if (ArrayUtils.isEmpty(filters)) { throw new IllegalArgumentException("The filters must not be null or empty"); } for (final FileFilter filter : filters) { diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/WildcardFileFilter.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/WildcardFileFilter.java index b672efa..f290e36 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/WildcardFileFilter.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/filter/WildcardFileFilter.java @@ -22,9 +22,10 @@ import java.util.Arrays; import java.util.List; import java.util.Stack; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileFilter; import org.apache.commons.vfs2.FileSelectInfo; -import org.apache.commons.vfs2.util.ArrayUtils; /** * Filters files using the supplied wildcards. @@ -180,7 +181,7 @@ public class WildcardFileFilter implements FileFilter, Serializable { final StringBuilder builder = new StringBuilder(); for (int i = 0; i < array.length; i++) { if (array[i] == '?' || array[i] == '*') { - if (builder.length() != 0) { + if (StringUtils.isNotEmpty(builder)) { list.add(builder.toString()); builder.setLength(0); } @@ -193,7 +194,7 @@ public class WildcardFileFilter implements FileFilter, Serializable { builder.append(array[i]); } } - if (builder.length() != 0) { + if (StringUtils.isNotEmpty(builder)) { list.add(builder.toString()); } 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 89332a8..0e5ca5d 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 @@ -676,8 +676,7 @@ public class DefaultFileSystemManager implements FileSystemManager { */ @Override public FileObject resolveFile(final File baseFile, final String uri) throws FileSystemException { - final FileObject baseFileObj = getLocalFileProvider().findLocalFile(baseFile); - return resolveFile(baseFileObj, uri); + return resolveFile(getLocalFileProvider().findLocalFile(baseFile), uri); } /** diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java index ceac054..1daf06b 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/impl/StandardFileSystemManager.java @@ -28,11 +28,12 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.VfsLog; import org.apache.commons.vfs2.operations.FileOperationProvider; import org.apache.commons.vfs2.provider.FileProvider; -import org.apache.commons.vfs2.util.ArrayUtils; import org.apache.commons.vfs2.util.Messages; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -264,7 +265,7 @@ public class StandardFileSystemManager extends DefaultFileSystemManager { private void addExtensionMap(final Element map) { final String extension = map.getAttribute("extension"); final String scheme = map.getAttribute("scheme"); - if (scheme != null && !scheme.isEmpty()) { + if (!StringUtils.isEmpty(scheme)) { addExtensionMap(extension, scheme); } } @@ -362,7 +363,7 @@ public class StandardFileSystemManager extends DefaultFileSystemManager { for (int i = 0; i < count; i++) { final Element dep = (Element) deps.item(i); final String className = dep.getAttribute("class-name"); - if (className != null && !className.isEmpty()) { + if (!StringUtils.isEmpty(className)) { classes.add(className); } } @@ -379,7 +380,7 @@ public class StandardFileSystemManager extends DefaultFileSystemManager { for (int i = 0; i < count; i++) { final Element dep = (Element) deps.item(i); final String scheme = dep.getAttribute("scheme"); - if (scheme != null && !scheme.isEmpty()) { + if (!StringUtils.isEmpty(scheme)) { schemes.add(scheme); } } 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 43f121e..7ed948a 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 @@ -16,6 +16,7 @@ */ package org.apache.commons.vfs2.provider; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -58,14 +59,14 @@ public abstract class AbstractFileName implements FileName { this.rootUri = null; this.scheme = scheme; this.type = type; - if (absPath != null && !absPath.isEmpty()) { + if (StringUtils.isEmpty(absPath)) { + this.absPath = ROOT_PATH; + } else { if (absPath.length() > 1 && absPath.endsWith("/")) { this.absPath = absPath.substring(0, absPath.length() - 1); } else { this.absPath = absPath; } - } else { - this.absPath = ROOT_PATH; } } @@ -271,7 +272,7 @@ public abstract class AbstractFileName implements FileName { } private String handleURISpecialCharacters(String uri) { - if (uri != null && !uri.isEmpty()) { + if (!StringUtils.isEmpty(uri)) { try { // VFS-325: Handle URI special characters in file name // Decode the base URI and re-encode with URI special characters diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultFileContent.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultFileContent.java index 8f47cd2..ebe3895 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultFileContent.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultFileContent.java @@ -25,13 +25,13 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileContent; import org.apache.commons.vfs2.FileContentInfo; import org.apache.commons.vfs2.FileContentInfoFactory; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.RandomAccessContent; -import org.apache.commons.vfs2.util.ArrayUtils; import org.apache.commons.vfs2.util.MonitorInputStream; import org.apache.commons.vfs2.util.MonitorOutputStream; import org.apache.commons.vfs2.util.MonitorRandomAccessContent; diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java index efc5216..7aaef44 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DelegateFileObject.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileChangeEvent; import org.apache.commons.vfs2.FileContentInfo; import org.apache.commons.vfs2.FileListener; @@ -33,7 +34,6 @@ import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; import org.apache.commons.vfs2.RandomAccessContent; -import org.apache.commons.vfs2.util.ArrayUtils; import org.apache.commons.vfs2.util.RandomAccessMode; import org.apache.commons.vfs2.util.WeakRefFileListener; diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericFileName.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericFileName.java index 5d17da5..7b4bf4a 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericFileName.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/GenericFileName.java @@ -16,6 +16,7 @@ */ package org.apache.commons.vfs2.provider; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileType; @@ -128,7 +129,7 @@ public class GenericFileName extends AbstractFileName { * @param addPassword flag if password should be added or replaced with placeholder (false). */ protected void appendCredentials(final StringBuilder buffer, final boolean addPassword) { - if (userName != null && !userName.isEmpty()) { + if (!StringUtils.isEmpty(userName)) { UriParser.appendEncoded(buffer, userName, USERNAME_RESERVED); if (password != null && !password.isEmpty()) { buffer.append(':'); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java index 92c80be..8789177 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/UriParser.java @@ -16,11 +16,11 @@ */ package org.apache.commons.vfs2.provider; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; import org.apache.commons.vfs2.VFS; -import org.apache.commons.vfs2.util.Os; /** * Utilities for dealing with URIs. See RFC 2396 for details. @@ -378,7 +378,7 @@ public final class UriParser { if (ch == ':') { // Found the end of the scheme final String scheme = uri.substring(0, pos); - if (scheme.length() <= 1 && Os.isFamily(Os.OS_FAMILY_WINDOWS)) { + if (scheme.length() <= 1 && SystemUtils.IS_OS_WINDOWS) { // This is not a scheme, but a Windows drive letter return null; } 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 9d8db03..a61a51d 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 @@ -23,6 +23,8 @@ import java.io.Writer; import java.net.Proxy; import java.time.Duration; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DurationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.net.PrintCommandListener; @@ -32,7 +34,6 @@ import org.apache.commons.net.ftp.FTPReply; import org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemOptions; -import org.apache.commons.vfs2.util.DurationUtils; import org.apache.commons.vfs2.util.UserAuthenticatorUtils; /** @@ -84,7 +85,7 @@ public final class FtpClientFactory { if (shortMonthNames != null) { final StringBuilder shortMonthNamesStr = new StringBuilder(BUFSZ); for (final String shortMonthName : shortMonthNames) { - if (shortMonthNamesStr.length() > 0) { + if (!StringUtils.isEmpty(shortMonthNamesStr)) { shortMonthNamesStr.append("|"); } shortMonthNamesStr.append(shortMonthName); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java index ceaeda9..d8d5232 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java @@ -29,6 +29,7 @@ import java.util.TimeZone; import java.util.TreeMap; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.net.ftp.FTPFile; @@ -238,7 +239,7 @@ public class FtpFileObject extends AbstractFileObject<FtpFileSystem> { .getPath() : relPath; final FTPFile[] tmpChildren = client.listFiles(path); - if (tmpChildren == null || tmpChildren.length == 0) { + if (ArrayUtils.isEmpty(tmpChildren)) { childMap = EMPTY_FTP_FILE_MAP; } else { childMap = new TreeMap<>(); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java index 2821afc..9786c35 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java @@ -21,6 +21,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileSystem; import org.apache.commons.vfs2.FileSystemConfigBuilder; import org.apache.commons.vfs2.FileSystemOptions; @@ -91,7 +92,7 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { */ public String[] getConfigNames(final FileSystemOptions opts) { final String names = this.getString(opts, KEY_CONFIG_NAMES); - return names == null || names.isEmpty() ? null : names.split(","); + return StringUtils.isEmpty(names) ? null : names.split(","); } /** @@ -103,7 +104,7 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { */ public Path[] getConfigPaths(final FileSystemOptions opts) { final String pathNames = this.getString(opts, KEY_CONFIG_PATHS); - if (pathNames == null || pathNames.isEmpty()) { + if (StringUtils.isEmpty(pathNames)) { return null; } return Arrays.stream(pathNames.split(",")).map(Path::new).toArray(Path[]::new); @@ -119,7 +120,7 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { public URL[] getConfigURLs(final FileSystemOptions opts) { try { final String urlNames = this.getString(opts, KEY_CONFIG_URLS); - if (urlNames == null || urlNames.isEmpty()) { + if (StringUtils.isEmpty(urlNames)) { return null; } final String[] urls = urlNames.split(","); @@ -198,7 +199,7 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { * @see #getConfigNames */ public void setConfigName(final FileSystemOptions opts, final String name) { - if (name == null || name.isEmpty()) { + if (StringUtils.isEmpty(name)) { this.setParam(opts, KEY_CONFIG_NAMES, null); } else { final String previousNames = this.getString(opts, KEY_CONFIG_NAMES); @@ -233,7 +234,7 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { this.setParam(opts, KEY_CONFIG_PATHS, null); } else { final String previousPathNames = this.getString(opts, KEY_CONFIG_PATHS); - if (previousPathNames == null || previousPathNames.isEmpty()) { + if (StringUtils.isEmpty(previousPathNames)) { this.setParam(opts, KEY_CONFIG_PATHS, path.toString()); } else { this.setParam(opts, KEY_CONFIG_PATHS, previousPathNames + "," + path.toString()); @@ -263,7 +264,7 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder { this.setParam(opts, KEY_CONFIG_URLS, null); } else { final String previousURLNames = this.getString(opts, KEY_CONFIG_URLS); - if (previousURLNames == null || previousURLNames.isEmpty()) { + if (StringUtils.isEmpty(previousURLNames)) { this.setParam(opts, KEY_CONFIG_URLS, url.toString()); } else { this.setParam(opts, KEY_CONFIG_URLS, previousURLNames + "," + url.toString()); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java index 20c5dc1..517a3a8 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpClientFactory.java @@ -25,11 +25,12 @@ import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; import org.apache.commons.httpclient.params.HttpClientParams; import org.apache.commons.httpclient.params.HttpConnectionManagerParams; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DurationUtils; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.UserAuthenticationData; import org.apache.commons.vfs2.UserAuthenticator; -import org.apache.commons.vfs2.util.DurationUtils; import org.apache.commons.vfs2.util.UserAuthenticatorUtils; /** @@ -68,7 +69,7 @@ public final class HttpClientFactory { final String proxyHost = builder.getProxyHost(fileSystemOptions); final int proxyPort = builder.getProxyPort(fileSystemOptions); - if (proxyHost != null && !proxyHost.isEmpty() && proxyPort > 0) { + if (!StringUtils.isEmpty(proxyHost) && proxyPort > 0) { config.setProxy(proxyHost, proxyPort); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java index 83e3756..11010f5 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http/HttpFileContentInfoFactory.java @@ -21,6 +21,7 @@ import java.io.IOException; import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HeaderElement; import org.apache.commons.httpclient.methods.HeadMethod; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileContent; import org.apache.commons.vfs2.FileContentInfo; import org.apache.commons.vfs2.FileContentInfoFactory; @@ -48,7 +49,7 @@ public class HttpFileContentInfoFactory implements FileContentInfoFactory { final Header header = headMethod.getResponseHeader("content-type"); if (header != null) { final HeaderElement[] element = header.getElements(); - if (element != null && element.length > 0) { + if (!ArrayUtils.isEmpty(element)) { contentType = element[0].getName(); } } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java index 14834b5..13516d8 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http4/Http4FileProvider.java @@ -32,6 +32,8 @@ import java.util.List; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DurationUtils; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystem; @@ -42,7 +44,6 @@ import org.apache.commons.vfs2.UserAuthenticationData; import org.apache.commons.vfs2.UserAuthenticator; import org.apache.commons.vfs2.provider.AbstractOriginatingFileProvider; import org.apache.commons.vfs2.provider.GenericFileName; -import org.apache.commons.vfs2.util.DurationUtils; import org.apache.commons.vfs2.util.UserAuthenticatorUtils; import org.apache.http.ConnectionReuseStrategy; import org.apache.http.Header; @@ -229,7 +230,7 @@ public class Http4FileProvider extends AbstractOriginatingFileProvider { final String password = UserAuthenticatorUtils.toString(UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword()))); - if (username != null && !username.isEmpty()) { + if (!StringUtils.isEmpty(username)) { credsProvider.setCredentials(new AuthScope(rootName.getHostName(), rootName.getPort()), new UsernamePasswordCredentials(username, password)); } @@ -295,7 +296,7 @@ public class Http4FileProvider extends AbstractOriginatingFileProvider { File keystoreFileObject = null; final String keystoreFile = builder.getKeyStoreFile(fileSystemOptions); - if (keystoreFile != null && !keystoreFile.isEmpty()) { + if (!StringUtils.isEmpty(keystoreFile)) { keystoreFileObject = new File(keystoreFile); } @@ -358,7 +359,7 @@ public class Http4FileProvider extends AbstractOriginatingFileProvider { final int proxyPort = builder.getProxyPort(fileSystemOptions); final String proxyScheme = builder.getProxyScheme(fileSystemOptions); - if (proxyHost != null && !proxyHost.isEmpty() && proxyPort > 0) { + if (!StringUtils.isEmpty(proxyHost) && proxyPort > 0) { return new HttpHost(proxyHost, proxyPort, proxyScheme); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java index d31e30b..d3d2db4 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/http5/Http5FileProvider.java @@ -32,6 +32,7 @@ import java.util.List; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystem; @@ -239,7 +240,7 @@ public class Http5FileProvider extends AbstractOriginatingFileProvider { final char[] password = UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())); - if (username != null && !username.isEmpty()) { + if (!StringUtils.isEmpty(username)) { // set root port credsProvider.setCredentials(new AuthScope(rootName.getHostName(), rootName.getPort()), new UsernamePasswordCredentials(username, password)); @@ -306,7 +307,7 @@ public class Http5FileProvider extends AbstractOriginatingFileProvider { File keystoreFileObject = null; final String keystoreFile = builder.getKeyStoreFile(fileSystemOptions); - if (keystoreFile != null && !keystoreFile.isEmpty()) { + if (!StringUtils.isEmpty(keystoreFile)) { keystoreFileObject = new File(keystoreFile); } @@ -369,7 +370,7 @@ public class Http5FileProvider extends AbstractOriginatingFileProvider { final String proxyHost = builder.getProxyHost(fileSystemOptions); final int proxyPort = builder.getProxyPort(fileSystemOptions); - if (proxyHost != null && !proxyHost.isEmpty() && proxyPort > 0) { + if (!StringUtils.isEmpty(proxyHost) && proxyPort > 0) { return new HttpHost(proxyScheme, proxyHost, proxyPort); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java index b0bef4d..795529f 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/DefaultLocalFileProvider.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.vfs2.Capability; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileObject; @@ -49,7 +50,7 @@ public class DefaultLocalFileProvider extends AbstractOriginatingFileProvider im * Constructs a new provider. */ public DefaultLocalFileProvider() { - if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) { + if (SystemUtils.IS_OS_WINDOWS) { setFileNameParser(new WindowsFileNameParser()); } else { setFileNameParser(new GenericFileNameParser()); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java index 17e4211..2498f7f 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/GenericFileNameParser.java @@ -16,6 +16,7 @@ */ package org.apache.commons.vfs2.provider.local; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -44,7 +45,7 @@ public class GenericFileNameParser extends LocalFileNameParser { // TODO - this class isn't generic at all. Need to fix this // Looking for <sep> - if (name.length() == 0 || name.charAt(0) != '/') { + if (StringUtils.isEmpty(name) || name.charAt(0) != '/') { throw new FileSystemException("vfs.provider.local/not-absolute-file-name.error", uri); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java index b68a343..c736f59 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileData.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -30,8 +31,6 @@ import org.apache.commons.vfs2.FileType; */ class RamFileData implements Serializable { - static final byte[] EMPTY = new byte[0]; - /** * serialVersionUID format is YYYYMMDD for the date of the last binary change. */ @@ -122,7 +121,7 @@ class RamFileData implements Serializable { /** */ void clear() { - this.content = EMPTY; + this.content = ArrayUtils.EMPTY_BYTE_ARRAY; updateLastModified(); this.type = FileType.IMAGINARY; this.children.clear(); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java index fd9261b..6b9fad1 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileObject.java @@ -21,6 +21,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemOptions; @@ -108,7 +109,7 @@ public class RamFileObject extends AbstractFileObject<RamFileSystem> { @Override protected OutputStream doGetOutputStream(final boolean bAppend) throws Exception { if (!bAppend) { - this.data.setContent(RamFileData.EMPTY); + this.data.setContent(ArrayUtils.EMPTY_BYTE_ARRAY); } return new RamFileOutputStream(this); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileNameParser.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileNameParser.java index 8c5c801..cdd8d42 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileNameParser.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileNameParser.java @@ -16,6 +16,7 @@ */ package org.apache.commons.vfs2.provider.res; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -50,7 +51,7 @@ public class ResourceFileNameParser extends GenericFileNameParser { name.delete(0, index); } - if (name.length() == 0) { + if (StringUtils.isEmpty(name)) { throw new FileSystemException("vfs.provider.res/not-valid-resource-location.error", uri); } diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java index c5486bc..c8f7583 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpClientFactory.java @@ -21,11 +21,12 @@ import java.io.IOException; import java.time.Duration; import java.util.Properties; +import org.apache.commons.lang3.SystemUtils; +import org.apache.commons.lang3.time.DurationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemOptions; -import org.apache.commons.vfs2.util.DurationUtils; import org.apache.commons.vfs2.util.Os; import com.jcraft.jsch.ConfigRepository; @@ -282,7 +283,7 @@ public final class SftpClientFactory { return sshDir; } - if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) { + if (SystemUtils.IS_OS_WINDOWS) { // TODO - this may not be true final String userName = System.getProperty("user.name"); sshDir = new File("C:\\cygwin\\home\\" + userName + "\\" + SSH_DIR_NAME); diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java index 67e9587..44be091 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java @@ -23,6 +23,7 @@ import java.time.Duration; import java.util.Collection; import java.util.Objects; +import org.apache.commons.lang3.time.DurationUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.Capability; @@ -32,7 +33,6 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.provider.AbstractFileName; import org.apache.commons.vfs2.provider.AbstractFileSystem; import org.apache.commons.vfs2.provider.GenericFileName; -import org.apache.commons.vfs2.util.DurationUtils; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.ChannelSftp; diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java index 65ecb72..099edd3 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/tar/TarFileObject.java @@ -20,12 +20,12 @@ import java.io.InputStream; import java.util.HashSet; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; import org.apache.commons.vfs2.provider.AbstractFileName; import org.apache.commons.vfs2.provider.AbstractFileObject; -import org.apache.commons.vfs2.util.ArrayUtils; /** * A file in a Tar file system. diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java index 935faf3..14b6038 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/zip/ZipFileObject.java @@ -20,12 +20,12 @@ import java.io.InputStream; import java.util.HashSet; import java.util.zip.ZipEntry; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; import org.apache.commons.vfs2.provider.AbstractFileName; import org.apache.commons.vfs2.provider.AbstractFileObject; -import org.apache.commons.vfs2.util.ArrayUtils; /** * A file in a ZIP file system. diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/ArrayUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/ArrayUtils.java deleted file mode 100644 index 1f3d4dd..0000000 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/ArrayUtils.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.vfs2.util; - -/** - * Array utilities. - * - * See Apache Commons Lang. - * @since 2.9.0 - */ -public class ArrayUtils { - - /** - * An empty immutable {@code String} array. - */ - public static final String[] EMPTY_STRING_ARRAY = new String[0]; - -} diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DurationUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DurationUtils.java deleted file mode 100644 index eba9c02..0000000 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/DurationUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.commons.vfs2.util; - -import java.time.Duration; - -/** Temporary until Commons Lang 3.12.0. */ -public class DurationUtils { - - /** Temporary until Commons Lang 3.12.0. */ - public static int toMillisInt(final Duration duration) { - final long millis = duration.toMillis(); - return millis > 0 ? (int) Math.min(millis, Integer.MAX_VALUE) : (int) Math.max(millis, Integer.MIN_VALUE); - } - -} diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java index e226b73..b2f922d 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Messages.java @@ -22,13 +22,13 @@ import java.util.ResourceBundle; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.apache.commons.lang3.ArrayUtils; + /** * Formats messages. */ public final class Messages { - private static final Object[] EMPTY_OBJECT_ARRAY = new Object[0]; - /** * Map from message code to MessageFormat object for the message. */ @@ -50,7 +50,7 @@ public final class Messages { * @return The formatted message. */ public static String getString(final String code) { - return getString(code, EMPTY_OBJECT_ARRAY); + return getString(code, ArrayUtils.EMPTY_OBJECT_ARRAY); } /** diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Os.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Os.java index b76fb34..3ab8f68 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Os.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/Os.java @@ -24,9 +24,14 @@ import java.util.List; import java.util.Locale; import java.util.Set; +import org.apache.commons.lang3.SystemUtils; + /** * Class to help determining the OS. + * + * @deprecated Use Apache Commons Lang's {@link SystemUtils}. Remove in 3.0. */ +@Deprecated public final class Os { /** diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/OsFamily.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/OsFamily.java index 00b78fd..1ec92f0 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/OsFamily.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/OsFamily.java @@ -16,9 +16,14 @@ */ package org.apache.commons.vfs2.util; +import org.apache.commons.lang3.SystemUtils; + /** * An enumerated type, which represents an OS family. + * + * @deprecated Use Apache Commons Lang's {@link SystemUtils}. Remove in 3.0. */ +@Deprecated public final class OsFamily { private final String name; diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java index 14e4ff7..21a0c58 100644 --- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java +++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/util/URIUtils.java @@ -22,6 +22,7 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.BitSet; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.provider.GenericURLFileName; @@ -74,7 +75,7 @@ public class URIUtils { throw new IllegalArgumentException("data may not be null"); } - if (charsetName == null || charsetName.isEmpty()) { + if (StringUtils.isEmpty(charsetName)) { throw new IllegalArgumentException("charset may not be null or empty"); } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProviderTest.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProviderTest.java index 502f85d..3f664e7 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProviderTest.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileProviderTest.java @@ -23,6 +23,7 @@ import java.io.InputStreamReader; import java.util.Map; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -106,7 +107,7 @@ public class HdfsFileProviderTest { * Will do nothing on Windows. */ public static void setUmask(final Configuration conf2) { - if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) { + if (SystemUtils.IS_OS_WINDOWS) { return; } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java index ca89c97..48aee61 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalProviderTestCase.java @@ -19,6 +19,7 @@ package org.apache.commons.vfs2.provider.local; import java.io.File; import org.apache.commons.AbstractVfsTestCase; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.vfs2.AbstractProviderTestConfig; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; @@ -44,7 +45,7 @@ public class LocalProviderTestCase extends AbstractProviderTestConfig { testSuite.addTests(UrlTests.class); testSuite.addTests(PermissionsTests.class); - if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) { + if (SystemUtils.IS_OS_WINDOWS) { testSuite.addTests(WindowsFileNameTests.class); } diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/FileLockTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/FileLockTestCase.java index 3b6f5ed..d436c0d 100644 --- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/FileLockTestCase.java +++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/FileLockTestCase.java @@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemManager; @@ -89,7 +90,7 @@ public class FileLockTestCase { public void testCannotDeleteWhileStreaming() throws Exception { try (final FileObject zipFileObject = manager.resolveFile(zipFileUri)) { try (InputStream inputStream = zipFileObject.getContent().getInputStream()) { - if (Os.isFamily(Os.OS_FAMILY_WINDOWS)) { + if (SystemUtils.IS_OS_WINDOWS) { // We do not use newZipFile in the Assert message to avoid touching it before calling delete(). Assert.assertFalse("Could not delete file", newZipFile.delete()); } @@ -100,7 +101,7 @@ public class FileLockTestCase { @Test public void testCannotDeleteWhileStreaming2() throws Exception { - Assume.assumeTrue(Os.isFamily(Os.OS_FAMILY_WINDOWS)); + Assume.assumeTrue(SystemUtils.IS_OS_WINDOWS); try (final FileObject zipFileObject = manager.resolveFile(zipFileUri)) { try (InputStream inputStream = zipFileObject.getContent().getInputStream()) { // We do not use newZipFile in the Assert message to avoid touching it before calling delete().