Skip to content

Commit

Permalink
Better names
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Feb 24, 2024
1 parent 296244a commit 3daaf49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/apache/commons/net/ftp/FTP.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 9 additions & 11 deletions src/main/java/org/apache/commons/net/ftp/FTPClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,8 @@ private static Properties getOverrideProperties() {
* 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.
*
Expand Down Expand Up @@ -713,7 +713,7 @@ protected Socket _openDataConnection_(final String command, final String arg) th
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) {
Expand Down Expand Up @@ -749,7 +749,7 @@ protected Socket _openDataConnection_(final String command, final String arg) th
_parsePassiveModeReply(_replyLines.get(0));
}

socket = wrapSocketIfModeZisEnabled(_socketFactory_.createSocket());
socket = wrapOnDeflate(_socketFactory_.createSocket());

if (receiveDataSocketBufferSize > 0) {
socket.setReceiveBufferSize(receiveDataSocketBufferSize);
Expand Down Expand Up @@ -2384,7 +2384,7 @@ public String[] listNames(final String pathname) throws IOException {
/**
* 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
Expand Down Expand Up @@ -2413,7 +2413,7 @@ public boolean login(final String user, final String password) throws IOExceptio
* 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.
Expand Down Expand Up @@ -3419,10 +3419,8 @@ public boolean structureMount(final String pathname) throws IOException {
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;
Expand Down Expand Up @@ -139,7 +139,7 @@ public void testRetrievingFiles() throws Exception {
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);
Expand All @@ -160,7 +160,7 @@ public void testStoringFiles() throws Exception {
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);
Expand Down

0 comments on commit 3daaf49

Please sign in to comment.