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
The following commit(s) were added to refs/heads/master by this push:
new 642d17cd NNTPClient.readNewsgroupListing() can use an ArrayList
instead of a Vector
642d17cd is described below
commit 642d17cdb0731d0537ae0723bfcb26b2283460ca
Author: Gary D. Gregory <[email protected]>
AuthorDate: Thu Mar 20 11:30:16 2025 -0400
NNTPClient.readNewsgroupListing() can use an ArrayList instead of a
Vector
---
src/changes/changes.xml | 1 +
.../java/org/apache/commons/net/nntp/NNTPClient.java | 20 +++++---------------
.../org/apache/commons/net/nntp/NewsgroupInfo.java | 5 +++++
3 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e7e96ef0..7c1232ea 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -89,6 +89,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Base64 does not
call super.finalize().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">TFTPServer does
not call super.finalize().</action>
<action type="fix" dev="ggregory" due-to="Gary
Gregory">KeyManagerUtils.loadStore(String, File, String) shouldn't ignore an
IOException closing a keystore stream; use try-with-resources.</action>
+ <action type="fix" dev="ggregory" due-to="Gary
Gregory">NNTPClient.readNewsgroupListing() can use an ArrayList instead of a
Vector.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
org.apache.commons.net.nntp.Article#getChild().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
org.apache.commons.net.nntp.Article#getNext().</action>
diff --git a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
index 3450b372..a47c2693 100644
--- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
+++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java
@@ -24,7 +24,6 @@ import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
-import java.util.Vector;
import org.apache.commons.io.IOUtils;
import org.apache.commons.net.MalformedServerReplyException;
@@ -64,8 +63,6 @@ import org.apache.commons.net.util.NetConstants;
public class NNTPClient extends NNTP {
- private static final NewsgroupInfo[] EMPTY_NEWSGROUP_INFO_ARRAY = {};
-
/**
* Parse a response line from {@link #retrieveArticleInfo(long, long)}.
*
@@ -589,11 +586,9 @@ public class NNTPClient extends NNTP {
}
private NewsgroupInfo[] readNewsgroupListing() throws IOException {
-
// Start of with a big vector because we may be reading a very large
// amount of groups.
- final Vector<NewsgroupInfo> list = new Vector<>(2048);
-
+ final List<NewsgroupInfo> list = new ArrayList<>(2048);
String line;
try (BufferedReader reader = new DotTerminatedMessageReader(_reader_))
{
while ((line = reader.readLine()) != null) {
@@ -601,18 +596,13 @@ public class NNTPClient extends NNTP {
if (tmp == null) {
throw new MalformedServerReplyException(line);
}
- list.addElement(tmp);
+ list.add(tmp);
}
}
- final int size;
- if ((size = list.size()) < 1) {
- return EMPTY_NEWSGROUP_INFO_ARRAY;
+ if (list.size() < 1) {
+ return NewsgroupInfo.EMPTY_ARRAY;
}
-
- final NewsgroupInfo[] info = new NewsgroupInfo[size];
- list.copyInto(info);
-
- return info;
+ return list.toArray(NewsgroupInfo.EMPTY_ARRAY);
}
private BufferedReader retrieve(final int command, final long
articleNumber, final ArticleInfo pointer) throws IOException {
diff --git a/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java
b/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java
index e68209f3..766e4ce0 100644
--- a/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java
+++ b/src/main/java/org/apache/commons/net/nntp/NewsgroupInfo.java
@@ -43,6 +43,11 @@ public final class NewsgroupInfo {
*/
public static final int PROHIBITED_POSTING_PERMISSION = 3;
+ /**
+ * The empty array of this type.
+ */
+ static final NewsgroupInfo[] EMPTY_ARRAY = new NewsgroupInfo[0];
+
private String newsgroup;
private long estimatedArticleCount;
private long firstArticle;