[FTP] Add Duration APIs for timeouts.
- Add FtpFileSystemConfigBuilder.setConnectTimeout(FileSystemOptions,
Duration) and deprecate Integer version.
- Add FtpFileSystemConfigBuilder.setDataTimeout(FileSystemOptions,
Duration) and deprecate Integer version.
- Add FtpFileSystemConfigBuilder.setSoTimeout(FileSystemOptions,
Duration) and deprecate Integer version.
- Add FtpFileSystemConfigBuilder.getConnectTimeoutDuration(FileSystemOptions)
and deprecate Integer version.
- Add FtpFileSystemConfigBuilder.getDataTimeoutDuration(FileSystemOptions)
and deprecate Integer version.
- Add FtpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions)
and deprecate Integer version.
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 909996f..10cf7c1 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
@@ -202,7 +202,7 @@
// VFS-307: now try the hard way by cd'ing into the directory, list and cd back
// if VFS is required to fallback here the user might experience a real bad FTP performance
- // as then every list requires 4 ftp commands.
+ // as then every list requires 4 FTP commands.
String workingDirectory = null;
if (relPath != null) {
workingDirectory = getFtpClient().printWorkingDirectory();
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 4576e60..4d6c40f 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
@@ -140,10 +140,9 @@
}
try {
- // Set connect timeout
- final Integer connectTimeoutMillis = builder.getConnectTimeout(fileSystemOptions);
- if (connectTimeoutMillis != null) {
- client.setDefaultTimeout(connectTimeoutMillis.intValue());
+ final Duration connectTimeout = builder.getConnectTimeoutDuration(fileSystemOptions);
+ if (connectTimeout != null) {
+ client.setDefaultTimeout(toIntMillisTimeout(connectTimeout));
}
final String controlEncoding = builder.getControlEncoding(fileSystemOptions);
@@ -185,14 +184,14 @@
}
// Set dataTimeout value
- final Integer dataTimeoutMillis = builder.getDataTimeout(fileSystemOptions);
- if (dataTimeoutMillis != null) {
- client.setDataTimeout(dataTimeoutMillis.intValue());
+ final Duration dataTimeout = builder.getDataTimeoutDuration(fileSystemOptions);
+ if (dataTimeout != null) {
+ client.setDataTimeout(toIntMillisTimeout(dataTimeout));
}
- final Integer socketTimeout = builder.getSoTimeout(fileSystemOptions);
+ final Duration socketTimeout = builder.getSoTimeoutDuration(fileSystemOptions);
if (socketTimeout != null) {
- client.setSoTimeout(socketTimeout.intValue());
+ client.setSoTimeout(toIntMillisTimeout(socketTimeout));
}
final Duration controlKeepAliveTimeout = builder.getControlKeepAliveTimeout(fileSystemOptions);
@@ -235,6 +234,10 @@
}
protected abstract void setupOpenConnection(C client, FileSystemOptions fileSystemOptions) throws IOException;
+
+ private int toIntMillisTimeout(final Duration duration) {
+ return (int) Math.min(duration.toMillis(), Integer.MAX_VALUE);
+ }
}
/** Connection Factory, used to configure the FTPClient. */
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 1c78ef3..ceaeda9 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
@@ -304,7 +304,7 @@
}
/**
- * Get the last modified time on an ftp file
+ * Get the last modified time on an FTP file
*
* @see org.apache.commons.vfs2.provider.AbstractFileObject#doGetLastModifiedTime()
*/
@@ -448,7 +448,7 @@
}
/**
- * Called by child file objects, to locate their ftp file info.
+ * Called by child file objects, to locate their FTP file info.
*
* @param name the file name in its native form ie. without URI stuff (%nn)
* @param flush recreate children cache
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
index 27c9469..1323516 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileSystemConfigBuilder.java
@@ -30,7 +30,7 @@
import org.apache.commons.vfs2.FileSystemOptions;
/**
- * The config builder for various ftp configuration options.
+ * The config builder for various FTP configuration options.
*/
public class FtpFileSystemConfigBuilder extends FileSystemConfigBuilder {
@@ -39,8 +39,8 @@
private static final FtpFileSystemConfigBuilder BUILDER = new FtpFileSystemConfigBuilder();
private static final String AUTODETECT_UTF8 = _PREFIX + ".AUTODETECT_UTF8";
- private static final String CONNECT_TIMEOUT_MILLIS = _PREFIX + ".CONNECT_TIMEOUT";
- private static final String DATA_TIMEOUT_MILLIS = _PREFIX + ".DATA_TIMEOUT";
+ private static final String CONNECT_TIMEOUT = _PREFIX + ".CONNECT_TIMEOUT";
+ private static final String DATA_TIMEOUT = _PREFIX + ".DATA_TIMEOUT";
private static final String DEFAULT_DATE_FORMAT = _PREFIX + ".DEFAULT_DATE_FORMAT";
private static final String ENCODING = _PREFIX + ".ENCODING";
private static final String FACTORY_KEY = FTPFileEntryParserFactory.class.getName() + ".KEY";
@@ -90,12 +90,12 @@
/**
* Gets whether to try to autodetect the server encoding (only UTF8 is supported).
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return True if autodetection should be done.
* @since 2.4
*/
- public Boolean getAutodetectUtf8(final FileSystemOptions opts) {
- return getBoolean(opts, AUTODETECT_UTF8);
+ public Boolean getAutodetectUtf8(final FileSystemOptions options) {
+ return getBoolean(options, AUTODETECT_UTF8);
}
@Override
@@ -106,190 +106,232 @@
/**
* Gets the timeout in milliseconds to use for the socket connection.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return The timeout in milliseconds to use for the socket connection.
* @since 2.1
+ * @deprecated Use {@link #getConnectTimeoutDuration(FileSystemOptions)}.
*/
- public Integer getConnectTimeout(final FileSystemOptions opts) {
- return getInteger(opts, CONNECT_TIMEOUT_MILLIS);
+ public Integer getConnectTimeout(final FileSystemOptions options) {
+ return (int) getConnectTimeoutDuration(options).toMillis();
}
/**
- * @param opts The FileSystemOptions.
+ * Gets the timeout in milliseconds to use for the socket connection.
+ *
+ * @param options The FileSystemOptions.
+ * @return The timeout in milliseconds to use for the socket connection.
+ * @since 2.8.0
+ */
+ public Duration getConnectTimeoutDuration(final FileSystemOptions options) {
+ return getDuration(options, CONNECT_TIMEOUT);
+ }
+
+ /**
+ * @param options The FileSystemOptions.
* @return The encoding.
* @since 2.0
*/
- public String getControlEncoding(final FileSystemOptions opts) {
- return getString(opts, ENCODING);
+ public String getControlEncoding(final FileSystemOptions options) {
+ return getString(options, ENCODING);
}
/**
- * @param opts The FileSystem options
+ * @param options The FileSystem options
* @return The controlKeepAliveReplyTimeout value.
* @since 2.8.0
*/
- public Duration getControlKeepAliveReplyTimeout(FileSystemOptions opts) {
- return getDuration(opts, CONTROL_KEEP_ALIVE_REPLY_TIMEOUT);
+ public Duration getControlKeepAliveReplyTimeout(FileSystemOptions options) {
+ return getDuration(options, CONTROL_KEEP_ALIVE_REPLY_TIMEOUT);
}
/**
- * @param opts The FileSystem options
+ * @param options The FileSystem options
* @return The controlKeepAliveTimeout value.
* @since 2.8.0
*/
- public Duration getControlKeepAliveTimeout(FileSystemOptions opts) {
- return getDuration(opts, CONTROL_KEEP_ALIVE_TIMEOUT);
+ public Duration getControlKeepAliveTimeout(FileSystemOptions options) {
+ return getDuration(options, CONTROL_KEEP_ALIVE_TIMEOUT);
}
/**
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return The timeout for opening the data channel in milliseconds.
* @see #setDataTimeout
+ * @deprecated Use {@link #getDataTimeoutDuration(FileSystemOptions)}.
*/
- public Integer getDataTimeout(final FileSystemOptions opts) {
- return getInteger(opts, DATA_TIMEOUT_MILLIS);
+ @Deprecated
+ public Integer getDataTimeout(final FileSystemOptions options) {
+ return (int) getDataTimeoutDuration(options).toMillis();
+ }
+
+ /**
+ * Gets the timeout for opening the data channel.
+ *
+ * @param options The FileSystemOptions.
+ * @return The timeout for opening the data channel.
+ * @see #setDataTimeout
+ * @since 2.8.0
+ */
+ public Duration getDataTimeoutDuration(final FileSystemOptions options) {
+ return getDuration(options, DATA_TIMEOUT);
}
/**
* Get the default date format used by the server. See {@link org.apache.commons.net.ftp.FTPClientConfig} for
* details and examples.
*
- * @param opts The FileSystemOptions
+ * @param options The FileSystemOptions
* @return The default date format.
*/
- public String getDefaultDateFormat(final FileSystemOptions opts) {
- return getString(opts, DEFAULT_DATE_FORMAT);
+ public String getDefaultDateFormat(final FileSystemOptions options) {
+ return getString(options, DEFAULT_DATE_FORMAT);
}
/**
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @see #setEntryParser
* @return the key to the EntryParser.
*/
- public String getEntryParser(final FileSystemOptions opts) {
- return getString(opts, FACTORY_KEY);
+ public String getEntryParser(final FileSystemOptions options) {
+ return getString(options, FACTORY_KEY);
}
/**
- * @param opts The FlleSystemOptions.
+ * @param options The FlleSystemOptions.
* @see #setEntryParserFactory
* @return An FTPFileEntryParserFactory.
*/
- public FTPFileEntryParserFactory getEntryParserFactory(final FileSystemOptions opts) {
- return getParam(opts, FTPFileEntryParserFactory.class.getName());
+ public FTPFileEntryParserFactory getEntryParserFactory(final FileSystemOptions options) {
+ return getParam(options, FTPFileEntryParserFactory.class.getName());
}
/**
* Gets the file type parameter.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return A FtpFileType
* @since 2.1
*/
- public FtpFileType getFileType(final FileSystemOptions opts) {
- return getEnum(FtpFileType.class, opts, FILE_TYPE);
+ public FtpFileType getFileType(final FileSystemOptions options) {
+ return getEnum(FtpFileType.class, options, FILE_TYPE);
}
/**
* Gets the option to use FTP MDTM for {@link FileContent#getLastModifiedTime()}.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return true if MDTM should be used.
* @since 2.8.0
*/
- public Boolean getMdtmLastModifiedTime(final FileSystemOptions opts) {
- return getBoolean(opts, MDTM_LAST_MODIFED_TIME);
+ public Boolean getMdtmLastModifiedTime(final FileSystemOptions options) {
+ return getBoolean(options, MDTM_LAST_MODIFED_TIME);
}
/**
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return true if passive mode is set.
* @see #setPassiveMode
*/
- public Boolean getPassiveMode(final FileSystemOptions opts) {
- return getBoolean(opts, PASSIVE_MODE);
+ public Boolean getPassiveMode(final FileSystemOptions options) {
+ return getBoolean(options, PASSIVE_MODE);
}
/**
* Gets the Proxy.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return the Proxy
* @since 2.1
*/
- public Proxy getProxy(final FileSystemOptions opts) {
- return getParam(opts, PROXY);
+ public Proxy getProxy(final FileSystemOptions options) {
+ return getParam(options, PROXY);
}
/**
* See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return The recent date format.
*/
- public String getRecentDateFormat(final FileSystemOptions opts) {
- return getString(opts, RECENT_DATE_FORMAT);
+ public String getRecentDateFormat(final FileSystemOptions options) {
+ return getString(options, RECENT_DATE_FORMAT);
}
/**
* Gets whether to use remote verification.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return True if remote verification should be done.
*/
- public Boolean getRemoteVerification(final FileSystemOptions opts) {
- return getBoolean(opts, REMOTE_VERIFICATION);
+ public Boolean getRemoteVerification(final FileSystemOptions options) {
+ return getBoolean(options, REMOTE_VERIFICATION);
}
/**
* Get the language code used by the server. See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and
* examples.
*
- * @param opts The FilesystemOptions.
+ * @param options The FilesystemOptions.
* @return The language code of the server.
*/
- public String getServerLanguageCode(final FileSystemOptions opts) {
- return getString(opts, SERVER_LANGUAGE_CODE);
+ public String getServerLanguageCode(final FileSystemOptions options) {
+ return getString(options, SERVER_LANGUAGE_CODE);
}
/**
* See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return The server timezone id.
*/
- public String getServerTimeZoneId(final FileSystemOptions opts) {
- return getString(opts, SERVER_TIME_ZONE_ID);
+ public String getServerTimeZoneId(final FileSystemOptions options) {
+ return getString(options, SERVER_TIME_ZONE_ID);
}
/**
* See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return An array of short month names.
*/
- public String[] getShortMonthNames(final FileSystemOptions opts) {
- return getParam(opts, SHORT_MONTH_NAMES);
+ public String[] getShortMonthNames(final FileSystemOptions options) {
+ return getParam(options, SHORT_MONTH_NAMES);
}
/**
- * @param opts The FileSystem options.
- * @return The timeout value in milliseconds.
+ * Gets The so timeout duration in milliseconds.
+ *
+ * @param options The FileSystem options.
+ * @return The so timeout duration in milliseconds.
* @see #getDataTimeout
* @since 2.0
+ * @deprecated Use {@link #getSoTimeoutDuration(FileSystemOptions)}.
*/
- public Integer getSoTimeout(final FileSystemOptions opts) {
- return getInteger(opts, SO_TIMEOUT);
+ @Deprecated
+ public Integer getSoTimeout(final FileSystemOptions options) {
+ return (int) getSoTimeoutDuration(options).toMillis();
}
/**
- * @param opts The FileSystem options.
+ * Gets The so timeout duration.
+ *
+ * @param options The FileSystem options.
+ * @return The timeout value in milliseconds.
+ * @see #getDataTimeout
+ * @since 2.8.0
+ */
+ public Duration getSoTimeoutDuration(final FileSystemOptions options) {
+ return getDuration(options, SO_TIMEOUT);
+ }
+
+ /**
+ * @param options The FileSystem options.
* @return The list of reply codes (apart from 200) that are considered as OK when prematurely
* closing a stream.
* @since 2.4
*/
- public List<Integer> getTransferAbortedOkReplyCodes(final FileSystemOptions opts) {
- return getParam(opts, TRANSFER_ABORTED_OK_REPLY_CODES);
+ public List<Integer> getTransferAbortedOkReplyCodes(final FileSystemOptions options) {
+ return getParam(options, TRANSFER_ABORTED_OK_REPLY_CODES);
}
/**
@@ -297,23 +339,23 @@
* {@code Boolean.TRUE} if the method {@link #setUserDirIsRoot(FileSystemOptions, boolean)} has not been
* invoked.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @return {@code Boolean.TRUE} if VFS treats the user directory as the root directory.
* @see #setUserDirIsRoot
*/
- public Boolean getUserDirIsRoot(final FileSystemOptions opts) {
- return getBoolean(opts, USER_DIR_IS_ROOT, Boolean.TRUE);
+ public Boolean getUserDirIsRoot(final FileSystemOptions options) {
+ return getBoolean(options, USER_DIR_IS_ROOT, Boolean.TRUE);
}
/**
* Sets whether to try to autodetect the server encoding (only UTF8 is supported).
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param autodetectUTF8 true if autodetection should be done.
* @since 2.4
*/
- public void setAutodetectUtf8(final FileSystemOptions opts, final Boolean autodetectUTF8) {
- setParam(opts, AUTODETECT_UTF8, autodetectUTF8);
+ public void setAutodetectUtf8(final FileSystemOptions options, final Boolean autodetectUTF8) {
+ setParam(options, AUTODETECT_UTF8, autodetectUTF8);
}
/**
@@ -322,34 +364,50 @@
* If you set the connectTimeout to {@code null} no connectTimeout will be set.
* </p>
*
- * @param opts The FileSystemOptions.
- * @param connectTimeout the timeout value in milliseconds
- * @since 2.1
+ * @param options The FileSystemOptions.
+ * @param duration the timeout duration in milliseconds
+ * @since 2.8.0
*/
- public void setConnectTimeout(final FileSystemOptions opts, final Integer connectTimeout) {
- setParam(opts, CONNECT_TIMEOUT_MILLIS, connectTimeout);
+ public void setConnectTimeout(final FileSystemOptions options, final Duration duration) {
+ setParam(options, CONNECT_TIMEOUT, duration);
+ }
+
+ /**
+ * Sets the timeout for the initial control connection.
+ * <p>
+ * If you set the connectTimeout to {@code null} no connectTimeout will be set.
+ * </p>
+ *
+ * @param options The FileSystemOptions.
+ * @param duration the timeout duration.
+ * @since 2.1
+ * @deprecated Use {@link #setConnectTimeout(FileSystemOptions, Duration)}.
+ */
+ @Deprecated
+ public void setConnectTimeout(final FileSystemOptions options, final Integer duration) {
+ setConnectTimeout(options, Duration.ofMillis(duration));
}
/**
* See {@link org.apache.commons.net.ftp.FTP#setControlEncoding} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param encoding the encoding to use
* @since 2.0
*/
- public void setControlEncoding(final FileSystemOptions opts, final String encoding) {
- setParam(opts, ENCODING, encoding);
+ public void setControlEncoding(final FileSystemOptions options, final String encoding) {
+ setParam(options, ENCODING, encoding);
}
/**
* Sets the control keep alive reply timeout for the FTP client.
*
- * @param opts The FileSystem options.
- * @param controlKeepAliveReplyTimeout timeout duration.
+ * @param options The FileSystem options.
+ * @param duration timeout duration.
* @since 2.8.0
*/
- public void setControlKeepAliveReplyTimeout(FileSystemOptions opts, final Duration controlKeepAliveReplyTimeout) {
- setParam(opts, CONTROL_KEEP_ALIVE_REPLY_TIMEOUT, controlKeepAliveReplyTimeout);
+ public void setControlKeepAliveReplyTimeout(FileSystemOptions options, final Duration duration) {
+ setParam(options, CONTROL_KEEP_ALIVE_REPLY_TIMEOUT, duration);
}
/**
@@ -358,36 +416,52 @@
* Set the {@code controlKeepAliveTimeout} to ensure the socket be alive after download huge file.
* </p>
*
- * @param opts The FileSystem options.
- * @param controlKeepAliveTimeout The timeout duration.
+ * @param options The FileSystem options.
+ * @param duration The timeout duration.
* @since 2.8.0
*/
- public void setControlKeepAliveTimeout(FileSystemOptions opts, final Duration controlKeepAliveTimeout) {
- setParam(opts, CONTROL_KEEP_ALIVE_TIMEOUT, controlKeepAliveTimeout);
+ public void setControlKeepAliveTimeout(FileSystemOptions options, final Duration duration) {
+ setParam(options, CONTROL_KEEP_ALIVE_TIMEOUT, duration);
}
/**
- * Set the data timeout for the ftp client.
+ * Set the data timeout for the FTP client.
* <p>
- * If you set the {@code dataTimeout} to {@code null}, no dataTimeout will be set on the ftp client.
+ * If you set the {@code dataTimeout} to {@code null}, no dataTimeout will be set on the FTP client.
* </p>
*
- * @param opts The FileSystemOptions.
- * @param dataTimeout The timeout value.
+ * @param options The FileSystemOptions.
+ * @param duration The timeout duration.
+ * @since 2.8.0
*/
- public void setDataTimeout(final FileSystemOptions opts, final Integer dataTimeout) {
- setParam(opts, DATA_TIMEOUT_MILLIS, dataTimeout);
+ public void setDataTimeout(final FileSystemOptions options, final Duration duration) {
+ setParam(options, DATA_TIMEOUT, duration);
+ }
+
+ /**
+ * Set the data timeout for the FTP client.
+ * <p>
+ * If you set the {@code dataTimeout} to {@code null}, no dataTimeout will be set on the FTP client.
+ * </p>
+ *
+ * @param options The FileSystemOptions.
+ * @param duration The timeout value.
+ * @deprecated Use {@link #setDataTimeout(FileSystemOptions, Duration)}.
+ */
+ @Deprecated
+ public void setDataTimeout(final FileSystemOptions options, final Integer duration) {
+ setDataTimeout(options, Duration.ofMillis(duration));
}
/**
* Set the default date format used by the server. See {@link org.apache.commons.net.ftp.FTPClientConfig} for
* details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param defaultDateFormat The default date format.
*/
- public void setDefaultDateFormat(final FileSystemOptions opts, final String defaultDateFormat) {
- setParam(opts, DEFAULT_DATE_FORMAT, defaultDateFormat);
+ public void setDefaultDateFormat(final FileSystemOptions options, final String defaultDateFormat) {
+ setParam(options, DEFAULT_DATE_FORMAT, defaultDateFormat);
}
/**
@@ -397,53 +471,53 @@
* this is the "key" parameter passed as argument into your custom factory.
* </p>
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param key The key.
*/
- public void setEntryParser(final FileSystemOptions opts, final String key) {
- setParam(opts, FACTORY_KEY, key);
+ public void setEntryParser(final FileSystemOptions options, final String key) {
+ setParam(options, FACTORY_KEY, key);
}
/**
* FTPFileEntryParserFactory which will be used for ftp-entry parsing.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param factory instance of your factory
*/
- public void setEntryParserFactory(final FileSystemOptions opts, final FTPFileEntryParserFactory factory) {
- setParam(opts, FTPFileEntryParserFactory.class.getName(), factory);
+ public void setEntryParserFactory(final FileSystemOptions options, final FTPFileEntryParserFactory factory) {
+ setParam(options, FTPFileEntryParserFactory.class.getName(), factory);
}
/**
* Sets the file type parameter.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param ftpFileType A FtpFileType
* @since 2.1
*/
- public void setFileType(final FileSystemOptions opts, final FtpFileType ftpFileType) {
- setParam(opts, FILE_TYPE, ftpFileType);
+ public void setFileType(final FileSystemOptions options, final FtpFileType ftpFileType) {
+ setParam(options, FILE_TYPE, ftpFileType);
}
/**
* Sets the option to use FTP MDTM for {@link FileContent#getLastModifiedTime()}.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param mdtm true if MDTM should be used.
* @since 2.8.0
*/
- public void setMdtmLastModifiedTime(final FileSystemOptions opts, final boolean mdtm) {
- setParam(opts, MDTM_LAST_MODIFED_TIME, toBooleanObject(mdtm));
+ public void setMdtmLastModifiedTime(final FileSystemOptions options, final boolean mdtm) {
+ setParam(options, MDTM_LAST_MODIFED_TIME, toBooleanObject(mdtm));
}
/**
* Enter into passive mode.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param passiveMode true if passive mode should be used.
*/
- public void setPassiveMode(final FileSystemOptions opts, final boolean passiveMode) {
- setParam(opts, PASSIVE_MODE, toBooleanObject(passiveMode));
+ public void setPassiveMode(final FileSystemOptions options, final boolean passiveMode) {
+ setParam(options, PASSIVE_MODE, toBooleanObject(passiveMode));
}
/**
@@ -452,83 +526,99 @@
* You might need to make sure that {@link #setPassiveMode(FileSystemOptions, boolean) passive mode} is activated.
* </p>
*
- * @param opts the FileSystem options.
+ * @param options the FileSystem options.
* @param proxy the Proxy
* @since 2.1
*/
- public void setProxy(final FileSystemOptions opts, final Proxy proxy) {
- setParam(opts, PROXY, proxy);
+ public void setProxy(final FileSystemOptions options, final Proxy proxy) {
+ setParam(options, PROXY, proxy);
}
/**
* See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param recentDateFormat The recent date format.
*/
- public void setRecentDateFormat(final FileSystemOptions opts, final String recentDateFormat) {
- setParam(opts, RECENT_DATE_FORMAT, recentDateFormat);
+ public void setRecentDateFormat(final FileSystemOptions options, final String recentDateFormat) {
+ setParam(options, RECENT_DATE_FORMAT, recentDateFormat);
}
/**
* Sets whether to use remote verification.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param remoteVerification True if verification should be done.
*/
- public void setRemoteVerification(final FileSystemOptions opts, final boolean remoteVerification) {
- setParam(opts, REMOTE_VERIFICATION, remoteVerification);
+ public void setRemoteVerification(final FileSystemOptions options, final boolean remoteVerification) {
+ setParam(options, REMOTE_VERIFICATION, remoteVerification);
}
/**
* Set the language code used by the server. See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and
* examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param serverLanguageCode The servers language code.
*/
- public void setServerLanguageCode(final FileSystemOptions opts, final String serverLanguageCode) {
- setParam(opts, SERVER_LANGUAGE_CODE, serverLanguageCode);
+ public void setServerLanguageCode(final FileSystemOptions options, final String serverLanguageCode) {
+ setParam(options, SERVER_LANGUAGE_CODE, serverLanguageCode);
}
/**
* See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param serverTimeZoneId The server timezone id.
*/
- public void setServerTimeZoneId(final FileSystemOptions opts, final String serverTimeZoneId) {
- setParam(opts, SERVER_TIME_ZONE_ID, serverTimeZoneId);
+ public void setServerTimeZoneId(final FileSystemOptions options, final String serverTimeZoneId) {
+ setParam(options, SERVER_TIME_ZONE_ID, serverTimeZoneId);
}
/**
* See {@link org.apache.commons.net.ftp.FTPClientConfig} for details and examples.
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param shortMonthNames an array of short month name Strings.
*/
- public void setShortMonthNames(final FileSystemOptions opts, final String[] shortMonthNames) {
+ public void setShortMonthNames(final FileSystemOptions options, final String[] shortMonthNames) {
String[] clone = null;
if (shortMonthNames != null) {
clone = new String[shortMonthNames.length];
System.arraycopy(shortMonthNames, 0, clone, 0, shortMonthNames.length);
}
- setParam(opts, SHORT_MONTH_NAMES, clone);
+ setParam(options, SHORT_MONTH_NAMES, clone);
}
/**
* Sets the socket timeout for the FTP client.
* <p>
- * If you set the {@code soTimeout} to {@code null}, no socket timeout will be set on the ftp client.
+ * If you set the {@code soTimeout} to {@code null}, no socket timeout will be set on the FTP client.
* </p>
*
- * @param opts The FileSystem options.
- * @param soTimeout The timeout value in milliseconds.
- * @since 2.0
+ * @param options The FileSystem options.
+ * @param duration The timeout value in milliseconds.
+ * @since 2.8.0
*/
- public void setSoTimeout(final FileSystemOptions opts, final Integer soTimeout) {
- setParam(opts, SO_TIMEOUT, soTimeout);
+ public void setSoTimeout(final FileSystemOptions options, final Duration duration) {
+ setParam(options, SO_TIMEOUT, duration);
+ }
+
+ /**
+ * Sets the socket timeout for the FTP client.
+ * <p>
+ * If you set the {@code soTimeout} to {@code null}, no socket timeout will be set on the FTP client.
+ * </p>
+ *
+ * @param options The FileSystem options.
+ * @param duration The timeout value in milliseconds.
+ * @since 2.0
+ * @deprecated Use {@link #setSoTimeout(FileSystemOptions, Duration)}.
+ */
+ @Deprecated
+ public void setSoTimeout(final FileSystemOptions options, final Integer duration) {
+ setSoTimeout(options, Duration.ofMillis(duration));
}
/**
@@ -538,21 +628,21 @@
* considered as an error.
* </p>
*
- * @param opts The FileSystem options.
+ * @param options The FileSystem options.
* @param replyCodes The reply codes.
* @since 2.4
*/
- public void setTransferAbortedOkReplyCodes(final FileSystemOptions opts, final List<Integer> replyCodes) {
- setParam(opts, TRANSFER_ABORTED_OK_REPLY_CODES, replyCodes);
+ public void setTransferAbortedOkReplyCodes(final FileSystemOptions options, final List<Integer> replyCodes) {
+ setParam(options, TRANSFER_ABORTED_OK_REPLY_CODES, replyCodes);
}
/**
* Use user directory as root (do not change to fs root).
*
- * @param opts The FileSystemOptions.
+ * @param options The FileSystemOptions.
* @param userDirIsRoot true if the user directory should be treated as the root.
*/
- public void setUserDirIsRoot(final FileSystemOptions opts, final boolean userDirIsRoot) {
- setParam(opts, USER_DIR_IS_ROOT, toBooleanObject(userDirIsRoot));
+ public void setUserDirIsRoot(final FileSystemOptions options, final boolean userDirIsRoot) {
+ setParam(options, USER_DIR_IS_ROOT, toBooleanObject(userDirIsRoot));
}
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java
index 92da202..143f505 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/res/ResourceFileSystemConfigBuilder.java
@@ -22,7 +22,7 @@
import org.apache.commons.vfs2.provider.url.UrlFileSystem;
/**
- * The config BUILDER for various ftp configuration options.
+ * The config BUILDER for various FTP configuration options.
*/
public final class ResourceFileSystemConfigBuilder extends FileSystemConfigBuilder {
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
index f29367c..41f0f04 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftp/FtpProviderTestCase.java
@@ -235,7 +235,7 @@
builder.setPassiveMode(options, true);
// FtpFileType.BINARY is the default
builder.setFileType(options, FtpFileType.BINARY);
- builder.setConnectTimeout(options, 10000);
+ builder.setConnectTimeout(options, Duration.ofSeconds(10));
builder.setControlEncoding(options, "UTF-8");
builder.setControlKeepAliveReplyTimeout(options, Duration.ofSeconds(35));
builder.setControlKeepAliveTimeout(options, Duration.ofSeconds(30));
diff --git a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java
index 42e6fc4..d7ce462 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/ftps/AbstractFtpsProviderTestCase.java
@@ -19,6 +19,7 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.time.Duration;
import org.apache.commons.io.FileUtils;
import org.apache.commons.vfs2.AbstractProviderTestConfig;
@@ -183,8 +184,8 @@
}
protected void setupOptions(final FtpsFileSystemConfigBuilder builder) {
- builder.setConnectTimeout(fileSystemOptions, Integer.valueOf(1000));
- builder.setDataTimeout(fileSystemOptions, Integer.valueOf(2000));
+ builder.setConnectTimeout(fileSystemOptions, Duration.ofSeconds(1));
+ builder.setDataTimeout(fileSystemOptions, Duration.ofSeconds(2));
}
/**
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 89bb0bd..81a10ed 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -85,6 +85,24 @@
<action issue="VFS-257" dev="ggregory" due-to="Andrew Franklin, Michael Graham, Gary Gregory" type="add">
[FTP] Add support for MDTM to get more accurate last modified times.
</action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ Add FtpFileSystemConfigBuilder.setConnectTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ Add FtpFileSystemConfigBuilder.setDataTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ Add FtpFileSystemConfigBuilder.setSoTimeout(FileSystemOptions, Duration) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ Add FtpFileSystemConfigBuilder.getConnectTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ Add FtpFileSystemConfigBuilder.getDataTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ </action>
+ <action dev="ggregory" due-to="Gary Gregory" type="add">
+ Add FtpFileSystemConfigBuilder.getSoTimeoutDuration(FileSystemOptions) and deprecate Integer version.
+ </action>
<!-- UPDATES -->
<action dev="ggregory" due-to="PeterAlfredLee" type="update">
Modify some code use for-each loop and stream API #142.