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 2021/02/08 19:07:25 UTC
[commons-net] 01/02: Normalize to US English spelling. Inline local
variables. Foramtting. Refactor if/else to ternary expression. Remove
whitespace. Use import instead of FQCN.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch release
in repository https://gitbox.apache.org/repos/asf/commons-net.git
commit 8b5201987adab2be28d7cf207ab31aeb8a593821
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Feb 8 14:06:54 2021 -0500
Normalize to US English spelling.
Inline local variables. Foramtting. Refactor if/else to ternary
expression. Remove whitespace. Use import instead of FQCN.
---
.../java/org/apache/commons/net/ftp/FTPClient.java | 182 ++++++---------------
1 file changed, 46 insertions(+), 136 deletions(-)
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 907411d..504c0d9 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -40,6 +40,7 @@ import java.util.Locale;
import java.util.Properties;
import java.util.Random;
import java.util.Set;
+import java.util.regex.Matcher;
import org.apache.commons.net.MalformedServerReplyException;
import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory;
@@ -50,6 +51,7 @@ import org.apache.commons.net.io.CopyStreamAdapter;
import org.apache.commons.net.io.CopyStreamEvent;
import org.apache.commons.net.io.CopyStreamListener;
import org.apache.commons.net.io.FromNetASCIIInputStream;
+import org.apache.commons.net.io.SocketOutputStream;
import org.apache.commons.net.io.ToNetASCIIOutputStream;
import org.apache.commons.net.io.Util;
import org.apache.commons.net.util.NetConstants;
@@ -644,8 +646,7 @@ public class FTPClient extends FTP implements Configurable {
}
@Override
- protected void _connectAction_() throws IOException
- {
+ protected void _connectAction_() throws IOException {
_connectAction_(null);
}
@@ -655,23 +656,19 @@ public class FTPClient extends FTP implements Configurable {
* @since 3.4
*/
@Override
- protected void _connectAction_(final Reader socketIsReader) throws IOException
- {
+ protected void _connectAction_(final Reader socketIsReader) throws IOException {
super._connectAction_(socketIsReader); // sets up _input_ and _output_
initDefaults();
// must be after super._connectAction_(), because otherwise we get an
// Exception claiming we're not connected
- if ( autodetectEncoding )
- {
- final ArrayList<String> oldReplyLines = new ArrayList<> (_replyLines);
+ if (autodetectEncoding) {
+ final ArrayList<String> oldReplyLines = new ArrayList<>(_replyLines);
final int oldReplyCode = _replyCode;
- if ( hasFeature("UTF8") || hasFeature("UTF-8")) // UTF8 appears to be the default
+ if (hasFeature("UTF8") || hasFeature("UTF-8")) // UTF8 appears to be the default
{
- setControlEncoding("UTF-8");
- _controlInput_ =
- new CRLFLineReader(new InputStreamReader(_input_, getControlEncoding()));
- _controlOutput_ =
- new BufferedWriter(new OutputStreamWriter(_output_, getControlEncoding()));
+ setControlEncoding("UTF-8");
+ _controlInput_ = new CRLFLineReader(new InputStreamReader(_input_, getControlEncoding()));
+ _controlOutput_ = new BufferedWriter(new OutputStreamWriter(_output_, getControlEncoding()));
}
// restore the original reply (server greeting)
_replyLines.clear();
@@ -726,13 +723,10 @@ public class FTPClient extends FTP implements Configurable {
* @deprecated (3.3) Use {@link #_openDataConnection_(FTPCmd, String)} instead
*/
@Deprecated
- protected Socket _openDataConnection_(final int command, final String arg)
- throws IOException
- {
+ protected Socket _openDataConnection_(final int command, final String arg) throws IOException {
return _openDataConnection_(FTPCommand.getCommand(command), arg);
}
-
/**
* Establishes a data connection with the FTP server, returning
* a Socket for the connection if successful. If a restart
@@ -890,38 +884,27 @@ public class FTPClient extends FTP implements Configurable {
return socket;
}
- protected void _parseExtendedPassiveModeReply(String reply)
- throws MalformedServerReplyException
- {
- reply = reply.substring(reply.indexOf('(') + 1,
- reply.indexOf(')')).trim();
-
- final char delim1;
- final char delim2;
- final char delim3;
- final char delim4;
- delim1 = reply.charAt(0);
- delim2 = reply.charAt(1);
- delim3 = reply.charAt(2);
- delim4 = reply.charAt(reply.length()-1);
+ protected void _parseExtendedPassiveModeReply(String reply) throws MalformedServerReplyException {
+ reply = reply.substring(reply.indexOf('(') + 1, reply.indexOf(')')).trim();
+
+ final char delim1 = reply.charAt(0);
+ final char delim2 = reply.charAt(1);
+ final char delim3 = reply.charAt(2);
+ final char delim4 = reply.charAt(reply.length() - 1);
if ((delim1 != delim2) || (delim2 != delim3) || (delim3 != delim4)) {
throw new MalformedServerReplyException(
- "Could not parse extended passive host information.\nServer Reply: " + reply);
+ "Could not parse extended passive host information.\nServer Reply: " + reply);
}
final int port;
- try
- {
- port = Integer.parseInt(reply.substring(3, reply.length()-1));
- }
- catch (final NumberFormatException e)
- {
+ try {
+ port = Integer.parseInt(reply.substring(3, reply.length() - 1));
+ } catch (final NumberFormatException e) {
throw new MalformedServerReplyException(
- "Could not parse extended passive host information.\nServer Reply: " + reply);
+ "Could not parse extended passive host information.\nServer Reply: " + reply);
}
-
// in EPSV mode, the passive host address is implicit
this.passiveHost = getRemoteAddress().getHostAddress();
this.passivePort = port;
@@ -932,28 +915,23 @@ public class FTPClient extends FTP implements Configurable {
* @param reply the reply to parse
* @throws MalformedServerReplyException if the server reply does not match (n,n,n,n),(n),(n)
*/
- protected void _parsePassiveModeReply(final String reply)
- throws MalformedServerReplyException
- {
- final java.util.regex.Matcher m = PARMS_PAT.matcher(reply);
+ protected void _parsePassiveModeReply(final String reply) throws MalformedServerReplyException {
+ final Matcher m = PARMS_PAT.matcher(reply);
if (!m.find()) {
throw new MalformedServerReplyException(
- "Could not parse passive host information.\nServer Reply: " + reply);
+ "Could not parse passive host information.\nServer Reply: " + reply);
}
- this.passiveHost = "0,0,0,0".equals(m.group(1)) ? _socket_.getInetAddress().getHostAddress() :
- m.group(1).replace(',', '.'); // Fix up to look like IP address
+ this.passiveHost = "0,0,0,0".equals(m.group(1)) ? _socket_.getInetAddress().getHostAddress()
+ : m.group(1).replace(',', '.'); // Fix up to look like IP address
- try
- {
+ try {
final int oct1 = Integer.parseInt(m.group(2));
final int oct2 = Integer.parseInt(m.group(3));
passivePort = (oct1 << 8) | oct2;
- }
- catch (final NumberFormatException e)
- {
+ } catch (final NumberFormatException e) {
throw new MalformedServerReplyException(
- "Could not parse passive port information.\nServer Reply: " + reply);
+ "Could not parse passive port information.\nServer Reply: " + reply);
}
if (passiveNatWorkaroundStrategy != null) {
@@ -961,17 +939,16 @@ public class FTPClient extends FTP implements Configurable {
final String newPassiveHost = passiveNatWorkaroundStrategy.resolve(this.passiveHost);
if (!this.passiveHost.equals(newPassiveHost)) {
fireReplyReceived(0,
- "[Replacing PASV mode reply address "+this.passiveHost+" with "+newPassiveHost+"]\n");
+ "[Replacing PASV mode reply address " + this.passiveHost + " with " + newPassiveHost + "]\n");
this.passiveHost = newPassiveHost;
}
} catch (final UnknownHostException e) { // Should not happen as we are passing in an IP address
throw new MalformedServerReplyException(
- "Could not parse passive host information.\nServer Reply: " + reply);
+ "Could not parse passive host information.\nServer Reply: " + reply);
}
}
}
-
/**
* @param command the command to get
* @param remote the remote file name
@@ -1137,10 +1114,9 @@ public class FTPClient extends FTP implements Configurable {
} else {
output = socket.getOutputStream();
}
- return new org.apache.commons.net.io.SocketOutputStream(socket, output);
+ return new SocketOutputStream(socket, output);
}
-
/**
* Abort a transfer in progress.
*
@@ -1158,7 +1134,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(abor());
}
-
/**
* Reserve a number of bytes on the server for the next file transfer.
*
@@ -1214,7 +1189,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(allo(bytes));
}
-
/**
* Reserve space on the server for the next file transfer.
*
@@ -1265,7 +1239,6 @@ public class FTPClient extends FTP implements Configurable {
return storeFile(FTPCmd.APPE, remote, local);
}
-
/**
* Returns an OutputStream through which data can be written to append
* to a file on the server with the given name. If the current file type
@@ -1385,7 +1358,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(getReply());
}
-
/**
* Implementation of the {@link Configurable Configurable} interface.
* In the case of this class, configuring merely makes the config object available for the
@@ -1399,7 +1371,6 @@ public class FTPClient extends FTP implements Configurable {
this.configuration = config;
}
-
// package access for test purposes
void createParser(final String parserKey) throws IOException {
// We cache the value to avoid creation of a new object every
@@ -1445,11 +1416,8 @@ public class FTPClient extends FTP implements Configurable {
}
}
}
-
-
}
-
/**
* Deletes a file on the FTP server.
*
@@ -1527,7 +1495,6 @@ public class FTPClient extends FTP implements Configurable {
return null;
}
-
/**
* Set the current data connection mode to
* <code>ACTIVE_LOCAL_DATA_CONNECTION_MODE</code>. No communication
@@ -1737,7 +1704,6 @@ public class FTPClient extends FTP implements Configurable {
return new BufferedInputStream(inputStream);
}
-
private OutputStream getBufferedOutputStream(final OutputStream outputStream) {
if (bufferSize > 0) {
return new BufferedOutputStream(outputStream, bufferSize);
@@ -1745,7 +1711,6 @@ public class FTPClient extends FTP implements Configurable {
return new BufferedOutputStream(outputStream);
}
-
/**
* Retrieve the current internal buffer size for buffered data streams.
* @return The current buffer size.
@@ -1754,7 +1719,6 @@ public class FTPClient extends FTP implements Configurable {
return bufferSize;
}
-
/**
* Gets how long to wait for control keep-alive message replies.
* @return wait time in milliseconds.
@@ -1764,7 +1728,6 @@ public class FTPClient extends FTP implements Configurable {
return controlKeepAliveReplyTimeoutMillis;
}
-
/**
* Gets the time to wait between sending control connection keepalive messages
* when processing file upload or download.
@@ -1778,7 +1741,6 @@ public class FTPClient extends FTP implements Configurable {
return controlKeepAliveTimeoutMillis / 1000;
}
-
/**
* Obtain the currently active listener.
*
@@ -1789,7 +1751,6 @@ public class FTPClient extends FTP implements Configurable {
return copyStreamListener;
}
-
/**
* Get the CSL debug array.
* <p>
@@ -1810,7 +1771,6 @@ public class FTPClient extends FTP implements Configurable {
return cslDebug;
}
-
/**
* Returns the current data connection mode (one of the
* <code> _DATA_CONNECTION_MODE </code> constants.
@@ -1823,7 +1783,6 @@ public class FTPClient extends FTP implements Configurable {
return dataConnectionMode;
}
-
// Method for use by unit test code only
FTPFileEntryParser getEntryParser() {
return entryParser;
@@ -1866,7 +1825,6 @@ public class FTPClient extends FTP implements Configurable {
return pathname;
}
-
/**
* @see #setListHiddenFiles(boolean)
* @return the current state
@@ -1923,7 +1881,6 @@ public class FTPClient extends FTP implements Configurable {
return this.passiveLocalHost;
}
-
/**
* If in passive mode, returns the data port of the passive host.
* This method only returns a valid value AFTER a
@@ -1941,7 +1898,6 @@ public class FTPClient extends FTP implements Configurable {
return passivePort;
}
-
/**
* Retrieve the value to be used for the data socket SO_RCVBUF option.
* @return The current buffer size.
@@ -1986,7 +1942,6 @@ public class FTPClient extends FTP implements Configurable {
return sendDataSocketBufferSize;
}
-
/**
* Issue the FTP SIZE command to the server for a given pathname.
* This should produce the size of the file.
@@ -2427,7 +2382,6 @@ public class FTPClient extends FTP implements Configurable {
return initiateListParsing(entryParser, pathname);
}
-
/**
* Initiate list parsing for MLSD listings in the current working directory.
*
@@ -2685,12 +2639,8 @@ public class FTPClient extends FTP implements Configurable {
* @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
* @see org.apache.commons.net.ftp.FTPFileEntryParser
*/
- public FTPFile[] listFiles(final String pathname)
- throws IOException
- {
- final FTPListParseEngine engine = initiateListParsing((String) null, pathname);
- return engine.getFiles();
-
+ public FTPFile[] listFiles(final String pathname) throws IOException {
+ return initiateListParsing((String) null, pathname).getFiles();
}
/**
@@ -2702,16 +2652,10 @@ public class FTPClient extends FTP implements Configurable {
* @throws IOException on error
* @since 2.2
*/
- public FTPFile[] listFiles(final String pathname, final FTPFileFilter filter)
- throws IOException
- {
- final FTPListParseEngine engine = initiateListParsing((String) null, pathname);
- return engine.getFiles(filter);
-
+ public FTPFile[] listFiles(final String pathname, final FTPFileFilter filter) throws IOException {
+ return initiateListParsing((String) null, pathname).getFiles(filter);
}
-
-
/**
* Fetches the system help information from the server and returns the
* full string.
@@ -2726,15 +2670,10 @@ public class FTPClient extends FTP implements Configurable {
* @throws IOException If an I/O error occurs while either sending a
* command to the server or receiving a reply from the server.
*/
- public String listHelp() throws IOException
- {
- if (FTPReply.isPositiveCompletion(help())) {
- return getReplyString();
- }
- return null;
+ public String listHelp() throws IOException {
+ return FTPReply.isPositiveCompletion(help()) ? getReplyString() : null;
}
-
/**
* Fetches the help information for a given command from the server and
* returns the full string.
@@ -2749,12 +2688,8 @@ public class FTPClient extends FTP implements Configurable {
* @throws IOException If an I/O error occurs while either sending a
* command to the server or receiving a reply from the server.
*/
- public String listHelp(final String command) throws IOException
- {
- if (FTPReply.isPositiveCompletion(help(command))) {
- return getReplyString();
- }
- return null;
+ public String listHelp(final String command) throws IOException {
+ return FTPReply.isPositiveCompletion(help(command)) ? getReplyString() : null;
}
/**
@@ -2783,7 +2718,6 @@ public class FTPClient extends FTP implements Configurable {
return listNames(null);
}
-
/**
* Obtain a list of file names in a directory (or just the name of a given
* file, which is not particularly useful). This information is obtained
@@ -2839,7 +2773,6 @@ public class FTPClient extends FTP implements Configurable {
return null;
}
-
/**
* Login to the FTP server using the provided username and password.
*
@@ -2872,7 +2805,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(pass(password));
}
-
/**
* Login to the FTP server using the provided username, password,
* and account. If no account is required by the server, only
@@ -2918,7 +2850,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(acct(account));
}
-
/**
* Logout of the FTP server by sending the QUIT command.
*
@@ -2936,7 +2867,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(quit());
}
-
/**
* Creates a new subdirectory on the FTP server in the current directory
* (if a relative pathname is given) or where specified (if an absolute
@@ -2957,7 +2887,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(mkd(pathname));
}
-
/**
* Issue the FTP MDTM command (not supported by all servers) to retrieve the last
* modification time of a file. The modification string should be in the
@@ -2982,7 +2911,6 @@ public class FTPClient extends FTP implements Configurable {
return null;
}
-
/**
* Merge two copystream listeners, either or both of which may be null.
*
@@ -3004,7 +2932,6 @@ public class FTPClient extends FTP implements Configurable {
return merged;
}
-
/**
* Generate a directory listing for the current directory using the MLSD command.
*
@@ -3017,7 +2944,6 @@ public class FTPClient extends FTP implements Configurable {
return mlistDir(null);
}
-
/**
* Generate a directory listing using the MLSD command.
*
@@ -3026,13 +2952,10 @@ public class FTPClient extends FTP implements Configurable {
* @throws IOException on error
* @since 3.0
*/
- public FTPFile[] mlistDir(final String pathname) throws IOException
- {
- final FTPListParseEngine engine = initiateMListParsing( pathname);
- return engine.getFiles();
+ public FTPFile[] mlistDir(final String pathname) throws IOException {
+ return initiateMListParsing(pathname).getFiles();
}
-
/**
* Generate a directory listing using the MLSD command.
*
@@ -3042,14 +2965,10 @@ public class FTPClient extends FTP implements Configurable {
* @throws IOException on error
* @since 3.0
*/
- public FTPFile[] mlistDir(final String pathname, final FTPFileFilter filter) throws IOException
- {
- final FTPListParseEngine engine = initiateMListParsing( pathname);
- return engine.getFiles(filter);
+ public FTPFile[] mlistDir(final String pathname, final FTPFileFilter filter) throws IOException {
+ return initiateMListParsing(pathname).getFiles(filter);
}
-
-
/**
* Get file details using the MLST command
*
@@ -3414,7 +3333,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(noop());
}
-
/**
* Send a site specific command.
* @param arguments The site specific command and arguments.
@@ -3432,7 +3350,6 @@ public class FTPClient extends FTP implements Configurable {
return FTPReply.isPositiveCompletion(site(arguments));
}
-
/**
* Set the external IP address in active mode.
* Useful when there are multiple network cards.
@@ -3446,7 +3363,6 @@ public class FTPClient extends FTP implements Configurable {
this.activeExternalHost = InetAddress.getByName(ipAddress);
}
-
/**
* Set the client side port range in active mode.
*
@@ -3460,7 +3376,6 @@ public class FTPClient extends FTP implements Configurable {
this.activeMaxPort = maxPort;
}
-
/**
* Enables or disables automatic server encoding detection (only UTF-8 supported).
* <p>
@@ -3473,7 +3388,6 @@ public class FTPClient extends FTP implements Configurable {
autodetectEncoding = autodetect;
}
-
/**
* Set the internal buffer size for buffered data streams.
*
@@ -3483,7 +3397,6 @@ public class FTPClient extends FTP implements Configurable {
bufferSize = bufSize;
}
-
/**
* Sets how long to wait for control keep-alive message replies.
*
@@ -3706,7 +3619,6 @@ public class FTPClient extends FTP implements Configurable {
return (FTPReply.isPositiveCompletion(mfmt(pathname, timeval)));
}
-
/**
* set the factory used for parser creation to the supplied factory object.
*
@@ -4074,8 +3986,6 @@ public class FTPClient extends FTP implements Configurable {
return storeFileStream(FTPCmd.STOU, remote);
}
- // DEPRECATED METHODS - for API compatibility only - DO NOT USE
-
/**
* Issue the FTP SMNT command.
*