You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2024/02/24 17:36:42 UTC
(commons-net) 02/02: Better names
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-net.git
commit 3daaf49c462ac72b513ebe2cd109efeabeeaa1bc
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Feb 24 12:36:39 2024 -0500
Better names
---
src/main/java/org/apache/commons/net/ftp/FTP.java | 9 ++++-----
.../java/org/apache/commons/net/ftp/FTPClient.java | 20 +++++++++-----------
.../apache/commons/net/ftp/FTPClientDeflateTest.java | 6 +++---
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java b/src/main/java/org/apache/commons/net/ftp/FTP.java
index a956e6a1..72945cc4 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -147,16 +147,15 @@ public class FTP extends SocketClient {
/**
* A constant used to indicate a file is to be transferred as FTP compressed data. All constants ending in <code>TRANSFER_MODE</code> are used to indicate
- * file transfer modes.
+ * file transfer modes. Currently unused.
*/
public static final int COMPRESSED_TRANSFER_MODE = 12;
/**
- * A constant used to indicate a file is to be transferred as FTP compressed
- * data with MODE Z (zlib). All constants ending in <code>TRANSFER_MODE</code> are used to indicate
- * file transfer modes.
+ * A constant used to indicate a file is to be transferred as FTP (un)compressing data in the "deflate" compression format. All constants ending in
+ * <code>TRANSFER_MODE</code> are used to indicate file transfer modes.
*/
- public static final int COMPRESSED_MODE_Z_TRANSFER_MODE = 13;
+ public static final int DEFLATE_TRANSFER_MODE = 13;
// We have to ensure that the protocol communication is in ASCII,
// but we use ISO-8859-1 just in case 8-bit characters cross
diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index b4a5459a..62d33d20 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -446,8 +446,8 @@ public class FTPClient extends FTP implements Configurable {
* Parse the pathname from a CWD reply.
* <p>
* According to <a href="http://www.ietf.org/rfc/rfc959.txt">RFC959</a>, it should be the same as for MKD i.e.
- * {@code 257<space>"<directory-name>"[<space>commentary]} where any double-quotes in {@code <directory-name>} are doubled.
- * Unlike MKD, the commentary is optional.
+ * {@code 257<space>"<directory-name>"[<space>commentary]} where any double-quotes in {@code <directory-name>} are doubled. Unlike MKD, the commentary is
+ * optional.
* <p>
* However, see NET-442 for an exception.
*
@@ -713,7 +713,7 @@ public class FTPClient extends FTP implements Configurable {
server.setSoTimeout(soTimeoutMillis);
}
- socket = wrapSocketIfModeZisEnabled(server.accept());
+ socket = wrapOnDeflate(server.accept());
// Ensure the timeout is set before any commands are issued on the new socket
if (soTimeoutMillis >= 0) {
@@ -749,7 +749,7 @@ public class FTPClient extends FTP implements Configurable {
_parsePassiveModeReply(_replyLines.get(0));
}
- socket = wrapSocketIfModeZisEnabled(_socketFactory_.createSocket());
+ socket = wrapOnDeflate(_socketFactory_.createSocket());
if (receiveDataSocketBufferSize > 0) {
socket.setReceiveBufferSize(receiveDataSocketBufferSize);
@@ -2384,7 +2384,7 @@ public class FTPClient extends FTP implements Configurable {
/**
* Login to the FTP server using the provided user and password.
*
- * @param user The user name to login under.
+ * @param user The user name to login under.
* @param password The password to use.
* @return True if successfully completed, false if not.
* @throws FTPConnectionClosedException If the FTP server prematurely closes the connection as a result of the client being idle or some other reason
@@ -2413,7 +2413,7 @@ public class FTPClient extends FTP implements Configurable {
* Login to the FTP server using the provided username, password, and account. If no account is required by the server, only the username and password, the
* account information is not used.
*
- * @param user The user name to login under.
+ * @param user The user name to login under.
* @param password The password to use.
* @param account The account to use.
* @return True if successfully completed, false if not.
@@ -3419,10 +3419,8 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(smnt(pathname));
}
- private Socket wrapSocketIfModeZisEnabled(final Socket plainSocket) {
- if (fileTransferMode == COMPRESSED_MODE_Z_TRANSFER_MODE) {
- return DeflateSocket.wrap(plainSocket);
- }
- return plainSocket;
+ @SuppressWarnings("resource")
+ private Socket wrapOnDeflate(final Socket plainSocket) {
+ return fileTransferMode == DEFLATE_TRANSFER_MODE ? DeflateSocket.wrap(plainSocket) : plainSocket;
}
}
diff --git a/src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java b/src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java
index 8fca1377..e5b0031a 100644
--- a/src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java
@@ -20,7 +20,7 @@ package org.apache.commons.net.ftp;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.nio.file.Files.readAllBytes;
import static org.apache.commons.io.FileUtils.deleteDirectory;
-import static org.apache.commons.net.ftp.FTP.COMPRESSED_MODE_Z_TRANSFER_MODE;
+import static org.apache.commons.net.ftp.FTP.DEFLATE_TRANSFER_MODE;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -139,7 +139,7 @@ public class FTPClientDeflateTest extends TestCase {
try {
client.connect("localhost", port);
client.login(user, password);
- assertTrue("Mode Z successfully activated", client.setFileTransferMode(COMPRESSED_MODE_Z_TRANSFER_MODE));
+ assertTrue("Mode Z successfully activated", client.setFileTransferMode(DEFLATE_TRANSFER_MODE));
final FTPFile[] files = client.listFiles();
assertEquals("Only single file in home directory", 1, files.length);
@@ -160,7 +160,7 @@ public class FTPClientDeflateTest extends TestCase {
try {
client.connect("localhost", port);
client.login(user, password);
- assertTrue("Mode Z successfully activated", client.setFileTransferMode(COMPRESSED_MODE_Z_TRANSFER_MODE));
+ assertTrue("Mode Z successfully activated", client.setFileTransferMode(DEFLATE_TRANSFER_MODE));
final FTPFile[] filesBeforeUpload = client.listFiles();
assertEquals("No files in home directory before upload", 0, filesBeforeUpload.length);