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/05/11 22:03:29 UTC
(commons-net) branch master updated (1ffef378 -> 0a7c49d3)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git
from 1ffef378 [SpotBugs] Make explicit use of the default encoding
new f019baba [SpotBugs] Make explicit use of the default encoding
new 83412391 Use final
new 671c1423 Java convention for variable declarations
new aa88ad7b Whitespace
new ff3437b0 Java convention for variable declarations
new 28707ac3 Java convention for variable declarations
new effe5651 Use an import instead of a FQCN
new 5bd2b5a7 Use an import instead of a FQCN
new 0a7c49d3 Javadoc
The 9 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/commons/net/ProtocolCommandSupport.java | 6 +-
.../commons/net/examples/ftp/TFTPExample.java | 19 ++----
.../commons/net/examples/mail/IMAPExportMbox.java | 32 ++++++----
.../commons/net/examples/mail/IMAPImportMbox.java | 42 ++++++-------
.../apache/commons/net/examples/mail/POP3Mail.java | 4 +-
.../apache/commons/net/examples/mail/SMTPMail.java | 13 ++--
.../apache/commons/net/examples/mail/Utils.java | 3 +-
.../commons/net/examples/nntp/ArticleReader.java | 4 +-
.../commons/net/examples/nntp/ExtendedNNTPOps.java | 4 +-
.../net/examples/nntp/MessageThreading.java | 4 +-
.../commons/net/examples/nntp/PostMessage.java | 14 +++--
.../net/examples/telnet/TelnetClientExample.java | 28 +++++----
.../apache/commons/net/examples/unix/chargen.java | 3 +-
.../java/org/apache/commons/net/ftp/FTPClient.java | 72 ++--------------------
.../org/apache/commons/net/smtp/SMTPClient.java | 45 ++++----------
.../apache/commons/net/tftp/TFTPErrorPacket.java | 5 +-
.../apache/commons/net/tftp/TFTPRequestPacket.java | 5 +-
.../net/ftp/parser/FTPTimestampParserImplTest.java | 2 +-
18 files changed, 114 insertions(+), 191 deletions(-)
(commons-net) 07/09: Use an import instead of a FQCN
Posted by gg...@apache.org.
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 effe5651d57c3d15c7702a0d7c811d3886ab0709
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:56:54 2024 -0400
Use an import instead of a FQCN
---
src/main/java/org/apache/commons/net/ProtocolCommandSupport.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
index 78f888e5..d2aa9ed7 100644
--- a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
+++ b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
@@ -17,6 +17,7 @@
package org.apache.commons.net;
+import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.EventListener;
@@ -100,7 +101,7 @@ public class ProtocolCommandSupport implements Serializable {
return listeners.getListenerCount();
}
- private void readObject(final java.io.ObjectInputStream in) {
+ private void readObject(final ObjectInputStream in) {
throw new UnsupportedOperationException("Serialization is not supported");
}
(commons-net) 09/09: Javadoc
Posted by gg...@apache.org.
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 0a7c49d374ca4fce8cb766d9698580212dd49c51
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 18:03:23 2024 -0400
Javadoc
---
src/main/java/org/apache/commons/net/smtp/SMTPClient.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/smtp/SMTPClient.java b/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
index c585e09c..e9b4ab1f 100644
--- a/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
+++ b/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
@@ -263,8 +263,8 @@ public class SMTPClient extends SMTP {
}
/**
- * Sends the SMTP DATA command in preparation to send an email message. This method returns a DotTerminatedMessageWriter instance to which the message can be
- * written. Null is returned if the DATA command fails.
+ * Sends the SMTP DATA command in preparation to send an email message. This method returns a DotTerminatedMessageWriter instance to which the message can
+ * be written. Null is returned if the DATA command fails.
* <p>
* You must not issue any commands to the SMTP server (i.e., call any (other methods) until you finish writing to the returned Writer instance and close it.
* The SMTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned Writer actually writes directly to
(commons-net) 04/09: Whitespace
Posted by gg...@apache.org.
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 aa88ad7b4e991d9b8ee1f88ded949b5c62d949d5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:48:02 2024 -0400
Whitespace
---
.../java/org/apache/commons/net/ftp/FTPClient.java | 72 ++--------------------
1 file changed, 4 insertions(+), 68 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 f9622281..f5099936 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -634,8 +634,8 @@ public class FTPClient extends FTP implements Configurable {
if (autodetectEncoding) {
final ArrayList<String> oldReplyLines = new ArrayList<>(_replyLines);
final int oldReplyCode = _replyCode;
- if (hasFeature("UTF8") || hasFeature(StandardCharsets.UTF_8.name())) // UTF-8 appears to be the default
- {
+ // UTF-8 appears to be the default
+ if (hasFeature("UTF8") || hasFeature(StandardCharsets.UTF_8.name())) {
setControlEncoding(StandardCharsets.UTF_8.name());
_controlInput_ = new CRLFLineReader(new InputStreamReader(_input_, getControlEncoding()));
_controlOutput_ = new BufferedWriter(new OutputStreamWriter(_output_, getControlEncoding()));
@@ -697,11 +697,8 @@ public class FTPClient extends FTP implements Configurable {
if (dataConnectionMode != ACTIVE_LOCAL_DATA_CONNECTION_MODE && dataConnectionMode != PASSIVE_LOCAL_DATA_CONNECTION_MODE) {
return null;
}
-
final boolean isInet6Address = getRemoteAddress() instanceof Inet6Address;
-
final Socket socket;
-
final int soTimeoutMillis = DurationUtils.toMillisInt(dataTimeout);
if (dataConnectionMode == ACTIVE_LOCAL_DATA_CONNECTION_MODE) {
// if no activePortRange was set (correctly) -> getActivePort() = 0
@@ -721,15 +718,12 @@ public class FTPClient extends FTP implements Configurable {
} else if (!FTPReply.isPositiveCompletion(port(getReportHostAddress(), server.getLocalPort()))) {
return null;
}
-
if (restartOffset > 0 && !restart(restartOffset)) {
return null;
}
-
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
return null;
}
-
// For now, let's just use the data timeout value for waiting for
// the data connection. It may be desirable to let this be a
// separately configurable value. In any case, we really want
@@ -737,9 +731,7 @@ public class FTPClient extends FTP implements Configurable {
if (soTimeoutMillis >= 0) {
server.setSoTimeout(soTimeoutMillis);
}
-
socket = wrapOnDeflate(server.accept());
-
// Ensure the timeout is set before any commands are issued on the new socket
if (soTimeoutMillis >= 0) {
socket.setSoTimeout(soTimeoutMillis);
@@ -751,8 +743,8 @@ public class FTPClient extends FTP implements Configurable {
socket.setSendBufferSize(sendDataSocketBufferSize);
}
}
- } else { // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE
-
+ } else {
+ // We must be in PASSIVE_LOCAL_DATA_CONNECTION_MODE
// Try EPSV command first on IPv6 - and IPv4 if enabled.
// When using IPv4 with NAT it has the advantage
// to work with more rare configurations.
@@ -773,9 +765,7 @@ public class FTPClient extends FTP implements Configurable {
}
_parsePassiveModeReply(_replyLines.get(0));
}
-
socket = wrapOnDeflate(_socketFactory_.createSocket());
-
if (receiveDataSocketBufferSize > 0) {
socket.setReceiveBufferSize(receiveDataSocketBufferSize);
}
@@ -785,7 +775,6 @@ public class FTPClient extends FTP implements Configurable {
if (passiveLocalHost != null) {
socket.bind(new InetSocketAddress(passiveLocalHost, 0));
}
-
// For now, let's just use the data timeout value for waiting for
// the data connection. It may be desirable to let this be a
// separately configurable value. In any case, we really want
@@ -793,51 +782,41 @@ public class FTPClient extends FTP implements Configurable {
if (soTimeoutMillis >= 0) {
socket.setSoTimeout(soTimeoutMillis);
}
-
socket.connect(new InetSocketAddress(passiveHost, passivePort), connectTimeout);
if (restartOffset > 0 && !restart(restartOffset)) {
socket.close();
return null;
}
-
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
socket.close();
return null;
}
}
-
if (remoteVerificationEnabled && !verifyRemote(socket)) {
// Grab the host before we close the socket to avoid NET-663
final InetAddress socketHost = socket.getInetAddress();
-
socket.close();
-
throw new IOException(
"Host attempting data connection " + socketHost.getHostAddress() + " is not same as server " + getRemoteAddress().getHostAddress());
}
-
return socket;
}
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);
}
-
final int port;
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);
}
-
// in EPSV mode, the passive host address is implicit
this.passiveHost = getRemoteAddress().getHostAddress();
this.passivePort = port;
@@ -853,11 +832,9 @@ public class FTPClient extends FTP implements Configurable {
if (!m.find()) {
throw new MalformedServerReplyException("Could not parse passive host information.\nServer Reply: " + reply);
}
-
int pasvPort;
// Fix up to look like IP address
String pasvHost = "0,0,0,0".equals(m.group(1)) ? _socket_.getInetAddress().getHostAddress() : m.group(1).replace(',', '.');
-
try {
final int oct1 = Integer.parseInt(m.group(2));
final int oct2 = Integer.parseInt(m.group(3));
@@ -865,7 +842,6 @@ public class FTPClient extends FTP implements Configurable {
} catch (final NumberFormatException e) {
throw new MalformedServerReplyException("Could not parse passive port information.\nServer Reply: " + reply);
}
-
if (isIpAddressFromPasvResponse()) {
// Pre-3.9.0 behavior
if (passiveNatWorkaroundStrategy != null) {
@@ -898,11 +874,9 @@ public class FTPClient extends FTP implements Configurable {
*/
protected boolean _retrieveFile(final String command, final String remote, final OutputStream local) throws IOException {
final Socket socket = _openDataConnection_(command, remote);
-
if (socket == null) {
return false;
}
-
InputStream input = null;
CSL csl = null;
try {
@@ -941,11 +915,9 @@ public class FTPClient extends FTP implements Configurable {
*/
protected InputStream _retrieveFileStream(final String command, final String remote) throws IOException {
final Socket socket = _openDataConnection_(command, remote);
-
if (socket == null) {
return null;
}
-
final InputStream input;
if (fileType == ASCII_FILE_TYPE) {
// We buffer ascii transfers because the buffering has to
@@ -972,30 +944,24 @@ public class FTPClient extends FTP implements Configurable {
*/
protected boolean _storeFile(final String command, final String remote, final InputStream local) throws IOException {
final Socket socket = _openDataConnection_(command, remote);
-
if (socket == null) {
return false;
}
-
final OutputStream output;
-
if (fileType == ASCII_FILE_TYPE) {
output = new ToNetASCIIOutputStream(getBufferedOutputStream(socket.getOutputStream()));
} else {
output = getBufferedOutputStream(socket.getOutputStream());
}
-
CSL csl = null;
if (DurationUtils.isPositive(controlKeepAliveTimeout)) {
csl = new CSL(this, controlKeepAliveTimeout, controlKeepAliveReplyTimeout);
}
-
// Treat everything else as binary for now
try {
Util.copyStream(local, output, getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, mergeListeners(csl), false);
output.close(); // ensure the file is fully written
socket.close(); // done writing the file
-
// Get the transfer response
return completePendingCommand();
} catch (final IOException e) {
@@ -1018,11 +984,9 @@ public class FTPClient extends FTP implements Configurable {
*/
protected OutputStream _storeFileStream(final String command, final String remote) throws IOException {
final Socket socket = _openDataConnection_(command, remote);
-
if (socket == null) {
return null;
}
-
final OutputStream output;
if (fileType == ASCII_FILE_TYPE) {
// We buffer ascii transfers because the buffering has to
@@ -1409,10 +1373,8 @@ public class FTPClient extends FTP implements Configurable {
if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) {
return false;
}
-
dataConnectionMode = PASSIVE_REMOTE_DATA_CONNECTION_MODE;
_parsePassiveModeReply(_replyLines.get(0));
-
return true;
}
@@ -1667,7 +1629,6 @@ public class FTPClient extends FTP implements Configurable {
}
return "-a";
}
-
return pathname;
}
@@ -2022,18 +1983,15 @@ public class FTPClient extends FTP implements Configurable {
*/
private FTPListParseEngine initiateListParsing(final FTPFileEntryParser parser, final String pathname) throws IOException {
final Socket socket = _openDataConnection_(FTPCmd.LIST, getListArguments(pathname));
-
final FTPListParseEngine engine = new FTPListParseEngine(parser, configuration);
if (socket == null) {
return engine;
}
-
try {
engine.readServerList(socket.getInputStream(), getControlEncoding());
} finally {
Util.closeQuietly(socket);
}
-
completePendingCommand();
return engine;
}
@@ -2147,7 +2105,6 @@ public class FTPClient extends FTP implements Configurable {
if (socket == null) {
return engine;
}
-
try {
engine.readServerList(socket.getInputStream(), getControlEncoding());
} finally {
@@ -2400,24 +2357,19 @@ public class FTPClient extends FTP implements Configurable {
public String[] listNames(final String pathname) throws IOException {
final ArrayList<String> results = new ArrayList<>();
try (final Socket socket = _openDataConnection_(FTPCmd.NLST, getListArguments(pathname))) {
-
if (socket == null) {
return null;
}
-
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()))) {
-
String line;
while ((line = reader.readLine()) != null) {
results.add(line);
}
}
}
-
if (completePendingCommand()) {
return results.toArray(NetConstants.EMPTY_STRING_ARRAY);
}
-
return null;
}
@@ -2433,19 +2385,15 @@ 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 boolean login(final String user, final String password) throws IOException {
-
user(user);
-
if (FTPReply.isPositiveCompletion(_replyCode)) {
return true;
}
-
// If we get here, we either have an error code, or an intermediate
// reply requesting password.
if (!FTPReply.isPositiveIntermediate(_replyCode)) {
return false;
}
-
return FTPReply.isPositiveCompletion(pass(password));
}
@@ -2464,27 +2412,21 @@ public class FTPClient extends FTP implements Configurable {
*/
public boolean login(final String user, final String password, final String account) throws IOException {
user(user);
-
if (FTPReply.isPositiveCompletion(_replyCode)) {
return true;
}
-
// If we get here, we either have an error code, or an intermediate
// reply requesting password.
if (!FTPReply.isPositiveIntermediate(_replyCode)) {
return false;
}
-
pass(password);
-
if (FTPReply.isPositiveCompletion(_replyCode)) {
return true;
}
-
if (!FTPReply.isPositiveIntermediate(_replyCode)) {
return false;
}
-
return FTPReply.isPositiveCompletion(acct(account));
}
@@ -2671,7 +2613,6 @@ public class FTPClient extends FTP implements Configurable {
if (pwd() != FTPReply.PATHNAME_CREATED) {
return null;
}
-
return parsePathname(_replyLines.get(_replyLines.size() - 1));
}
@@ -2687,14 +2628,10 @@ public class FTPClient extends FTP implements Configurable {
*/
public boolean reinitialize() throws IOException {
rein();
-
if (FTPReply.isPositiveCompletion(_replyCode) || FTPReply.isPositivePreliminary(_replyCode) && FTPReply.isPositiveCompletion(getReply())) {
-
initDefaults();
-
return true;
}
-
return false;
}
@@ -2818,7 +2755,6 @@ public class FTPClient extends FTP implements Configurable {
if (!FTPReply.isPositiveIntermediate(rnfr(from))) {
return false;
}
-
return FTPReply.isPositiveCompletion(rnto(to));
}
(commons-net) 03/09: Java convention for variable declarations
Posted by gg...@apache.org.
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 671c1423ec63f186bc90f4eeb81a56c7545f0480
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:41:34 2024 -0400
Java convention for variable declarations
- Normalize Javadoc
- Whitespace
---
.../org/apache/commons/net/smtp/SMTPClient.java | 43 ++++++----------------
1 file changed, 12 insertions(+), 31 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/smtp/SMTPClient.java b/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
index eea66c79..c585e09c 100644
--- a/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
+++ b/src/main/java/org/apache/commons/net/smtp/SMTPClient.java
@@ -111,7 +111,7 @@ public class SMTPClient extends SMTP {
}
/**
- * Add a recipient for a message using the SMTP RCPT command, specifying a forward relay path. The sender must be set first before any recipients may be
+ * Adds a recipient for a message using the SMTP RCPT command, specifying a forward relay path. The sender must be set first before any recipients may be
* specified, otherwise the mail server will reject your commands.
*
* @param path The forward relay path pointing to the recipient.
@@ -126,7 +126,7 @@ public class SMTPClient extends SMTP {
}
/**
- * Add a recipient for a message using the SMTP RCPT command, the recipient's email address. The sender must be set first before any recipients may be
+ * Adds a recipient for a message using the SMTP RCPT command, the recipient's email address. The sender must be set first before any recipients may be
* specified, otherwise the mail server will reject your commands.
*
* @param address The recipient's email address.
@@ -213,16 +213,11 @@ public class SMTPClient extends SMTP {
* @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
*/
public boolean login() throws IOException {
- final String name;
- final InetAddress host;
-
- host = getLocalAddress();
- name = host.getHostName();
-
+ final InetAddress host = getLocalAddress();
+ final String name = host.getHostName();
if (name == null) {
return false;
}
-
return SMTPReply.isPositiveCompletion(helo(name));
}
@@ -268,7 +263,7 @@ public class SMTPClient extends SMTP {
}
/**
- * Send the SMTP DATA command in preparation to send an email message. This method returns a DotTerminatedMessageWriter instance to which the message can be
+ * Sends the SMTP DATA command in preparation to send an email message. This method returns a DotTerminatedMessageWriter instance to which the message can be
* written. Null is returned if the DATA command fails.
* <p>
* You must not issue any commands to the SMTP server (i.e., call any (other methods) until you finish writing to the returned Writer instance and close it.
@@ -298,7 +293,6 @@ public class SMTPClient extends SMTP {
if (!SMTPReply.isPositiveIntermediate(data())) {
return null;
}
-
return new DotTerminatedMessageWriter(writer);
}
@@ -316,7 +310,7 @@ public class SMTPClient extends SMTP {
}
/**
- * A convenience method for sending short messages. This method fetches the Writer returned by {@link #sendMessageData sendMessageData() } and writes the
+ * Sends a short messages. This method fetches the Writer returned by {@link #sendMessageData sendMessageData() } and writes the
* specified String to it. After writing the message, this method calls {@link #completePendingCommand completePendingCommand() } to finalize the
* transaction and returns its success or failure.
*
@@ -329,19 +323,16 @@ public class SMTPClient extends SMTP {
*/
public boolean sendShortMessageData(final String message) throws IOException {
try (final Writer writer = sendMessageData()) {
-
if (writer == null) {
return false;
}
-
writer.write(message);
}
-
return completePendingCommand();
}
/**
- * A convenience method for a sending short email without having to explicitly set the sender and recipient(s). This method sets the sender and recipient
+ * Sends a short email without having to explicitly set the sender and recipient(s). This method sets the sender and recipient
* using {@link #setSender setSender } and {@link #addRecipient addRecipient }, and then sends the message using {@link #sendShortMessageData
* sendShortMessageData }.
*
@@ -358,16 +349,14 @@ public class SMTPClient extends SMTP {
if (!setSender(sender)) {
return false;
}
-
if (!addRecipient(recipient)) {
return false;
}
-
return sendShortMessageData(message);
}
/**
- * A convenience method for a sending short email without having to explicitly set the sender and recipient(s). This method sets the sender and recipients
+ * Sends a short email without having to explicitly set the sender and recipient(s). This method sets the sender and recipients
* using {@link #setSender(String) setSender} and {@link #addRecipient(String) addRecipient}, and then sends the message using
* {@link #sendShortMessageData(String) sendShortMessageData}.
* <p>
@@ -385,23 +374,18 @@ public class SMTPClient extends SMTP {
* @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
*/
public boolean sendSimpleMessage(final String sender, final String[] recipients, final String message) throws IOException {
- boolean oneSuccess = false;
- int count;
-
if (!setSender(sender)) {
return false;
}
-
- for (count = 0; count < recipients.length; count++) {
+ boolean oneSuccess = false;
+ for (int count = 0; count < recipients.length; count++) {
if (addRecipient(recipients[count])) {
oneSuccess = true;
}
}
-
if (!oneSuccess) {
return false;
}
-
return sendShortMessageData(message);
}
@@ -436,7 +420,7 @@ public class SMTPClient extends SMTP {
}
/**
- * Verify that a user or email address is valid, i.e., that mail can be delivered to that mailbox on the server.
+ * Verifies that a user or email address is valid, i.e., that mail can be delivered to that mailbox on the server.
*
* @param user The user name or email address to validate.
* @return True if the user name is valid, false if not.
@@ -446,10 +430,7 @@ public class SMTPClient extends SMTP {
* @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server.
*/
public boolean verify(final String user) throws IOException {
- final int result;
-
- result = vrfy(user);
-
+ final int result = vrfy(user);
return result == SMTPReply.ACTION_OK || result == SMTPReply.USER_NOT_LOCAL_WILL_FORWARD;
}
(commons-net) 06/09: Java convention for variable declarations
Posted by gg...@apache.org.
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 28707ac3563261f2cbf21da03e99d014c02e6776
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:52:46 2024 -0400
Java convention for variable declarations
---
src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
index 29aa780a..302011f0 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
@@ -197,9 +197,7 @@ public final class TFTPExample {
private static boolean send(final int transferMode, final String hostname, final String localFilename, final String remoteFilename, final TFTPClient tftp)
throws IOException {
- final boolean closed;
FileInputStream input;
-
// Try to open local file for reading
try {
input = new FileInputStream(localFilename);
@@ -207,9 +205,8 @@ public final class TFTPExample {
tftp.close();
throw new IOException("Error: could not open local file for reading.", e);
}
-
open(tftp);
-
+ final boolean closed;
// Try to send local file via TFTP
try {
final String[] parts = hostname.split(":");
@@ -230,7 +227,6 @@ public final class TFTPExample {
// Close local socket and input file
closed = close(tftp, input);
}
-
return closed;
}
(commons-net) 02/09: Use final
Posted by gg...@apache.org.
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 834123915c77567c0b40eebb92f1fca5e5c0abae
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:36:09 2024 -0400
Use final
---
.../org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java b/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
index 7930b545..9f2b6c66 100644
--- a/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java
@@ -204,7 +204,7 @@ java.text.ParseException: Timestamp 'Mar 13 02:33' could not be parsed using a s
@Test
@Disabled
public void testNet710() throws ParseException {
- Calendar serverTime = Calendar.getInstance(TimeZone.getTimeZone("EDT"), Locale.US);
+ final Calendar serverTime = Calendar.getInstance(TimeZone.getTimeZone("EDT"), Locale.US);
serverTime.set(2022, 2, 16, 14, 0);
new FTPTimestampParserImpl().parseTimestamp("Mar 13 02:33", serverTime);
}
(commons-net) 01/09: [SpotBugs] Make explicit use of the default encoding
Posted by gg...@apache.org.
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 f019babad7c4d48f96ef9545d15f9211b05b26df
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:36:04 2024 -0400
[SpotBugs] Make explicit use of the default encoding
Remove unused imports
---
.../commons/net/examples/ftp/TFTPExample.java | 6 ----
.../commons/net/examples/mail/IMAPExportMbox.java | 32 ++++++++++-------
.../commons/net/examples/mail/IMAPImportMbox.java | 42 +++++++++++-----------
.../apache/commons/net/examples/mail/POP3Mail.java | 4 +--
.../apache/commons/net/examples/mail/SMTPMail.java | 13 +++----
.../apache/commons/net/examples/mail/Utils.java | 3 +-
.../commons/net/examples/nntp/ArticleReader.java | 4 +--
.../commons/net/examples/nntp/ExtendedNNTPOps.java | 4 +--
.../net/examples/nntp/MessageThreading.java | 4 +--
.../commons/net/examples/nntp/PostMessage.java | 14 ++++----
.../net/examples/telnet/TelnetClientExample.java | 28 ++++++++-------
.../apache/commons/net/examples/unix/chargen.java | 3 +-
.../apache/commons/net/tftp/TFTPErrorPacket.java | 5 +--
.../apache/commons/net/tftp/TFTPRequestPacket.java | 5 +--
14 files changed, 88 insertions(+), 79 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
index a76d0820..121d9ade 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
@@ -159,15 +159,12 @@ public final class TFTPExample {
final boolean closed;
FileOutputStream output;
final File file;
-
file = new File(localFilename);
-
// If file exists, don't overwrite it.
if (file.exists()) {
System.err.println("Error: " + localFilename + " already exists.");
return false;
}
-
// Try to open local file for writing
try {
output = new FileOutputStream(file);
@@ -175,9 +172,7 @@ public final class TFTPExample {
tftp.close();
throw new IOException("Error: could not open local file for writing.", e);
}
-
open(tftp);
-
// Try to receive remote file via TFTP
try {
final String[] parts = hostname.split(":");
@@ -198,7 +193,6 @@ public final class TFTPExample {
// Close local socket and output file
closed = close(tftp, output);
}
-
return closed;
}
diff --git a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
index 18cfa9cc..ac13a96f 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/IMAPExportMbox.java
@@ -18,12 +18,15 @@
package org.apache.commons.net.examples.mail;
import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -318,20 +321,23 @@ public final class IMAPExportMbox {
if (file.equals("-")) {
mboxListener = null;
} else if (file.startsWith("+")) {
- final File mbox = new File(file.substring(1));
- System.out.println("Appending to file " + mbox);
- mboxListener = new MboxListener(new BufferedWriter(new FileWriter(mbox, true)), eol, printHash, printMarker, checkSequence);
+ final Path mboxPath = Paths.get(file.substring(1));
+ System.out.println("Appending to file " + mboxPath);
+ mboxListener = new MboxListener(Files.newBufferedWriter(mboxPath, Charset.defaultCharset(), StandardOpenOption.CREATE, StandardOpenOption.APPEND),
+ eol, printHash, printMarker, checkSequence);
} else if (file.startsWith("-")) {
- final File mbox = new File(file.substring(1));
- System.out.println("Writing to file " + mbox);
- mboxListener = new MboxListener(new BufferedWriter(new FileWriter(mbox, false)), eol, printHash, printMarker, checkSequence);
+ final Path mboxPath = Paths.get(file.substring(1));
+ System.out.println("Writing to file " + mboxPath);
+ mboxListener = new MboxListener(Files.newBufferedWriter(mboxPath, Charset.defaultCharset(), StandardOpenOption.CREATE), eol, printHash, printMarker,
+ checkSequence);
} else {
- final File mboxFile = new File(file);
- if (mboxFile.exists() && mboxFile.length() > 0) {
- throw new IOException("mailbox file: " + mboxFile + " already exists and is non-empty!");
+ final Path mboxPath = Paths.get(file);
+ if (Files.exists(mboxPath) && Files.size(mboxPath) > 0) {
+ throw new IOException("mailbox file: " + mboxPath + " already exists and is non-empty!");
}
- System.out.println("Creating file " + mboxFile);
- mboxListener = new MboxListener(new BufferedWriter(new FileWriter(mboxFile)), eol, printHash, printMarker, checkSequence);
+ System.out.println("Creating file " + mboxPath);
+ mboxListener = new MboxListener(Files.newBufferedWriter(mboxPath, Charset.defaultCharset(), StandardOpenOption.CREATE), eol, printHash, printMarker,
+ checkSequence);
}
final String path = uri.getPath();
diff --git a/src/main/java/org/apache/commons/net/examples/mail/IMAPImportMbox.java b/src/main/java/org/apache/commons/net/examples/mail/IMAPImportMbox.java
index 3c12ee0c..645bce81 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/IMAPImportMbox.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/IMAPImportMbox.java
@@ -19,9 +19,11 @@ package org.apache.commons.net.examples.mail;
import java.io.BufferedReader;
import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
import java.net.URI;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
@@ -133,30 +135,28 @@ public final class IMAPImportMbox {
int loaded = 0;
try {
imap.setSoTimeout(6000);
-
- final BufferedReader br = new BufferedReader(new FileReader(file)); // TODO charset?
-
- String line;
- final StringBuilder sb = new StringBuilder();
boolean wanted = false; // Skip any leading rubbish
- while ((line = br.readLine()) != null) {
- if (line.startsWith("From ")) { // start of message; i.e. end of previous (if any)
- if (process(sb, imap, folder, total)) { // process previous message (if any)
- loaded++;
+ final StringBuilder sb = new StringBuilder();
+ try (BufferedReader br = Files.newBufferedReader(Paths.get(file), Charset.defaultCharset())) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ if (line.startsWith("From ")) { // start of message; i.e. end of previous (if any)
+ if (process(sb, imap, folder, total)) { // process previous message (if any)
+ loaded++;
+ }
+ sb.setLength(0);
+ total++;
+ wanted = wanted(total, line, msgNums, contains);
+ } else if (startsWith(line, PATFROM)) { // Unescape ">+From " in body text
+ line = line.substring(1);
+ }
+ // TODO process first Received: line to determine arrival date?
+ if (wanted) {
+ sb.append(line);
+ sb.append(CRLF);
}
- sb.setLength(0);
- total++;
- wanted = wanted(total, line, msgNums, contains);
- } else if (startsWith(line, PATFROM)) { // Unescape ">+From " in body text
- line = line.substring(1);
- }
- // TODO process first Received: line to determine arrival date?
- if (wanted) {
- sb.append(line);
- sb.append(CRLF);
}
}
- br.close();
if (wanted && process(sb, imap, folder, total)) { // last message (if any)
loaded++;
}
diff --git a/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java b/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java
index 5a60e4e1..25075228 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/POP3Mail.java
@@ -19,10 +19,10 @@ package org.apache.commons.net.examples.mail;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.PrintWriter;
import java.util.Locale;
import org.apache.commons.net.PrintCommandListener;
+import org.apache.commons.net.io.Util;
import org.apache.commons.net.pop3.POP3Client;
import org.apache.commons.net.pop3.POP3MessageInfo;
import org.apache.commons.net.pop3.POP3SClient;
@@ -77,7 +77,7 @@ public final class POP3Mail {
pop3.setDefaultTimeout(60000);
// suppress login details
- pop3.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ pop3.addProtocolCommandListener(new PrintCommandListener(Util.newPrintWriter(System.out), true));
try {
pop3.connect(server);
diff --git a/src/main/java/org/apache/commons/net/examples/mail/SMTPMail.java b/src/main/java/org/apache/commons/net/examples/mail/SMTPMail.java
index 366c7b48..3c699a99 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/SMTPMail.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/SMTPMail.java
@@ -19,11 +19,12 @@ package org.apache.commons.net.examples.mail;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.PrintWriter;
import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@@ -49,7 +50,7 @@ public final class SMTPMail {
String cc;
final List<String> ccList = new ArrayList<>();
final BufferedReader stdin;
- FileReader fileReader = null;
+ BufferedReader fileReader = null;
final Writer writer;
final SimpleSMTPHeader header;
final SMTPClient client;
@@ -61,7 +62,7 @@ public final class SMTPMail {
server = args[0];
- stdin = new BufferedReader(new InputStreamReader(System.in));
+ stdin = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
try {
System.out.print("From: ");
@@ -101,13 +102,13 @@ public final class SMTPMail {
fileName = stdin.readLine();
try {
- fileReader = new FileReader(fileName);
+ fileReader = Files.newBufferedReader(Paths.get(fileName), Charset.defaultCharset());
} catch (final FileNotFoundException e) {
System.err.println("File not found. " + e.getMessage());
}
client = new SMTPClient();
- client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ client.addProtocolCommandListener(new PrintCommandListener(Util.newPrintWriter(System.out), true));
client.connect(server);
diff --git a/src/main/java/org/apache/commons/net/examples/mail/Utils.java b/src/main/java/org/apache/commons/net/examples/mail/Utils.java
index 5a41d4de..55ea94f1 100644
--- a/src/main/java/org/apache/commons/net/examples/mail/Utils.java
+++ b/src/main/java/org/apache/commons/net/examples/mail/Utils.java
@@ -21,6 +21,7 @@ import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.util.Locale;
/**
@@ -40,7 +41,7 @@ final class Utils {
*/
static String getPassword(final String user, String password) throws IOException {
if ("-".equals(password)) { // stdin
- final BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
+ final BufferedReader in = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
password = in.readLine();
} else if ("*".equals(password)) { // console
final Console con = System.console(); // Java 1.6
diff --git a/src/main/java/org/apache/commons/net/examples/nntp/ArticleReader.java b/src/main/java/org/apache/commons/net/examples/nntp/ArticleReader.java
index 7f8a1e55..b7872a0f 100644
--- a/src/main/java/org/apache/commons/net/examples/nntp/ArticleReader.java
+++ b/src/main/java/org/apache/commons/net/examples/nntp/ArticleReader.java
@@ -19,10 +19,10 @@ package org.apache.commons.net.examples.nntp;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.PrintWriter;
import java.net.SocketException;
import org.apache.commons.net.PrintCommandListener;
+import org.apache.commons.net.io.Util;
import org.apache.commons.net.nntp.NNTPClient;
import org.apache.commons.net.nntp.NewsgroupInfo;
@@ -44,7 +44,7 @@ public class ArticleReader {
final String articleSpec = args.length >= 3 ? args[2] : null;
final NNTPClient client = new NNTPClient();
- client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ client.addProtocolCommandListener(new PrintCommandListener(Util.newPrintWriter(System.out), true));
client.connect(hostname);
if (args.length == 5) { // Optional auth
diff --git a/src/main/java/org/apache/commons/net/examples/nntp/ExtendedNNTPOps.java b/src/main/java/org/apache/commons/net/examples/nntp/ExtendedNNTPOps.java
index c36f050f..94523dbd 100644
--- a/src/main/java/org/apache/commons/net/examples/nntp/ExtendedNNTPOps.java
+++ b/src/main/java/org/apache/commons/net/examples/nntp/ExtendedNNTPOps.java
@@ -18,9 +18,9 @@
package org.apache.commons.net.examples.nntp;
import java.io.IOException;
-import java.io.PrintWriter;
import org.apache.commons.net.PrintCommandListener;
+import org.apache.commons.net.io.Util;
import org.apache.commons.net.nntp.Article;
import org.apache.commons.net.nntp.NNTPClient;
import org.apache.commons.net.nntp.NewsgroupInfo;
@@ -47,7 +47,7 @@ public class ExtendedNNTPOps {
public ExtendedNNTPOps() {
client = new NNTPClient();
- client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ client.addProtocolCommandListener(new PrintCommandListener(Util.newPrintWriter(System.out), true));
}
private void demo(final String host, final String user, final String password) {
diff --git a/src/main/java/org/apache/commons/net/examples/nntp/MessageThreading.java b/src/main/java/org/apache/commons/net/examples/nntp/MessageThreading.java
index 54a5653e..7711f69c 100644
--- a/src/main/java/org/apache/commons/net/examples/nntp/MessageThreading.java
+++ b/src/main/java/org/apache/commons/net/examples/nntp/MessageThreading.java
@@ -18,10 +18,10 @@
package org.apache.commons.net.examples.nntp;
import java.io.IOException;
-import java.io.PrintWriter;
import java.net.SocketException;
import org.apache.commons.net.PrintCommandListener;
+import org.apache.commons.net.io.Util;
import org.apache.commons.net.nntp.Article;
import org.apache.commons.net.nntp.NNTPClient;
import org.apache.commons.net.nntp.NewsgroupInfo;
@@ -42,7 +42,7 @@ public class MessageThreading {
final String newsgroup = args[1];
final NNTPClient client = new NNTPClient();
- client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ client.addProtocolCommandListener(new PrintCommandListener(Util.newPrintWriter(System.out), true));
client.connect(hostname);
if (args.length == 4) { // Optional auth
diff --git a/src/main/java/org/apache/commons/net/examples/nntp/PostMessage.java b/src/main/java/org/apache/commons/net/examples/nntp/PostMessage.java
index 9b2f7168..38e3cda1 100644
--- a/src/main/java/org/apache/commons/net/examples/nntp/PostMessage.java
+++ b/src/main/java/org/apache/commons/net/examples/nntp/PostMessage.java
@@ -19,11 +19,13 @@ package org.apache.commons.net.examples.nntp;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
-import java.io.PrintWriter;
+import java.io.Reader;
import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.io.Util;
@@ -47,7 +49,7 @@ public final class PostMessage {
final String organization;
final String references;
final BufferedReader stdin;
- FileReader fileReader = null;
+ Reader fileReader = null;
final SimpleNNTPHeader header;
final NNTPClient client;
@@ -58,7 +60,7 @@ public final class PostMessage {
server = args[0];
- stdin = new BufferedReader(new InputStreamReader(System.in));
+ stdin = new BufferedReader(new InputStreamReader(System.in, Charset.defaultCharset()));
try {
System.out.print("From: ");
@@ -123,14 +125,14 @@ public final class PostMessage {
fileName = stdin.readLine();
try {
- fileReader = new FileReader(fileName);
+ fileReader = Files.newBufferedReader(Paths.get(fileName), Charset.defaultCharset());
} catch (final FileNotFoundException e) {
System.err.println("File not found. " + e.getMessage());
System.exit(1);
}
client = new NNTPClient();
- client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
+ client.addProtocolCommandListener(new PrintCommandListener(Util.newPrintWriter(System.out), true));
client.connect(server);
diff --git a/src/main/java/org/apache/commons/net/examples/telnet/TelnetClientExample.java b/src/main/java/org/apache/commons/net/examples/telnet/TelnetClientExample.java
index 1bfda6ea..1c315a66 100644
--- a/src/main/java/org/apache/commons/net/examples/telnet/TelnetClientExample.java
+++ b/src/main/java/org/apache/commons/net/examples/telnet/TelnetClientExample.java
@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.nio.charset.Charset;
import java.time.Duration;
import java.util.StringTokenizer;
@@ -106,13 +107,14 @@ public class TelnetClientExample implements Runnable, TelnetNotificationHandler
final OutputStream outstr = tc.getOutputStream();
final byte[] buff = new byte[1024];
- int ret_read = 0;
+ int readCount = 0;
do {
try {
- ret_read = System.in.read(buff);
- if (ret_read > 0) {
- final String line = new String(buff, 0, ret_read); // deliberate use of default charset
+ readCount = System.in.read(buff);
+ if (readCount > 0) {
+ final Charset charset = Charset.defaultCharset();
+ final String line = new String(buff, 0, readCount, charset); // deliberate use of default charset
if (line.startsWith("AYT")) {
try {
System.out.println("Sending AYT");
@@ -128,7 +130,7 @@ public class TelnetClientExample implements Runnable, TelnetNotificationHandler
+ tc.getRemoteOptionState(ii));
}
} else if (line.startsWith("REGISTER")) {
- final StringTokenizer st = new StringTokenizer(new String(buff));
+ final StringTokenizer st = new StringTokenizer(new String(buff, charset));
try {
st.nextToken();
final int opcode = Integer.parseInt(st.nextToken());
@@ -149,7 +151,7 @@ public class TelnetClientExample implements Runnable, TelnetNotificationHandler
}
}
} else if (line.startsWith("UNREGISTER")) {
- final StringTokenizer st = new StringTokenizer(new String(buff));
+ final StringTokenizer st = new StringTokenizer(new String(buff, charset));
try {
st.nextToken();
final int opcode = Integer.parseInt(st.nextToken());
@@ -177,7 +179,7 @@ public class TelnetClientExample implements Runnable, TelnetNotificationHandler
outstr.flush();
} else {
try {
- outstr.write(buff, 0, ret_read);
+ outstr.write(buff, 0, readCount);
outstr.flush();
} catch (final IOException e) {
end_loop = true;
@@ -188,7 +190,7 @@ public class TelnetClientExample implements Runnable, TelnetNotificationHandler
System.err.println("Exception while reading keyboard:" + e.getMessage());
end_loop = true;
}
- } while (ret_read > 0 && !end_loop);
+ } while (readCount > 0 && !end_loop);
try {
tc.disconnect();
@@ -243,14 +245,14 @@ public class TelnetClientExample implements Runnable, TelnetNotificationHandler
try {
final byte[] buff = new byte[1024];
- int ret_read = 0;
+ int readCount = 0;
do {
- ret_read = instr.read(buff);
- if (ret_read > 0) {
- System.out.print(new String(buff, 0, ret_read));
+ readCount = instr.read(buff);
+ if (readCount > 0) {
+ System.out.print(new String(buff, 0, readCount, Charset.defaultCharset()));
}
- } while (ret_read >= 0);
+ } while (readCount >= 0);
} catch (final IOException e) {
System.err.println("Exception while reading socket:" + e.getMessage());
}
diff --git a/src/main/java/org/apache/commons/net/examples/unix/chargen.java b/src/main/java/org/apache/commons/net/examples/unix/chargen.java
index cbefbddb..928dfda6 100644
--- a/src/main/java/org/apache/commons/net/examples/unix/chargen.java
+++ b/src/main/java/org/apache/commons/net/examples/unix/chargen.java
@@ -23,6 +23,7 @@ import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import java.net.InetAddress;
import java.net.SocketException;
+import java.nio.charset.Charset;
import java.time.Duration;
import org.apache.commons.net.chargen.CharGenTCPClient;
@@ -45,7 +46,7 @@ public final class chargen {
// We want to timeout if a response takes longer than 60 seconds
client.setDefaultTimeout(60000);
client.connect(host);
- try (final BufferedReader chargenInput = new BufferedReader(new InputStreamReader(client.getInputStream()))) {
+ try (final BufferedReader chargenInput = new BufferedReader(new InputStreamReader(client.getInputStream(), Charset.defaultCharset()))) {
// We assume the chargen service outputs lines, but it really doesn't
// have to, so this code might actually not work if no newlines are
diff --git a/src/main/java/org/apache/commons/net/tftp/TFTPErrorPacket.java b/src/main/java/org/apache/commons/net/tftp/TFTPErrorPacket.java
index 02d420ca..60ca88a4 100644
--- a/src/main/java/org/apache/commons/net/tftp/TFTPErrorPacket.java
+++ b/src/main/java/org/apache/commons/net/tftp/TFTPErrorPacket.java
@@ -19,6 +19,7 @@ package org.apache.commons.net.tftp;
import java.net.DatagramPacket;
import java.net.InetAddress;
+import java.nio.charset.Charset;
/**
* A final class derived from TFTPPacket defining the TFTP Error packet type.
@@ -157,7 +158,7 @@ public final class TFTPErrorPacket extends TFTPPacket {
data[2] = (byte) ((error & 0xffff) >> 8);
data[3] = (byte) (error & 0xff);
- System.arraycopy(message.getBytes(), 0, data, 4, length);
+ System.arraycopy(message.getBytes(Charset.defaultCharset()), 0, data, 4, length);
data[length + 4] = 0;
@@ -183,7 +184,7 @@ public final class TFTPErrorPacket extends TFTPPacket {
data[2] = (byte) ((error & 0xffff) >> 8);
data[3] = (byte) (error & 0xff);
- System.arraycopy(message.getBytes(), 0, data, 4, length);
+ System.arraycopy(message.getBytes(Charset.defaultCharset()), 0, data, 4, length);
data[length + 4] = 0;
diff --git a/src/main/java/org/apache/commons/net/tftp/TFTPRequestPacket.java b/src/main/java/org/apache/commons/net/tftp/TFTPRequestPacket.java
index 1452e3df..64ec423c 100644
--- a/src/main/java/org/apache/commons/net/tftp/TFTPRequestPacket.java
+++ b/src/main/java/org/apache/commons/net/tftp/TFTPRequestPacket.java
@@ -19,6 +19,7 @@ package org.apache.commons.net.tftp;
import java.net.DatagramPacket;
import java.net.InetAddress;
+import java.nio.charset.Charset;
/**
* An abstract class derived from TFTPPacket definiing a TFTP Request packet type. It is subclassed by the
@@ -169,7 +170,7 @@ public abstract class TFTPRequestPacket extends TFTPPacket {
data = new byte[fileLength + modeLength + 4];
data[0] = 0;
data[1] = (byte) type;
- System.arraycopy(fileName.getBytes(), 0, data, 2, fileLength);
+ System.arraycopy(fileName.getBytes(Charset.defaultCharset()), 0, data, 2, fileLength);
data[fileLength + 2] = 0;
System.arraycopy(modeBytes[mode], 0, data, fileLength + 3, modeLength);
@@ -194,7 +195,7 @@ public abstract class TFTPRequestPacket extends TFTPPacket {
data[0] = 0;
data[1] = (byte) type;
- System.arraycopy(fileName.getBytes(), 0, data, 2, fileLength);
+ System.arraycopy(fileName.getBytes(Charset.defaultCharset()), 0, data, 2, fileLength);
data[fileLength + 2] = 0;
System.arraycopy(modeBytes[mode], 0, data, fileLength + 3, modeLength);
(commons-net) 05/09: Java convention for variable declarations
Posted by gg...@apache.org.
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 ff3437b0b3d7495d7e3017b1fa9ef793a8c71fdb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:51:54 2024 -0400
Java convention for variable declarations
---
src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
index 121d9ade..29aa780a 100644
--- a/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
+++ b/src/main/java/org/apache/commons/net/examples/ftp/TFTPExample.java
@@ -156,15 +156,13 @@ public final class TFTPExample {
private static boolean receive(final int transferMode, final String hostname, final String localFilename, final String remoteFilename,
final TFTPClient tftp) throws IOException {
- final boolean closed;
- FileOutputStream output;
- final File file;
- file = new File(localFilename);
+ final File file = new File(localFilename);
// If file exists, don't overwrite it.
if (file.exists()) {
System.err.println("Error: " + localFilename + " already exists.");
return false;
}
+ FileOutputStream output;
// Try to open local file for writing
try {
output = new FileOutputStream(file);
@@ -173,6 +171,7 @@ public final class TFTPExample {
throw new IOException("Error: could not open local file for writing.", e);
}
open(tftp);
+ final boolean closed;
// Try to receive remote file via TFTP
try {
final String[] parts = hostname.split(":");
(commons-net) 08/09: Use an import instead of a FQCN
Posted by gg...@apache.org.
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 5bd2b5a788d0edee50e229e882933d3e6e274e88
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat May 11 17:57:14 2024 -0400
Use an import instead of a FQCN
---
src/main/java/org/apache/commons/net/ProtocolCommandSupport.java | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
index d2aa9ed7..073533de 100644
--- a/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
+++ b/src/main/java/org/apache/commons/net/ProtocolCommandSupport.java
@@ -18,6 +18,7 @@
package org.apache.commons.net;
import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.EventListener;
@@ -118,7 +119,7 @@ public class ProtocolCommandSupport implements Serializable {
listeners.removeListener(listener);
}
- private void writeObject(final java.io.ObjectOutputStream out) {
+ private void writeObject(final ObjectOutputStream out) {
throw new UnsupportedOperationException("Serialization is not supported");
}