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 2020/12/17 17:37:13 UTC
[commons-net] 01/03: Refactor and avoid extra array creations.
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 dfdb53ac809c9694cfc5364f753f61d1bf75388f
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 17 12:33:51 2020 -0500
Refactor and avoid extra array creations.
---
src/main/java/org/apache/commons/net/ftp/FTP.java | 13 +++++++++++++
.../java/org/apache/commons/net/ftp/FTPClient.java | 18 +++++++++---------
2 files changed, 22 insertions(+), 9 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 871808f..2476563 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -733,6 +733,19 @@ public class FTP extends SocketClient
}
/**
+ * Returns the noth line of text from the last FTP server response as a string. The end of line markers of each are
+ * stripped from the line.
+ *
+ * @param index The index of the line to return, 0-based.
+ *
+ * @return The lines of text from the last FTP response as an array.
+ */
+ String getReplyString(final int index)
+ {
+ return _replyLines.get(index);
+ }
+
+ /**
* Returns the entire text of the last FTP server response exactly
* as it was received, including all end of line markers in NETASCII
* format.
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 f22f6ae..d309e32 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -2414,16 +2414,16 @@ implements Configurable
if (!success) {
return false;
}
- for (final String l : getReplyStrings()) {
- if (l.startsWith(" ")) { // it's a FEAT entry
+ for (final String line : _replyLines) {
+ if (line.startsWith(" ")) { // it's a FEAT entry
String key;
String value="";
- final int varsep = l.indexOf(' ', 1);
+ final int varsep = line.indexOf(' ', 1);
if (varsep > 0) {
- key = l.substring(1, varsep);
- value = l.substring(varsep+1);
+ key = line.substring(1, varsep);
+ value = line.substring(varsep+1);
} else {
- key = l.substring(1);
+ key = line.substring(1);
}
key = key.toUpperCase(Locale.ENGLISH);
Set<String> entries = featuresMap.get(key);
@@ -2535,7 +2535,7 @@ implements Configurable
{
final boolean success = FTPReply.isPositiveCompletion(sendCommand(FTPCmd.MLST, pathname));
if (success){
- String reply = getReplyStrings()[1];
+ String reply = getReplyString(1);
// some FTP server reply not contains space before fact(s)
if(reply.charAt(0) != ' ') { reply = " " + reply; }
/* check the response makes sense.
@@ -3579,7 +3579,7 @@ implements Configurable
public String getSize(final String pathname) throws IOException
{
if (FTPReply.isPositiveCompletion(size(pathname))) {
- return getReplyStrings()[0].substring(4); // skip the return code (e.g. 213) and the space
+ return getReplyString(0).substring(4); // skip the return code (e.g. 213) and the space
}
return null;
}
@@ -3599,7 +3599,7 @@ implements Configurable
public String getModificationTime(final String pathname) throws IOException {
if (FTPReply.isPositiveCompletion(mdtm(pathname))) {
// skip the return code (e.g. 213) and the space
- return getReplyStrings()[0].substring(4);
+ return getReplyString(0).substring(4);
}
return null;
}