diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1b09e247b..142042177 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -45,10 +45,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 with: persist-credentials: false - - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 + - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -57,7 +57,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 + uses: github/codeql-action/init@04daf014b50eaf774287bf3f0f1869d4b4c4b913 # v2.21.7 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -68,7 +68,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 + uses: github/codeql-action/autobuild@04daf014b50eaf774287bf3f0f1869d4b4c4b913 # v2.21.7 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -82,4 +82,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 + uses: github/codeql-action/analyze@04daf014b50eaf774287bf3f0f1869d4b4c4b913 # v2.21.7 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index a55c9beae..a30b3529b 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -29,10 +29,10 @@ jobs: java: [ 8 ] steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 with: persist-credentials: false - - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 + - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index f88d9eab9..a9ace51df 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -43,10 +43,10 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 with: persist-credentials: false - - uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 + - uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3.3.2 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} diff --git a/.github/workflows/maven_adhoc.yml b/.github/workflows/maven_adhoc.yml index 09eaebb75..02071f6d8 100644 --- a/.github/workflows/maven_adhoc.yml +++ b/.github/workflows/maven_adhoc.yml @@ -25,7 +25,7 @@ jobs: timeout-minutes: 7 runs-on: windows-latest steps: - - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/scorecards-analysis.yml b/.github/workflows/scorecards-analysis.yml index 999dfca10..d914a1380 100644 --- a/.github/workflows/scorecards-analysis.yml +++ b/.github/workflows/scorecards-analysis.yml @@ -40,7 +40,7 @@ jobs: steps: - name: "Checkout code" - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 with: persist-credentials: false @@ -57,13 +57,13 @@ jobs: publish_results: true - name: "Upload artifact" - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # 3.1.0 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # 3.1.0 with: name: SARIF file path: results.sarif retention-days: 5 - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # 2.21.3 + uses: github/codeql-action/upload-sarif@04daf014b50eaf774287bf3f0f1869d4b4c4b913 # 2.21.7 with: sarif_file: results.sarif diff --git a/checkstyle.xml b/checkstyle.xml index a34cbfc10..e3c1173bc 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -17,8 +17,8 @@ limitations under the License. --> + "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" + "https://checkstyle.org/dtds/configuration_1_3.dtd"> diff --git a/pom.xml b/pom.xml index 15a29ba70..aa7399465 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ org.apache.commons commons-parent - 59 + 62 commons-net @@ -44,7 +44,7 @@ Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Tel 1.8 1.8 - ${commons.javadoc7.java.link} + ${commons.javadoc8.java.link} net org.apache.commons.net NET diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 6787a61da..af119f7ee 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -145,9 +145,12 @@ The type attribute can be add,update,fix,remove. Javadoc for FtpClient.setControlKeepAliveReplyTimeout(Duration) says timeout is in milliseconds. + + Change class org.apache.commons.net.ftp.parser.MVSFTPEntryParser to support more datasets #182. + - Bump commons-parent from 54 to 59 #132, #137, #153. + Bump commons-parent from 54 to 62 #132, #137, #153. Bump commons-io from 2.11.0 to 2.13.0. diff --git a/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java b/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java index a322941cf..b26f8f1e4 100644 --- a/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java +++ b/src/main/java/org/apache/commons/net/examples/ftp/FTPClientExample.java @@ -182,7 +182,7 @@ public static void main(final String[] args) throws UnknownHostException { displayTimeZoneId = args[++base]; } else if (args[base].equals("-PrH")) { proxyHost = args[++base]; - final String parts[] = proxyHost.split(":"); + final String[] parts = proxyHost.split(":"); if (parts.length == 2) { proxyHost = parts[0]; proxyPort = Integer.parseInt(parts[1]); @@ -213,7 +213,7 @@ public static void main(final String[] args) throws UnknownHostException { String server = args[base++]; int port = 0; - final String parts[] = server.split(":"); + final String[] parts = server.split(":"); if (parts.length == 2) { server = parts[0]; port = Integer.parseInt(parts[1]); @@ -248,7 +248,7 @@ public static void main(final String[] args) throws UnknownHostException { } else if (protocol.equals("false")) { ftps = new FTPSClient(false); } else { - final String prot[] = protocol.split(","); + final String[] prot = protocol.split(","); if (prot.length == 1) { // Just protocol ftps = new FTPSClient(protocol); } else { // protocol,true|false diff --git a/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java b/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java index 86631d3aa..ade654eb7 100644 --- a/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java +++ b/src/main/java/org/apache/commons/net/examples/ftp/ServerToServerFTP.java @@ -165,7 +165,7 @@ public static void main(final String[] args) { System.err.println("Couldn't initiate transfer. Check that file names are valid."); break __main; } - // if(ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) { + // if (ftp1.remoteRetrieve(file1) && ftp2.remoteStore(file2)) { // We have to fetch the positive completion reply. ftp1.completePendingCommand(); ftp2.completePendingCommand(); 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 562baeb45..ae0599e34 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 @@ -377,7 +377,7 @@ public void protocolReplyReceived(final ProtocolCommandEvent event) { while (true) { final boolean ok = imap.fetch(sequenceSet, itemNames); // If the fetch failed, can we retry? - if (ok || (retryWaitSecs <= 0) || (mboxListener == null) || !checkSequence) { + if (ok || retryWaitSecs <= 0 || mboxListener == null || !checkSequence) { break; } final String replyString = imap.getReplyString(); // includes EOL 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 875e483be..3c12ee0cb 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 @@ -201,7 +201,7 @@ private static boolean startsWith(final String input, final Pattern pat) { * @return true if the message is wanted */ private static boolean wanted(final int msgNum, final String line, final BitSet msgNums, final List contains) { - return (msgNums.isEmpty() && contains.isEmpty()) // no selectors + return msgNums.isEmpty() && contains.isEmpty() // no selectors || msgNums.get(msgNum) // matches message number || listContains(contains, line); // contains string } diff --git a/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java b/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java index f9296912a..a47359145 100644 --- a/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java +++ b/src/main/java/org/apache/commons/net/examples/mail/POP3ExportMbox.java @@ -62,7 +62,7 @@ public static void main(final String[] args) { System.exit(1); } - final String arg0[] = args[argIdx++].split(":"); + final String[] arg0 = args[argIdx++].split(":"); final String server = arg0[0]; final String username = args[argIdx++]; String password = args[argIdx++]; 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 e5f59fb60..5a60e4e1e 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 @@ -41,7 +41,7 @@ public static void main(final String[] args) { System.exit(1); } - final String arg0[] = args[0].split(":"); + final String[] arg0 = args[0].split(":"); final String server = arg0[0]; final String username = args[1]; String password = args[2]; 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 5be1bdb3d..54a5653e3 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 @@ -54,7 +54,7 @@ public static void main(final String[] args) throws SocketException, IOException } } - final String fmt[] = client.listOverviewFmt(); + final String[] fmt = client.listOverviewFmt(); if (fmt != null) { System.out.println("LIST OVERVIEW.FMT:"); for (final String s : fmt) { diff --git a/src/main/java/org/apache/commons/net/examples/ntp/SimpleNTPServer.java b/src/main/java/org/apache/commons/net/examples/ntp/SimpleNTPServer.java index cd10bb534..36c2163a6 100644 --- a/src/main/java/org/apache/commons/net/examples/ntp/SimpleNTPServer.java +++ b/src/main/java/org/apache/commons/net/examples/ntp/SimpleNTPServer.java @@ -162,7 +162,7 @@ public boolean isStarted() { @Override public void run() { running = true; - final byte buffer[] = new byte[48]; + final byte[] buffer = new byte[48]; final DatagramPacket request = new DatagramPacket(buffer, buffer.length); do { try { 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 854719531..4a743ddfa 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java @@ -85,7 +85,7 @@ * // success. * reply = ftp.getReplyCode(); * - * if(!FTPReply.isPositiveCompletion(reply)) { + * if (!FTPReply.isPositiveCompletion(reply)) { * ftp.disconnect(); * System.err.println("FTP server refused connection."); * System.exit(1); @@ -96,7 +96,7 @@ * error = true; * e.printStackTrace(); * } finally { - * if(ftp.isConnected()) { + * if (ftp.isConnected()) { * try { * ftp.disconnect(); * } catch (IOException ioe) { @@ -697,7 +697,7 @@ protected Socket _openDataConnection_(final String command, final String arg) th return null; } - if ((restartOffset > 0) && !restart(restartOffset)) { + if (restartOffset > 0 && !restart(restartOffset)) { return null; } @@ -768,7 +768,7 @@ protected Socket _openDataConnection_(final String command, final String arg) th } socket.connect(new InetSocketAddress(passiveHost, passivePort), connectTimeout); - if ((restartOffset > 0) && !restart(restartOffset)) { + if (restartOffset > 0 && !restart(restartOffset)) { socket.close(); return null; } @@ -800,7 +800,7 @@ protected void _parseExtendedPassiveModeReply(String reply) throws MalformedServ final char delim3 = reply.charAt(2); final char delim4 = reply.charAt(reply.length() - 1); - if ((delim1 != delim2) || (delim2 != delim3) || (delim3 != delim4)) { + if (delim1 != delim2 || delim2 != delim3 || delim3 != delim4) { throw new MalformedServerReplyException("Could not parse extended passive host information.\nServer Reply: " + reply); } @@ -834,7 +834,7 @@ protected void _parsePassiveModeReply(final String reply) throws MalformedServer try { final int oct1 = Integer.parseInt(m.group(2)); final int oct2 = Integer.parseInt(m.group(3)); - pasvPort = (oct1 << 8) | oct2; + pasvPort = oct1 << 8 | oct2; } catch (final NumberFormatException e) { throw new MalformedServerReplyException("Could not parse passive port information.\nServer Reply: " + reply); } @@ -1164,7 +1164,7 @@ public boolean changeWorkingDirectory(final String pathname) throws IOException * OutputStream output; * input = new FileInputStream("foobaz.txt"); * output = ftp.storeFileStream("foobar.txt") - * if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) { + * if (!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) { * input.close(); * output.close(); * ftp.logout(); @@ -1176,7 +1176,7 @@ public boolean changeWorkingDirectory(final String pathname) throws IOException * input.close(); * output.close(); * // Must call completePendingCommand() to finish command. - * if(!ftp.completePendingCommand()) { + * if (!ftp.completePendingCommand()) { * ftp.logout(); * ftp.disconnect(); * System.err.println("File transfer failed."); @@ -1211,7 +1211,7 @@ void createParser(final String parserKey) throws IOException { // We cache the value to avoid creation of a new object every // time a file listing is generated. // Note: we don't check against a null parserKey (NET-544) - if (entryParser == null || (parserKey != null && !entryParserKey.equals(parserKey))) { + if (entryParser == null || parserKey != null && !entryParserKey.equals(parserKey)) { if (null != parserKey) { // if a parser key was supplied in the parameters, // use that to create the parser @@ -2646,7 +2646,7 @@ public String printWorkingDirectory() throws IOException { public boolean reinitialize() throws IOException { rein(); - if (FTPReply.isPositiveCompletion(_replyCode) || (FTPReply.isPositivePreliminary(_replyCode) && FTPReply.isPositiveCompletion(getReply()))) { + if (FTPReply.isPositiveCompletion(_replyCode) || FTPReply.isPositivePreliminary(_replyCode) && FTPReply.isPositiveCompletion(getReply())) { initDefaults(); @@ -3137,7 +3137,7 @@ public void setListHiddenFiles(final boolean listHiddenFiles) { * @see http://tools.ietf.org/html/draft-somers-ftp-mfxx-04 */ public boolean setModificationTime(final String pathname, final String timeval) throws IOException { - return (FTPReply.isPositiveCompletion(mfmt(pathname, timeval))); + return FTPReply.isPositiveCompletion(mfmt(pathname, timeval)); } /** diff --git a/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java b/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java index f9703fdd9..c1da541c4 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPHTTPClient.java @@ -214,7 +214,7 @@ private BufferedReader tunnelHandshake(final String host, final int port, final String code; final String resp = response.get(0); - if (!resp.startsWith("HTTP/") || (resp.length() < 12)) { + if (!resp.startsWith("HTTP/") || resp.length() < 12) { throw new IOException("Invalid response from proxy: " + resp); } code = resp.substring(9, 12); diff --git a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java index b2fc0ab43..a0c92ba3b 100644 --- a/src/main/java/org/apache/commons/net/ftp/FTPSClient.java +++ b/src/main/java/org/apache/commons/net/ftp/FTPSClient.java @@ -714,7 +714,7 @@ private Socket openDataSecureConnection(final String command, final String arg) return null; } - if ((getRestartOffset() > 0) && !restart(getRestartOffset())) { + if (getRestartOffset() > 0 && !restart(getRestartOffset())) { return null; } @@ -795,7 +795,7 @@ private Socket openDataSecureConnection(final String command, final String arg) sslSocket = context.getSocketFactory().createSocket(socket, getPassiveHost(), getPassivePort(), true); } - if ((getRestartOffset() > 0) && !restart(getRestartOffset())) { + if (getRestartOffset() > 0 && !restart(getRestartOffset())) { closeSockets(socket, sslSocket); return null; } @@ -1025,7 +1025,7 @@ protected void sslNegotiation() throws IOException { _controlInput_ = new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding())); _controlOutput_ = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), getControlEncoding())); - if (isClientMode && (hostnameVerifier != null && !hostnameVerifier.verify(_hostname_, socket.getSession()))) { + if (isClientMode && hostnameVerifier != null && !hostnameVerifier.verify(_hostname_, socket.getSession())) { throw new SSLHandshakeException("Hostname doesn't match certificate"); } } diff --git a/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java b/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java index 496ae981c..516be6fb2 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImpl.java @@ -308,7 +308,7 @@ public Calendar parseTimestamp(final String timestampStr, final Calendar serverT // a valid year (e.g. 22:04 will parse as 22 A.D.) // so could mistakenly confuse an hour with a year, // if we don't insist on full length parsing. - if ((parsed == null) || (pp.getIndex() != timestampStr.length())) { + if (parsed == null || pp.getIndex() != timestampStr.length()) { throw new ParseException("Timestamp '" + timestampStr + "' could not be parsed using a server time of " + serverTime.getTime().toString(), pp.getErrorIndex()); } diff --git a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java index 6364780d5..0687b5ff9 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/MLSxEntryParser.java @@ -194,7 +194,7 @@ public FTPFile parseFTPEntry(final String entry) { return null; // Invalid - no pathname } - final String parts[] = entry.split(" ", 2); // Path may contain space + final String[] parts = entry.split(" ", 2); // Path may contain space if (parts.length != 2 || parts[1].isEmpty()) { return null; // no space found or no file name } diff --git a/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java index 6bfbc5d82..13601e595 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParser.java @@ -60,7 +60,7 @@ public class MVSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl { "\\S+\\s+" + // extents -ignored // If the values are too large, the fields may be merged (NET-639) "(?:\\S+\\s+)?" + // used - ignored - "(?:F|FB|V|VB|U)\\s+" + // recfm - F[B], V[B], U + "\\S+\\s+" + // recfm - ignored "\\S+\\s+" + // logical record length -ignored "\\S+\\s+" + // block size - ignored "(PS|PO|PO-E)\\s+" + // Dataset organisation. Many exist @@ -193,7 +193,7 @@ public class MVSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl { * * Other notes =========== * - * The file system supports automatically backup and retrieval of datasets. If a file is backed up, the ftp LIST command will return: ARCHIVE Not Direct + * The file system supports automatically backup and retrieval of datasets. If a file is backed up, the ftp LIST command will return: ARCIVE Not Direct * Access Device KJ.IOP998.ERROR.PL.UNITTEST * * @@ -213,17 +213,10 @@ public class MVSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl { * scheduler DB2 is used to interact with a DB2 subsystem * * This parser supports SEQ and JES. - * - * - * - * - * - * */ /** * The sole constructor for a MVSFTPEntryParser object. - * */ public MVSFTPEntryParser() { super(""); // note the regex is set in preParse. @@ -239,17 +232,20 @@ protected FTPClientConfig getDefaultConfiguration() { } /** - * Parse entries representing a dataset list. Only datasets with DSORG PS or PO or PO-E and with RECFM F[B], V[B], U will be parsed. - *

- * Format of ZOS/MVS file list: 1 2 3 4 5 6 7 8 9 10 Volume Unit Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname B10142 3390 2006/03/20 2 31 F 80 80 PS - * MDI.OKL.WORK ARCHIVE Not Direct Access Device KJ.IOP998.ERROR.PL.UNITTEST B1N231 3390 2006/03/20 1 15 VB 256 27998 PO PLU B1N231 3390 2006/03/20 1 15 VB - * 256 27998 PO-E PLB - *

+ * Parses entries representing a dataset list. + *

+     * Format of ZOS/MVS file list: 1 2 3 4 5 6 7 8 9 10
+     * Volume Unit Referred Ext Used Recfm Lrecl BlkSz Dsorg Dsname
+     * B10142 3390 2006/03/20 2 31 F 80 80 PS MDI.OKL.WORK
+     * ARCIVE Not Direct Access Device KJ.IOP998.ERROR.PL.UNITTEST
+     * B1N231 3390 2006/03/20 1 15 VB 256 27998 PO PLU
+     * B1N231 3390 2006/03/20 1 15 VB 256 27998 PO-E PLB
+     * Migrated                                                HLQ.DATASET.NAME
+     * 
+ *
      * ----------------------------------- Group within Regex [1] Volume [2] Unit [3] Referred [4] Ext: number of extents [5] Used [6] Recfm: Record format [7]
      * Lrecl: Logical record length [8] BlkSz: Block size [9] Dsorg: Dataset organisation. Many exists but only support: PS, PO, PO-E [10] Dsname: Dataset name
-     * 

- * Note: When volume is ARCHIVE, it means the dataset is stored somewhere in a tape archive. These entries are currently not supported by this parser. - * A null value is returned. + *

* * @param entry zosDirectoryEntry * @return null: entry was not parsed. @@ -275,6 +271,16 @@ private FTPFile parseFileList(final String entry) { return file; } + final boolean migrated = entry.startsWith("Migrated"); + if (migrated || entry.startsWith("ARCIVE")) { + // Type of file is unknown for migrated datasets + final FTPFile file = new FTPFile(); + file.setRawListing(entry); + file.setType(FTPFile.UNKNOWN_TYPE); + file.setName(entry.split("\\s+")[migrated ? 1 : 5]); + return file; + } + return null; } @@ -327,18 +333,7 @@ public FTPFile parseFTPEntry(final String entry) { * @return null: entry was not parsed. */ private FTPFile parseJeslevel1List(final String entry) { - if (matches(entry)) { - final FTPFile file = new FTPFile(); - if (group(3).equalsIgnoreCase("OUTPUT")) { - file.setRawListing(entry); - final String name = group(2); /* Job Number, used by GET */ - file.setName(name); - file.setType(FTPFile.FILE_TYPE); - return file; - } - } - - return null; + return parseJeslevelList(entry, 3); } /** @@ -365,9 +360,13 @@ private FTPFile parseJeslevel1List(final String entry) { * @return null: entry was not parsed. */ private FTPFile parseJeslevel2List(final String entry) { + return parseJeslevelList(entry, 4); + } + + private FTPFile parseJeslevelList(final String entry, final int matchNum) { if (matches(entry)) { final FTPFile file = new FTPFile(); - if (group(4).equalsIgnoreCase("OUTPUT")) { + if (group(matchNum).equalsIgnoreCase("OUTPUT")) { file.setRawListing(entry); final String name = group(2); /* Job Number, used by GET */ file.setName(name); @@ -375,12 +374,11 @@ private FTPFile parseJeslevel2List(final String entry) { return file; } } - return null; } /** - * Parse entries within a partitioned dataset. + * Parses entries within a partitioned dataset. * * Format of a memberlist within a PDS: * @@ -437,7 +435,7 @@ private FTPFile parseMemberList(final String entry) { } /** - * preParse is called as part of the interface. Per definition, it is called before the parsing takes place. Three kinds of lists are recognized: + * Pre-parses is called as part of the interface. Per definition, it is called before the parsing takes place. Three kinds of lists are recognized: *
    *
  • z/OS-MVS File lists,
  • *
  • z/OS-MVS Member lists,
  • @@ -480,7 +478,7 @@ public List preParse(final List orig) { } /** - * Explicitly set the type of listing being processed. + * Sets the type of listing being processed. * * @param type The listing type. */ diff --git a/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java index 89e99f992..7b72a4aa4 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParser.java @@ -152,8 +152,8 @@ public FTPFile parseFTPEntry(final String entry) { int g = 4; for (int access = 0; access < 3; access++, g += 4) { // Use != '-' to avoid having to check for suid and sticky bits - file.setPermission(access, FTPFile.READ_PERMISSION, (!group(g).equals("-"))); - file.setPermission(access, FTPFile.WRITE_PERMISSION, (!group(g + 1).equals("-"))); + file.setPermission(access, FTPFile.READ_PERMISSION, !group(g).equals("-")); + file.setPermission(access, FTPFile.WRITE_PERMISSION, !group(g + 1).equals("-")); final String execPerm = group(g + 2); file.setPermission(access, FTPFile.EXECUTE_PERMISSION, !execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0))); diff --git a/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java index 7320886ea..e5e9e3747 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParser.java @@ -325,7 +325,7 @@ public FTPFile parseFTPEntry(final String entry) { // file. // Save files are a special type of files which are used // to save objects, e.g. for backups. - if ((name == null) || !name.toUpperCase(Locale.ROOT).endsWith(".SAVF")) { + if (name == null || !name.toUpperCase(Locale.ROOT).endsWith(".SAVF")) { return null; } mustScanForPathSeparator = false; diff --git a/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java b/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java index b39b12d31..93b6803a7 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/RegexFTPFileEntryParserImpl.java @@ -122,15 +122,15 @@ public String getGroupsAsString() { /** * Convenience method delegates to the internal MatchResult's group() method. * - * @param matchnum match group number to be retrieved + * @param matchNum match group number to be retrieved * * @return the content of the matchnum'th group of the internal match or null if this method is called without a match having been made. */ - public String group(final int matchnum) { + public String group(final int matchNum) { if (this.result == null) { return null; } - return this.result.group(matchnum); + return this.result.group(matchNum); } /** diff --git a/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java index a6ea27d3b..8aa75779b 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParser.java @@ -126,7 +126,7 @@ public FTPFile parseFTPEntry(final String entry) { final String size = group(2); final String datestr = group(3) + " " + group(4); final String owner = group(5); - final String permissions[] = new String[3]; + final String[] permissions = new String[3]; permissions[0] = group(9); permissions[1] = group(10); permissions[2] = group(11); diff --git a/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java b/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java index 3dd78e9a1..71a2af140 100644 --- a/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java +++ b/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java @@ -103,7 +103,7 @@ public List preParse(final List original) { final String version = result.group(2); final Integer nv = Integer.valueOf(version); final Integer existing = existingEntries.get(name); - if ((null != existing) && (nv.intValue() < existing.intValue())) { + if (null != existing && nv.intValue() < existing.intValue()) { iter.remove(); // removes older version from original list. continue; } @@ -125,7 +125,7 @@ public List preParse(final List original) { final String version = result.group(2); final int nv = Integer.parseInt(version); final Integer existing = existingEntries.get(name); - if ((null != existing) && (nv < existing.intValue())) { + if (null != existing && nv < existing.intValue()) { iter.remove(); // removes older version from original list. } } diff --git a/src/main/java/org/apache/commons/net/nntp/Article.java b/src/main/java/org/apache/commons/net/nntp/Article.java index 8418af76b..1c274dc63 100644 --- a/src/main/java/org/apache/commons/net/nntp/Article.java +++ b/src/main/java/org/apache/commons/net/nntp/Article.java @@ -161,7 +161,7 @@ public String getSubject() { @Override public boolean isDummy() { - return (articleNumber == -1); + return articleNumber == -1; } @Override @@ -246,13 +246,13 @@ private void simplifySubject() { start++; } - if (start < (len - 2) && (subject.charAt(start) == 'r' || subject.charAt(start) == 'R') + if (start < len - 2 && (subject.charAt(start) == 'r' || subject.charAt(start) == 'R') && (subject.charAt(start + 1) == 'e' || subject.charAt(start + 1) == 'E')) { if (subject.charAt(start + 2) == ':') { start += 3; // Skip "Re:" done = false; - } else if (start < (len - 2) && (subject.charAt(start + 2) == '[' || subject.charAt(start + 2) == '(')) { + } else if (start < len - 2 && (subject.charAt(start + 2) == '[' || subject.charAt(start + 2) == '(')) { int i = start + 3; @@ -260,7 +260,7 @@ private void simplifySubject() { i++; } - if (i < (len - 1) && (subject.charAt(i) == ']' || subject.charAt(i) == ')') && subject.charAt(i + 1) == ':') { + if (i < len - 1 && (subject.charAt(i) == ']' || subject.charAt(i) == ')') && subject.charAt(i + 1) == ':') { start = i + 2; done = false; } diff --git a/src/main/java/org/apache/commons/net/nntp/NNTP.java b/src/main/java/org/apache/commons/net/nntp/NNTP.java index 24a27df77..6e6402b4f 100644 --- a/src/main/java/org/apache/commons/net/nntp/NNTP.java +++ b/src/main/java/org/apache/commons/net/nntp/NNTP.java @@ -45,11 +45,13 @@ * {@link org.apache.commons.net.nntp.NNTPConnectionClosedException} , you must disconnect the connection with {@link #disconnect disconnect() } to properly * clean up the system resources used by NNTP. Before disconnecting, you may check the last reply code and text with {@link #getReplyCode getReplyCode } and * {@link #getReplyString getReplyString }. + *

    *

    * Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can also throw a * {@link org.apache.commons.net.MalformedServerReplyException} , which is a subclass of IOException. A MalformedServerReplyException will be thrown when the * reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful manner despite attempts to be as * lenient as possible. + *

    * * @see NNTPClient * @see NNTPConnectionClosedException @@ -115,7 +117,6 @@ protected void _connectAction_() throws IOException { /** * A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -140,7 +141,6 @@ public int article(final int a) throws IOException { /** * A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code. - *

    * * @param articleNumber The number of the article to request from the currently selected newsgroup. * @return The reply code received from the server. @@ -155,7 +155,6 @@ public int article(final long articleNumber) throws IOException { /** * A convenience method to send the NNTP ARTICLE command to the server, receive the initial reply, and return the reply code. - *

    * * @param messageId The message identifier of the requested article, including the encapsulating < and > characters. * @return The reply code received from the server. @@ -171,7 +170,6 @@ public int article(final String messageId) throws IOException { /** * A convenience method to send the AUTHINFO PASS command to the server, receive the reply, and return the reply code. If this step is required, it should * immediately follow the AUTHINFO USER command (See RFC 2980) - *

    * * @param password a valid password. * @return The reply code received from the server. The server should return a 281 or 502 for this command. @@ -187,7 +185,6 @@ public int authinfoPass(final String password) throws IOException { /** * A convenience method to send the AUTHINFO USER command to the server, receive the reply, and return the reply code. (See RFC 2980) - *

    * * @param username A valid username. * @return The reply code received from the server. The server should return a 381 or 281 for this command. @@ -203,7 +200,6 @@ public int authinfoUser(final String username) throws IOException { /** * A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -228,7 +224,6 @@ public int body(final int a) throws IOException { /** * A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code. - *

    * * @param articleNumber The number of the article to request from the currently selected newsgroup. * @return The reply code received from the server. @@ -243,7 +238,6 @@ public int body(final long articleNumber) throws IOException { /** * A convenience method to send the NNTP BODY command to the server, receive the initial reply, and return the reply code. - *

    * * @param messageId The message identifier of the requested article, including the encapsulating < and > characters. * @return The reply code received from the server. @@ -259,7 +253,6 @@ public int body(final String messageId) throws IOException { /** * Closes the connection to the NNTP server and sets to null some internal data so that the memory may be reclaimed by the garbage collector. The reply text * and code information from the last command is voided so that the memory it used may be reclaimed. - *

    * * @throws IOException If an error occurs while disconnecting. */ @@ -284,7 +277,6 @@ protected ProtocolCommandSupport getCommandSupport() { * Fetches a reply from the NNTP server and returns the integer reply code. After calling this method, the actual reply text can be accessed from * {@link #getReplyString getReplyString }. Only use this method if you are implementing your own NNTP client or if you need to fetch a secondary response * from the NNTP server. - *

    * * @return The integer value of the reply code of the fetched NNTP reply. in response to the command. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -322,7 +314,6 @@ public int getReply() throws IOException { /** * Returns the integer value of the reply code of the last NNTP reply. You will usually only use this method after you connect to the NNTP server to check * that the connection was successful since connect is of type void. - *

    * * @return The integer value of the reply code of the last NNTP reply. */ @@ -332,7 +323,6 @@ public int getReplyCode() { /** * Returns the entire text of the last NNTP server response exactly as it was received, not including the end of line marker. - *

    * * @return The entire text from the last NNTP response as a String. */ @@ -342,7 +332,6 @@ public String getReplyString() { /** * A convenience method to send the NNTP GROUP command to the server, receive the reply, and return the reply code. - *

    * * @param newsgroup The name of the newsgroup to select. * @return The reply code received from the server. @@ -357,7 +346,6 @@ public int group(final String newsgroup) throws IOException { /** * A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -382,7 +370,6 @@ public int head(final int a) throws IOException { /** * A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code. - *

    * * @param articleNumber The number of the article to request from the currently selected newsgroup. * @return The reply code received from the server. @@ -397,7 +384,6 @@ public int head(final long articleNumber) throws IOException { /** * A convenience method to send the NNTP HEAD command to the server, receive the initial reply, and return the reply code. - *

    * * @param messageId The message identifier of the requested article, including the encapsulating < and > characters. * @return The reply code received from the server. @@ -412,7 +398,6 @@ public int head(final String messageId) throws IOException { /** * A convenience method to send the NNTP HELP command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -426,7 +411,6 @@ public int help() throws IOException { /** * A convenience method to send the NNTP IHAVE command to the server, receive the reply, and return the reply code. - *

    * * @param messageId The article identifier, including the encapsulating < and > characters. * @return The reply code received from the server. @@ -441,7 +425,6 @@ public int ihave(final String messageId) throws IOException { /** * Indicates whether or not the client is allowed to post articles to the server it is currently connected to. - *

    * * @return True if the client can post articles to the server, false otherwise. */ @@ -451,7 +434,6 @@ public boolean isAllowedToPost() { /** * A convenience method to send the NNTP LAST command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -465,7 +447,6 @@ public int last() throws IOException { /** * A convenience method to send the NNTP LIST command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -479,7 +460,6 @@ public int list() throws IOException { /** * A convenience wrapper for the extended LIST command that takes an argument, allowing us to selectively list multiple groups. - *

    * * @param wildmat A wildmat (pseudo-regex) pattern. See RFC 2980 for details. * @return the reply code received from the server. @@ -493,7 +473,6 @@ public int listActive(final String wildmat) throws IOException { /** * A convenience method to send the "NEWGROUPS" command to the server, receive the reply, and return the reply code. - *

    * * @param date The date after which to check for new groups. Date format is YYMMDD * @param time The time after which to check for new groups. Time format is HHMMSS using a 24-hour clock. @@ -528,7 +507,6 @@ public int newgroups(final String date, final String time, final boolean GMT, fi /** * A convenience method to send the "NEWNEWS" command to the server, receive the reply, and return the reply code. - *

    * * @param newsgroups A comma-separated list of newsgroups to check for new news. * @param date The date after which to check for new news. Date format is YYMMDD @@ -566,7 +544,6 @@ public int newnews(final String newsgroups, final String date, final String time /** * A convenience method to send the NNTP NEXT command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -580,7 +557,6 @@ public int next() throws IOException { /** * A convenience method to send the NNTP POST command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -594,7 +570,6 @@ public int post() throws IOException { /** * A convenience method to send the NNTP QUIT command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -609,7 +584,6 @@ public int quit() throws IOException { /** * Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed * information, the actual reply text can be accessed by calling {@link #getReplyString getReplyString }. - *

    * * @param command The NNTPCommand constant corresponding to the NNTP command to send. * @return The integer value of the NNTP reply code returned by the server in response to the command. in response to the command. @@ -625,7 +599,6 @@ public int sendCommand(final int command) throws IOException { /** * Sends an NNTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the * actual reply text can be accessed by calling {@link #getReplyString getReplyString }. - *

    * * @param command The NNTPCommand constant corresponding to the NNTP command to send. * @param args The arguments to the NNTP command. If this parameter is set to null, then the command is sent with no argument. @@ -642,7 +615,6 @@ public int sendCommand(final int command, final String args) throws IOException /** * Sends an NNTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed * information, the actual reply text can be accessed by calling {@link #getReplyString getReplyString }. - *

    * * @param command The text representation of the NNTP command to send. * @return The integer value of the NNTP reply code returned by the server in response to the command. in response to the command. @@ -658,7 +630,6 @@ public int sendCommand(final String command) throws IOException { /** * Sends an NNTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the * actual reply text can be accessed by calling {@link #getReplyString getReplyString }. - *

    * * @param command The text representation of the NNTP command to send. * @param args The arguments to the NNTP command. If this parameter is set to null, then the command is sent with no argument. @@ -689,7 +660,6 @@ public int sendCommand(final String command, final String args) throws IOExcepti /** * A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -701,8 +671,6 @@ public int stat() throws IOException { return sendCommand(NNTPCommand.STAT); } - // DEPRECATED METHODS - for API compatibility only - DO NOT USE - /** * @param a article number * @return number @@ -716,7 +684,6 @@ public int stat(final int a) throws IOException { /** * A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code. - *

    * * @param articleNumber The number of the article to request from the currently selected newsgroup. * @return The reply code received from the server. @@ -731,7 +698,6 @@ public int stat(final long articleNumber) throws IOException { /** * A convenience method to send the NNTP STAT command to the server, receive the initial reply, and return the reply code. - *

    * * @param messageId The message identifier of the requested article, including the encapsulating < and > characters. * @return The reply code received from the server. @@ -746,7 +712,6 @@ public int stat(final String messageId) throws IOException { /** * A convenience method to send the NNTP XHDR command to the server, receive the reply, and return the reply code. - *

    * * @param header a String naming a header line (e.g., "subject"). See RFC-1036 for a list of valid header lines. * @param selectedArticles a String representation of the range of article headers required. This may be an article number, or a range of article numbers in @@ -767,7 +732,6 @@ public int xhdr(final String header, final String selectedArticles) throws IOExc /** * A convenience method to send the NNTP XOVER command to the server, receive the reply, and return the reply code. - *

    * * @param selectedArticles a String representation of the range of article headers required. This may be an article number, or a range of article numbers in * the form "XXXX-YYYY", where XXXX and YYYY are valid article numbers in the current group. It also may be of the form "XXX-", 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 0bc67d4d8..471400fcd 100644 --- a/src/main/java/org/apache/commons/net/nntp/NNTPClient.java +++ b/src/main/java/org/apache/commons/net/nntp/NNTPClient.java @@ -47,11 +47,13 @@ * {@link org.apache.commons.net.nntp.NNTP#disconnect disconnect() } to properly clean up the system resources used by NNTP. Before disconnecting, you may check * the last reply code and text with {@link org.apache.commons.net.nntp.NNTP#getReplyCode getReplyCode } and * {@link org.apache.commons.net.nntp.NNTP#getReplyString getReplyString }. + *

    *

    * Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can also throw a * {@link org.apache.commons.net.MalformedServerReplyException} , which is a subclass of IOException. A MalformedServerReplyException will be thrown when the * reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful manner despite attempts to be as * lenient as possible. + *

    * * @see NNTP * @see NNTPConnectionClosedException @@ -76,7 +78,7 @@ static Article parseArticleEntry(final String line) { final Article article = new Article(); article.setSubject(line); // in case parsing fails - final String parts[] = line.split("\t"); + final String[] parts = line.split("\t"); if (parts.length > 6) { int i = 0; try { @@ -99,7 +101,7 @@ static Article parseArticleEntry(final String line) { */ private static void parseGroupReply(final String reply, final NewsgroupInfo info) throws MalformedServerReplyException { - final String tokens[] = reply.split(" "); + final String[] tokens = reply.split(" "); if (tokens.length >= 5) { int i = 1; // Skip numeric response value try { @@ -124,7 +126,7 @@ private static void parseGroupReply(final String reply, final NewsgroupInfo info // Format: group last first p static NewsgroupInfo parseNewsgroupListEntry(final String entry) { - final String tokens[] = entry.split(" "); + final String[] tokens = entry.split(" "); if (tokens.length < 4) { return null; } @@ -139,7 +141,7 @@ static NewsgroupInfo parseNewsgroupListEntry(final String entry) { final long firstNum = Long.parseLong(tokens[i++]); result.setFirstArticle(firstNum); result.setLastArticle(lastNum); - if ((firstNum == 0) && (lastNum == 0)) { + if (firstNum == 0 && lastNum == 0) { result.setArticleCount(0); } else { result.setArticleCount(lastNum - firstNum + 1); @@ -188,7 +190,6 @@ private ArticleInfo ap2ai(@SuppressWarnings("deprecation") final ArticlePointer /** * Log into a news server by sending the AUTHINFO USER/AUTHINFO PASS command sequence. This is usually sent in response to a 480 reply code from the NNTP * server. - *

    * * @param username a valid username * @param password the corresponding password @@ -215,7 +216,7 @@ public boolean authenticate(final String username, final String password) throws * method to receive the completion reply from the server and verify the success of the entire transaction. *

    * For example - * + *

    *
          * writer = client.postArticle();
          * if (writer == null) // failure
    @@ -228,7 +229,6 @@ public boolean authenticate(final String username, final String password) throws
          * if (!client.completePendingCommand()) // failure
          *     return false;
          * 
    - *

    * * @return True if successfully completed, false if not. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -250,7 +250,6 @@ public Writer forwardArticle(final String articleId) throws IOException { /** * Return article headers for all articles between lowArticleNumber and highArticleNumber, inclusively, using the XOVER command. - *

    * * @param lowArticleNumber low * @param highArticleNumber high @@ -271,7 +270,6 @@ public Iterable

    iterateArticleInfo(final long lowArticleNumber, final l * List all new articles added to the NNTP server since a particular date subject to the conditions of the specified query. If no new news is found, * no entries will be returned. This uses the "NEWNEWS" command. You must add at least one newsgroup to the query, else the command will fail. * Each String which is returned is a unique message identifier including the enclosing < and >. - *

    * * @param query The query restricting how to search for new news. You must add at least one newsgroup to the query. * @return An iterator of String instances containing the unique message identifiers for each new article added to the NNTP server. If no new news is found, @@ -292,7 +290,6 @@ public Iterable iterateNewNews(final NewGroupsOrNewsQuery query) throws /** * List all new newsgroups added to the NNTP server since a particular date subject to the conditions of the specified query. If no new newsgroups were * added, no entries will be returned. This uses the "NEWGROUPS" command. - *

    * * @param query The query restricting how to search for new newsgroups. * @return An iterable of Strings containing the raw information for each new newsgroup added to the NNTP server. If no newsgroups were added, no entries @@ -313,7 +310,6 @@ public Iterable iterateNewNewsgroupListing(final NewGroupsOrNewsQuery qu /** * List all new newsgroups added to the NNTP server since a particular date subject to the conditions of the specified query. If no new newsgroups were * added, no entries will be returned. This uses the "NEWGROUPS" command. - *

    * * @param query The query restricting how to search for new newsgroups. * @return An iterable of NewsgroupInfo instances containing the information for each new newsgroup added to the NNTP server. If no newsgroups were added, @@ -330,7 +326,6 @@ public Iterable iterateNewNewsgroups(final NewGroupsOrNewsQuery q /** * List all newsgroups served by the NNTP server. If no newsgroups are served, no entries will be returned. The method uses the "LIST" command. - *

    * * @return An iterable of NewsgroupInfo instances containing the information for each newsgroup served by the NNTP server. If no newsgroups are served, no * entries will be returned. @@ -349,7 +344,6 @@ public Iterable iterateNewsgroupListing() throws IOException { /** * List the newsgroups that match a given pattern. Uses the "LIST ACTIVE" command. - *

    * * @param wildmat a pseudo-regex pattern (cf. RFC 2980) * @return An iterable of Strings containing the raw information for each newsgroup served by the NNTP server corresponding to the supplied pattern. If no @@ -366,7 +360,6 @@ public Iterable iterateNewsgroupListing(final String wildmat) throws IOE /** * List all newsgroups served by the NNTP server. If no newsgroups are served, no entries will be returned. The method uses the "LIST" command. - *

    * * @return An iterable of Strings containing the raw information for each newsgroup served by the NNTP server. If no newsgroups are served, no entries will * be returned. @@ -382,7 +375,6 @@ public Iterable iterateNewsgroups() throws IOException { /** * List the newsgroups that match a given pattern. Uses the "LIST ACTIVE" command. - *

    * * @param wildmat a pseudo-regex pattern (cf. RFC 2980) * @return An iterable NewsgroupInfo instances containing the information for each newsgroup served by the NNTP server corresponding to the supplied @@ -396,7 +388,6 @@ public Iterable iterateNewsgroups(final String wildmat) throws IO /** * List the command help from the server. - *

    * * @return The sever help information. * @throws NNTPConnectionClosedException If the NNTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -419,7 +410,6 @@ public String listHelp() throws IOException { * List all new articles added to the NNTP server since a particular date subject to the conditions of the specified query. If no new news is found, a * zero length array will be returned. If the command fails, null will be returned. You must add at least one newsgroup to the query, else the command will * fail. Each String in the returned array is a unique message identifier including the enclosing < and >. This uses the "NEWNEWS" command. - *

    * * @param query The query restricting how to search for new news. You must add at least one newsgroup to the query. * @return An array of String instances containing the unique message identifiers for each new article added to the NNTP server. If no new news is found, a @@ -459,7 +449,6 @@ public String[] listNewNews(final NewGroupsOrNewsQuery query) throws IOException /** * List all new newsgroups added to the NNTP server since a particular date subject to the conditions of the specified query. If no new newsgroups were * added, a zero length array will be returned. If the command fails, null will be returned. This uses the "NEWGROUPS" command. - *

    * * @param query The query restricting how to search for new newsgroups. * @return An array of NewsgroupInfo instances containing the information for each new newsgroup added to the NNTP server. If no newsgroups were added, a @@ -482,7 +471,6 @@ public NewsgroupInfo[] listNewNewsgroups(final NewGroupsOrNewsQuery query) throw /** * List all newsgroups served by the NNTP server. If no newsgroups are served, a zero length array will be returned. If the command fails, null will be * returned. The method uses the "LIST" command. - *

    * * @return An array of NewsgroupInfo instances containing the information for each newsgroup served by the NNTP server. If no newsgroups are served, a zero * length array will be returned. If the command fails, null will be returned. @@ -503,7 +491,6 @@ public NewsgroupInfo[] listNewsgroups() throws IOException { /** * List the newsgroups that match a given pattern. Uses the "LIST ACTIVE" command. - *

    * * @param wildmat a pseudo-regex pattern (cf. RFC 2980) * @return An array of NewsgroupInfo instances containing the information for each newsgroup served by the NNTP server corresponding to the supplied @@ -543,7 +530,6 @@ public String[] listOverviewFmt() throws IOException { /** * Logs out of the news server gracefully by sending the QUIT command. However, you must still disconnect from the server before you can open a new * connection. - *

    * * @return True if successfully completed, false if not. * @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server. @@ -561,7 +547,7 @@ public boolean logout() throws IOException { * @throws MalformedServerReplyException if response could not be parsed */ private void parseArticlePointer(final String reply, final ArticleInfo pointer) throws MalformedServerReplyException { - final String tokens[] = reply.split(" "); + final String[] tokens = reply.split(" "); if (tokens.length >= 3) { // OK, we can parset the line int i = 1; // skip reply code try { @@ -586,15 +572,17 @@ private void parseArticlePointer(final String reply, final ArticleInfo pointer) * The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned Writer actually writes directly to * the NNTP connection. After you close the writer, you can execute new commands. If you do not follow these requirements your program will not work * properly. + *

    *

    * Different NNTP servers will require different header formats, but you can use the provided {@link org.apache.commons.net.nntp.SimpleNNTPHeader} class to * construct the bare minimum acceptable header for most newsreaders. To construct more complicated headers you should refer to RFC 822. When the Java Mail * API is finalized, you will be able to use it to compose fully compliant Internet text messages. The DotTerminatedMessageWriter takes care of doubling * line-leading dots and ending the message with a single dot upon closing, so all you have to worry about is writing the header and the message. + *

    *

    * Upon closing the returned Writer, you need to call {@link #completePendingCommand completePendingCommand() } to finalize the posting and verify its * success or failure from the server reply. - *

    + *

    * * @return A DotTerminatedMessageWriter to which the article (including header) can be written. Returns null if the command fails. * @throws IOException If an I/O error occurs while either sending a command to the server or receiving a reply from the server. @@ -716,12 +704,13 @@ public BufferedReader retrieveArticle(final long articleNumber) throws IOExcepti * servers do not correctly follow the RFC 977 reply format. *

    * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + *

    *

    * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader * instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned BufferedReader actually * reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not * follow these requirements, your program will not work properly. - *

    + *

    * * @param articleNumber The number of the article to retrieve. * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of @@ -754,12 +743,13 @@ public Reader retrieveArticle(final String articleId) throws IOException { * cannot always be trusted because some NNTP servers do not correctly follow the RFC 977 reply format. *

    * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + *

    *

    * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader * instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned BufferedReader actually * reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not * follow these requirements, your program will not work properly. - *

    + *

    * * @param articleId The unique article identifier of the article to retrieve. If this parameter is null, the currently selected article is retrieved. * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of server @@ -844,12 +834,13 @@ public BufferedReader retrieveArticleBody(final long articleNumber) throws IOExc * some NNTP servers do not correctly follow the RFC 977 reply format. *

    * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + *

    *

    * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader * instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned BufferedReader actually * reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not * follow these requirements, your program will not work properly. - *

    + *

    * * @param articleNumber The number of the article whose body is being retrieved. * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of @@ -882,12 +873,13 @@ public Reader retrieveArticleBody(final String articleId) throws IOException { * cannot always be trusted because some NNTP servers do not correctly follow the RFC 977 reply format. *

    * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + *

    *

    * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader * instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned BufferedReader actually * reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not * follow these requirements, your program will not work properly. - *

    + *

    * * @param articleId The unique article identifier of the article whose body is being retrieved. If this parameter is null, the body of the currently * selected article is retrieved. @@ -973,12 +965,13 @@ public BufferedReader retrieveArticleHeader(final long articleNumber) throws IOE * some NNTP servers do not correctly follow the RFC 977 reply format. *

    * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + *

    *

    * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader * instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned BufferedReader actually * reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not * follow these requirements, your program will not work properly. - *

    + *

    * * @param articleNumber The number of the article whose header is being retrieved. * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of @@ -1011,12 +1004,13 @@ public Reader retrieveArticleHeader(final String articleId) throws IOException { * cannot always be trusted because some NNTP servers do not correctly follow the RFC 977 reply format. *

    * A DotTerminatedMessageReader is returned from which the article can be read. If the article does not exist, null is returned. + *

    *

    * You must not issue any commands to the NNTP server (i.e., call any other methods) until you finish reading the message from the returned BufferedReader * instance. The NNTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned BufferedReader actually * reads directly from the NNTP connection. After the end of message has been reached, new commands can be executed and their replies read. If you do not * follow these requirements, your program will not work properly. - *

    + *

    * * @param articleId The unique article identifier of the article whose header is being retrieved. If this parameter is null, the header of the currently * selected article is retrieved. @@ -1074,7 +1068,6 @@ public Reader retrieveArticleInfo(final int lowArticleNumber, final int highArti /** * Return article headers for a specified post. - *

    * * @param articleNumber the article to retrieve headers for * @return a DotTerminatedReader if successful, null otherwise @@ -1086,7 +1079,6 @@ public BufferedReader retrieveArticleInfo(final long articleNumber) throws IOExc /** * Return article headers for all articles between lowArticleNumber and highArticleNumber, inclusively. Uses the XOVER command. - *

    * * @param lowArticleNumber low number * @param highArticleNumber high number @@ -1101,7 +1093,6 @@ public BufferedReader retrieveArticleInfo(final long lowArticleNumber, final lon * Private implementation of XOVER functionality. * * See {@link NNTP#xover} for legal agument formats. Alternatively, read RFC 2980 :-) - *

    * * @param articleRange * @return Returns a DotTerminatedMessageReader if successful, null otherwise @@ -1127,9 +1118,6 @@ public Reader retrieveHeader(final String a, final int b) throws IOException { return retrieveHeader(a, (long) b); } - // DEPRECATED METHODS - for API compatibility only - DO NOT USE - // ============================================================ - /** * @param header the header * @param lowArticleNumber to fetch @@ -1145,7 +1133,6 @@ public Reader retrieveHeader(final String header, final int lowArticleNumber, fi /** * Return an article header for a specified post. - *

    * * @param header the header to retrieve * @param articleNumber the article to retrieve the header for @@ -1158,7 +1145,6 @@ public BufferedReader retrieveHeader(final String header, final long articleNumb /** * Return an article header for all articles between lowArticleNumber and highArticleNumber, inclusively. - *

    * * @param header the header * @param lowArticleNumber to fetch @@ -1172,9 +1158,9 @@ public BufferedReader retrieveHeader(final String header, final long lowArticleN /** * Private implementation of XHDR functionality. - * - * See {@link NNTP#xhdr} for legal argument formats. Alternatively, read RFC 1036. *

    + * See {@link NNTP#xhdr} for legal argument formats. Alternatively, read RFC 1036. + *

    * * @param header * @param articleRange @@ -1256,7 +1242,6 @@ public boolean selectArticle(final long articleNumber) throws IOException { * Select an article in the currently selected newsgroup by its number. and return its article number and id through the pointer parameter. This is achieved * through the STAT command. According to RFC 977, this WILL set the current article pointer on the server. Use this command to select an article before * retrieving it, or to obtain an article's unique identifier given its number. - *

    * * @param articleNumber The number of the article to select from the currently selected newsgroup. * @param pointer A parameter through which to return the article's number and unique id. Although the articleId field cannot always be trusted @@ -1295,7 +1280,6 @@ public boolean selectArticle(final String articleId) throws IOException { * Select an article by its unique identifier (including enclosing < and >) and return its article number and id through the pointer parameter. This * is achieved through the STAT command. According to RFC 977, this will NOT set the current article pointer on the server. To do that, you must reference * the article by its number. - *

    * * @param articleId The unique article identifier of the article that is being selectedd. If this parameter is null, the body of the current article is * selected @@ -1354,7 +1338,6 @@ public boolean selectNewsgroup(final String newsgroup) throws IOException { /** * Select the specified newsgroup to be the target of for future article retrieval and posting operations. Also return the newsgroup information contained * in the server reply through the info parameter. - *

    * * @param newsgroup The newsgroup to select. * @param info A parameter through which the newsgroup information of the selected newsgroup contained in the server reply is returned. Set this to @@ -1391,7 +1374,6 @@ public boolean selectNextArticle() throws IOException { * Select the article following the currently selected article in the currently selected newsgroup and return its number and unique id through the pointer * parameter. Because of deviating server implementations, the articleId information cannot be trusted. To obtain the article identifier, issue a * selectArticle(pointer.articleNumber, pointer) immediately afterward. - *

    * * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of server * deviations from RFC 977 reply formats. You may set this parameter to null if you do not desire to retrieve the returned article @@ -1445,7 +1427,6 @@ public boolean selectPreviousArticle() throws IOException { * Select the article preceding the currently selected article in the currently selected newsgroup and return its number and unique id through the pointer * parameter. Because of deviating server implementations, the articleId information cannot be trusted. To obtain the article identifier, issue a * selectArticle(pointer.articleNumber, pointer) immediately afterward. - *

    * * @param pointer A parameter through which to return the article's number and unique id. The articleId field cannot always be trusted because of server * deviations from RFC 977 reply formats. You may set this parameter to null if you do not desire to retrieve the returned article diff --git a/src/main/java/org/apache/commons/net/nntp/Threader.java b/src/main/java/org/apache/commons/net/nntp/Threader.java index 9c11c68d6..8f1a0b406 100644 --- a/src/main/java/org/apache/commons/net/nntp/Threader.java +++ b/src/main/java/org/apache/commons/net/nntp/Threader.java @@ -46,7 +46,7 @@ private void buildContainer(final Threadable threadable, final HashMap"; + id = ""; container = null; } else { // The container just contained a forward reference to this message, so let's @@ -79,7 +79,7 @@ private void buildContainer(final Threadable threadable, final HashMap make this message a child of old c.parent = old; c.next = old.child; @@ -296,9 +296,9 @@ private void gatherSubjects(final NntpThreadContainer root) { */ private void pruneEmptyContainers(final NntpThreadContainer parent) { NntpThreadContainer container, prev, next; - for (prev = null, container = parent.child, next = container.next; container != null; prev = container, container = next, next = (container == null + for (prev = null, container = parent.child, next = container.next; container != null; prev = container, container = next, next = container == null ? null - : container.next)) { + : container.next) { // Is it empty and without any children? If so,delete it if (container.threadable == null && container.child == null) { @@ -393,7 +393,7 @@ public Threadable thread(final Iterable messages) { } } - final Threadable result = (root.child == null ? null : root.child.threadable); + final Threadable result = root.child == null ? null : root.child.threadable; root.flush(); return result; diff --git a/src/main/java/org/apache/commons/net/ntp/NtpUtils.java b/src/main/java/org/apache/commons/net/ntp/NtpUtils.java index 4280e0b3d..3981a0f48 100644 --- a/src/main/java/org/apache/commons/net/ntp/NtpUtils.java +++ b/src/main/java/org/apache/commons/net/ntp/NtpUtils.java @@ -29,7 +29,7 @@ public final class NtpUtils { * @return the raw IP address in a string format. */ public static String getHostAddress(final int address) { - return ((address >>> 24) & 0xFF) + "." + ((address >>> 16) & 0xFF) + "." + ((address >>> 8) & 0xFF) + "." + ((address >>> 0) & 0xFF); + return (address >>> 24 & 0xFF) + "." + (address >>> 16 & 0xFF) + "." + (address >>> 8 & 0xFF) + "." + (address >>> 0 & 0xFF); } /** @@ -68,7 +68,7 @@ public static String getModeName(final int mode) { * @return the packet reference id (as IP address) in "%d.%d.%d.%d" format. */ public static String getRefAddress(final NtpV3Packet packet) { - final int address = (packet == null) ? 0 : packet.getReferenceId(); + final int address = packet == null ? 0 : packet.getReferenceId(); return getHostAddress(address); } @@ -90,7 +90,7 @@ public static String getReferenceClock(final NtpV3Packet message) { final StringBuilder buf = new StringBuilder(4); // start at highest-order byte (0x4c434c00 -> LCL) for (int shiftBits = 24; shiftBits >= 0; shiftBits -= 8) { - final char c = (char) ((refId >>> shiftBits) & 0xff); + final char c = (char) (refId >>> shiftBits & 0xff); if (c == 0) { // 0-terminated ASCII string break; } diff --git a/src/main/java/org/apache/commons/net/pop3/ExtendedPOP3Client.java b/src/main/java/org/apache/commons/net/pop3/ExtendedPOP3Client.java index 94632ee24..6b796a4b3 100644 --- a/src/main/java/org/apache/commons/net/pop3/ExtendedPOP3Client.java +++ b/src/main/java/org/apache/commons/net/pop3/ExtendedPOP3Client.java @@ -70,7 +70,6 @@ public ExtendedPOP3Client() throws NoSuchAlgorithmException { /** * Authenticate to the POP3 server by sending the AUTH command with the selected mechanism, using the given username and the given password. - *

    * * @param method the {@link AUTH_METHOD} to use * @param username the username diff --git a/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java b/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java index 9148cc699..81959c782 100644 --- a/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java +++ b/src/main/java/org/apache/commons/net/smtp/AuthenticatingSMTPClient.java @@ -217,7 +217,6 @@ private String convertToHexString(final byte[] a) { /** * A convenience method to send the ESMTP EHLO command to the server, receive the reply, and return the reply code. - *

    * * @param hostname The hostname of the sender. * @return The reply code received from the server. @@ -232,7 +231,6 @@ public int ehlo(final String hostname) throws IOException { /** * Login to the ESMTP server by sending the EHLO command with the client hostname as an argument. Before performing any mail commands, you must first login. - *

    * * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -256,7 +254,6 @@ public boolean elogin() throws IOException { /** * Login to the ESMTP server by sending the EHLO command with the given hostname as an argument. Before performing any mail commands, you must first login. - *

    * * @param hostname The hostname with which to greet the SMTP server. * @return True if successfully completed, false if not. @@ -282,5 +279,3 @@ public int[] getEnhancedReplyCode() { return res; } } - -/* kate: indent-width 4; replace-tabs on; */ diff --git a/src/main/java/org/apache/commons/net/smtp/SMTP.java b/src/main/java/org/apache/commons/net/smtp/SMTP.java index 79660ed34..a242c7361 100644 --- a/src/main/java/org/apache/commons/net/smtp/SMTP.java +++ b/src/main/java/org/apache/commons/net/smtp/SMTP.java @@ -120,7 +120,6 @@ protected void _connectAction_() throws IOException { /** * A convenience method to send the SMTP DATA command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -135,7 +134,6 @@ public int data() throws IOException { /** * Closes the connection to the SMTP server and sets to null some internal data so that the memory may be reclaimed by the garbage collector. The reply text * and code information from the last command is voided so that the memory it used may be reclaimed. - *

    * * @throws IOException If an error occurs while disconnecting. */ @@ -151,7 +149,6 @@ public void disconnect() throws IOException { /** * A convenience method to send the SMTP VRFY command to the server, receive the reply, and return the reply code. - *

    * * @param name The name to expand. * @return The reply code received from the server. @@ -176,7 +173,6 @@ protected ProtocolCommandSupport getCommandSupport() { * Fetches a reply from the SMTP server and returns the integer reply code. After calling this method, the actual reply text can be accessed from either * calling {@link #getReplyString getReplyString } or {@link #getReplyStrings getReplyStrings }. Only use this method if you are implementing your own SMTP * client or if you need to fetch a secondary response from the SMTP server. - *

    * * @return The integer value of the reply code of the fetched SMTP reply. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -243,7 +239,6 @@ public int getReply() throws IOException { /** * Returns the integer value of the reply code of the last SMTP reply. You will usually only use this method after you connect to the SMTP server to check * that the connection was successful since connect is of type void. - *

    * * @return The integer value of the reply code of the last SMTP reply. */ @@ -253,7 +248,6 @@ public int getReplyCode() { /** * Returns the entire text of the last SMTP server response exactly as it was received, including all end of line markers in NETASCII format. - *

    * * @return The entire text from the last SMTP response as a String. */ @@ -280,7 +274,6 @@ public String getReplyString() { /** * Returns the lines of text from the last SMTP server response as an array of strings, one entry per line. The end of line markers of each are stripped * from each line. - *

    * * @return The lines of text from the last SMTP response as an array. */ @@ -290,7 +283,6 @@ public String[] getReplyStrings() { /** * A convenience method to send the SMTP HELO command to the server, receive the reply, and return the reply code. - *

    * * @param hostname The hostname of the sender. * @return The reply code received from the server. @@ -305,7 +297,6 @@ public int helo(final String hostname) throws IOException { /** * A convenience method to send the SMTP HELP command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -319,7 +310,6 @@ public int help() throws IOException { /** * A convenience method to send the SMTP HELP command to the server, receive the reply, and return the reply code. - *

    * * @param command The command name on which to request help. * @return The reply code received from the server. @@ -334,7 +324,6 @@ public int help(final String command) throws IOException { /** * A convenience method to send the SMTP MAIL command to the server, receive the reply, and return the reply code. - *

    * * @param reversePath The reverse path. * @return The reply code received from the server. @@ -349,7 +338,6 @@ public int mail(final String reversePath) throws IOException { /** * A convenience method to send the SMTP NOOP command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -363,7 +351,6 @@ public int noop() throws IOException { /** * A convenience method to send the SMTP QUIT command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -377,7 +364,6 @@ public int quit() throws IOException { /** * A convenience method to send the SMTP RCPT command to the server, receive the reply, and return the reply code. - *

    * * @param forwardPath The forward path. * @return The reply code received from the server. @@ -404,7 +390,6 @@ public void removeProtocolCommandistener(final org.apache.commons.net.ProtocolCo /** * A convenience method to send the SMTP RSET command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -418,7 +403,6 @@ public int rset() throws IOException { /** * A convenience method to send the SMTP SAML command to the server, receive the reply, and return the reply code. - *

    * * @param reversePath The reverse path. * @return The reply code received from the server. @@ -433,7 +417,6 @@ public int saml(final String reversePath) throws IOException { /** * A convenience method to send the SMTP SEND command to the server, receive the reply, and return the reply code. - *

    * * @param reversePath The reverse path. * @return The reply code received from the server. @@ -449,7 +432,6 @@ public int send(final String reversePath) throws IOException { /** * Sends an SMTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed * information, the actual reply text can be accessed by calling {@link #getReplyString getReplyString } or {@link #getReplyStrings getReplyStrings }. - *

    * * @param command The SMTPCommand constant corresponding to the SMTP command to send. * @return The integer value of the SMTP reply code returned by the server in response to the command. @@ -465,7 +447,6 @@ public int sendCommand(final int command) throws IOException { /** * Sends an SMTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the * actual reply text can be accessed by calling {@link #getReplyString getReplyString } or {@link #getReplyStrings getReplyStrings }. - *

    * * @param command The SMTPCommand constant corresponding to the SMTP command to send. * @param args The arguments to the SMTP command. If this parameter is set to null, then the command is sent with no argument. @@ -494,7 +475,6 @@ private int sendCommand(final int command, final String args, final boolean incl /** * Sends an SMTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed * information, the actual reply text can be accessed by calling {@link #getReplyString getReplyString } or {@link #getReplyStrings getReplyStrings }. - *

    * * @param command The text representation of the SMTP command to send. * @return The integer value of the SMTP reply code returned by the server in response to the command. @@ -510,7 +490,6 @@ public int sendCommand(final String command) throws IOException { /** * Sends an SMTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the * actual reply text can be accessed by calling {@link #getReplyString getReplyString } or {@link #getReplyStrings getReplyStrings }. - *

    * * @param command The text representation of the SMTP command to send. * @param args The arguments to the SMTP command. If this parameter is set to null, then the command is sent with no argument. @@ -557,7 +536,6 @@ private int sendCommand(final String command, final String args, final boolean i /** * A convenience method to send the SMTP SOML command to the server, receive the reply, and return the reply code. - *

    * * @param reversePath The reverse path. * @return The reply code received from the server. @@ -572,7 +550,6 @@ public int soml(final String reversePath) throws IOException { /** * A convenience method to send the SMTP TURN command to the server, receive the reply, and return the reply code. - *

    * * @return The reply code received from the server. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -586,7 +563,6 @@ public int turn() throws IOException { /** * A convenience method to send the SMTP VRFY command to the server, receive the reply, and return the reply code. - *

    * * @param user The user address to verify. * @return The reply code received from the server. 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 3fb05f195..cb9d4647f 100644 --- a/src/main/java/org/apache/commons/net/smtp/SMTPClient.java +++ b/src/main/java/org/apache/commons/net/smtp/SMTPClient.java @@ -40,7 +40,7 @@ * // success. * reply = client.getReplyCode(); * - * if(!SMTPReply.isPositiveCompletion(reply)) { + * if (!SMTPReply.isPositiveCompletion(reply)) { * client.disconnect(); * System.err.println("SMTP server refused connection."); * System.exit(1); @@ -49,7 +49,7 @@ * // Do useful stuff here. * ... * } catch (IOException e) { - * if(client.isConnected()) { + * if (client.isConnected()) { * try { * client.disconnect(); * } catch (IOException f) { @@ -67,6 +67,7 @@ * reply from the SMTP server and false on a reply resulting in an error condition or failure. The methods returning a value other than boolean return a value * containing the higher level data produced by the SMTP command, or null if a reply resulted in an error condition or failure. If you want to access the exact * SMTP reply code causing a success or failure, you must call {@link org.apache.commons.net.smtp.SMTP#getReplyCode getReplyCode } after a success or failure. + *

    *

    * You should keep in mind that the SMTP server may choose to prematurely close a connection for various reasons. The SMTPClient class will detect a premature * SMTP server connection closing when it receives a {@link org.apache.commons.net.smtp.SMTPReply#SERVICE_NOT_AVAILABLE SMTPReply.SERVICE_NOT_AVAILABLE } @@ -77,11 +78,13 @@ * clean up the system resources used by SMTPClient. Before disconnecting, you may check the last reply code and text with * {@link org.apache.commons.net.smtp.SMTP#getReplyCode getReplyCode }, {@link org.apache.commons.net.smtp.SMTP#getReplyString getReplyString }, and * {@link org.apache.commons.net.smtp.SMTP#getReplyStrings getReplyStrings}. + *

    *

    * Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can also throw a * {@link org.apache.commons.net.MalformedServerReplyException} , which is a subclass of IOException. A MalformedServerReplyException will be thrown when the * reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful manner despite attempts to be as * lenient as possible. + *

    * * @see SMTP * @see SimpleSMTPHeader @@ -111,7 +114,6 @@ public SMTPClient(final String encoding) { /** * 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 * specified, otherwise the mail server will reject your commands. - *

    * * @param path The forward relay path pointing to the recipient. * @return True if successfully completed, false if not. @@ -127,7 +129,6 @@ public boolean addRecipient(final RelayPath path) throws IOException { /** * 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 * specified, otherwise the mail server will reject your commands. - *

    * * @param address The recipient's email address. * @return True if successfully completed, false if not. @@ -146,7 +147,7 @@ public boolean addRecipient(final String address) throws IOException { * code completes its actions, it must call this method to receive the completion reply from the server and verify the success of the entire transaction. *

    * For example, - * + *

    *
          * writer = client.sendMessageData();
          * if (writer == null) // failure
    @@ -158,7 +159,6 @@ public boolean addRecipient(final String address) throws IOException {
          * if (!client.completePendingCommand()) // failure
          *     return false;
          * 
    - *

    * * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -172,7 +172,6 @@ public boolean completePendingCommand() throws IOException { /** * Fetches the system help information from the server and returns the full string. - *

    * * @return The system help string obtained from the server. null if the information could not be obtained. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -189,7 +188,6 @@ public String listHelp() throws IOException { /** * Fetches the help information for a given command from the server and returns the full string. - *

    * * @param command The command on which to ask for help. * @return The command help string obtained from the server. null if the information could not be obtained. @@ -208,7 +206,6 @@ public String listHelp(final String command) throws IOException { /** * Login to the SMTP server by sending the {@code HELO} command with the client hostname as an argument. * Before performing any mail commands, you must first log in. - *

    * * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -233,7 +230,6 @@ public boolean login() throws IOException { /** * Login to the SMTP server by sending the {@code HELO} command with the given hostname as an argument. * Before performing any mail commands, you must first log in. - *

    * * @param hostname The hostname with which to greet the SMTP server. * @return True if successfully completed, false if not. @@ -248,7 +244,6 @@ public boolean login(final String hostname) throws IOException { /** * Logout of the SMTP server by sending the QUIT command. - *

    * * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -262,7 +257,6 @@ public boolean logout() throws IOException { /** * Aborts the current mail transaction, resetting all server stored sender, recipient, and mail data, cleaning all buffers and tables. - *

    * * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -282,15 +276,17 @@ public boolean reset() throws IOException { * The SMTP protocol uses the same stream for issuing commands as it does for returning results. Therefore, the returned Writer actually writes directly to * the SMTP connection. After you close the writer, you can execute new commands. If you do not follow these requirements your program will not work * properly. + *

    *

    * You can use the provided {@link org.apache.commons.net.smtp.SimpleSMTPHeader} class to construct a bare minimum header. To construct more complicated * headers you should refer to RFC 5322. When the Java Mail API is finalized, you will be able to use it to compose fully compliant Internet text messages. * The DotTerminatedMessageWriter takes care of doubling line-leading dots and ending the message with a single dot upon closing, so all you have to worry * about is writing the header and the message. + *

    *

    * Upon closing the returned Writer, you need to call {@link #completePendingCommand completePendingCommand() } to finalize the transaction and verify its * success or failure from the server reply. - *

    + *

    * * @return A DotTerminatedMessageWriter to which the message (including header) can be written. Returns null if the command fails. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -309,7 +305,6 @@ public Writer sendMessageData() throws IOException { /** * Sends a NOOP command to the SMTP server. This is useful for preventing server timeouts. - *

    * * @return True if successfully completed, false if not. * @throws SMTPConnectionClosedException If the SMTP server prematurely closes the connection as a result of the client being idle or some other reason @@ -325,7 +320,6 @@ public boolean sendNoOp() throws IOException { * A convenience method for sending 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. - *

    * * @param message The short email message to send. This must include the headers and the body, but not the trailing "." * @return True if successfully completed, false if not. @@ -351,7 +345,6 @@ public boolean sendShortMessageData(final String message) throws IOException { * 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 * using {@link #setSender setSender } and {@link #addRecipient addRecipient }, and then sends the message using {@link #sendShortMessageData * sendShortMessageData }. - *

    * * @param sender The email address of the sender. * @param recipient The email address of the recipient. @@ -381,7 +374,7 @@ public boolean sendSimpleMessage(final String sender, final String recipient, fi *

    * Note that the method ignores failures when calling {@link #addRecipient(String) addRecipient} so long as at least one call succeeds. If no recipients can * be successfully added then the method will fail (and does not attempt to send the message) - *

    + *

    * * @param sender The email address of the sender. * @param recipients An array of recipient email addresses. @@ -416,7 +409,6 @@ public boolean sendSimpleMessage(final String sender, final String[] recipients, /** * Set the sender of a message using the SMTP MAIL command, specifying a reverse 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 reverse relay path pointing back to the sender. * @return True if successfully completed, false if not. @@ -432,7 +424,6 @@ public boolean setSender(final RelayPath path) throws IOException { /** * Set the sender of a message using the SMTP MAIL command, specifying the sender'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 sender's email address. * @return True if successfully completed, false if not. @@ -447,7 +438,6 @@ public boolean setSender(final String address) throws IOException { /** * Verify that a username or email address is valid, i.e., that mail can be delivered to that mailbox on the server. - *

    * * @param username The username or email address to validate. * @return True if the username is valid, false if not. diff --git a/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java b/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java index b5b79fe5d..f86b926de 100644 --- a/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java +++ b/src/main/java/org/apache/commons/net/smtp/SimpleSMTPHeader.java @@ -30,7 +30,7 @@ * *

      * writer = client.sendMessageData();
    - * if(writer == null) // failure
    + * if (writer == null) // failure
      *   return false;
      * header =
      *    new SimpleSMTPHeader("foobar@foo.com", "foo@bar.com" "Just testing");
    @@ -39,7 +39,7 @@
      * writer.write(header.toString());
      * writer.write("This is just a test");
      * writer.close();
    - * if(!client.completePendingCommand()) // failure
    + * if (!client.completePendingCommand()) // failure
      *   return false;
      * 
    * diff --git a/src/main/java/org/apache/commons/net/telnet/EchoOptionHandler.java b/src/main/java/org/apache/commons/net/telnet/EchoOptionHandler.java index 7bd197fce..b17331bc3 100644 --- a/src/main/java/org/apache/commons/net/telnet/EchoOptionHandler.java +++ b/src/main/java/org/apache/commons/net/telnet/EchoOptionHandler.java @@ -31,7 +31,6 @@ public EchoOptionHandler() { /** * Constructor for the EchoOptionHandler. Allows defining desired initial setting for local/remote activation of this option and behavior in case a * local/remote activation request for this option is received. - *

    * * @param initlocal - if set to true, a WILL is sent upon connection. * @param initremote - if set to true, a DO is sent upon connection. diff --git a/src/main/java/org/apache/commons/net/telnet/Telnet.java b/src/main/java/org/apache/commons/net/telnet/Telnet.java index c198ff4c3..f4177aa94 100644 --- a/src/main/java/org/apache/commons/net/telnet/Telnet.java +++ b/src/main/java/org/apache/commons/net/telnet/Telnet.java @@ -822,7 +822,7 @@ void setDo(final int option) throws IOException { options[option] |= DO_MASK; /* open TelnetOptionHandler functionality (start) */ - if (requestedDo(option) && (optionHandlers[option] != null)) { + if (requestedDo(option) && optionHandlers[option] != null) { optionHandlers[option].setDo(true); final int[] subneg = optionHandlers[option].startSubnegotiationRemote(); @@ -895,7 +895,7 @@ void setWill(final int option) throws IOException { options[option] |= WILL_MASK; /* open TelnetOptionHandler functionality (start) */ - if (requestedWill(option) && (optionHandlers[option] != null)) { + if (requestedWill(option) && optionHandlers[option] != null) { optionHandlers[option].setWill(true); final int[] subneg = optionHandlers[option].startSubnegotiationLocal(); diff --git a/src/main/java/org/apache/commons/net/telnet/TelnetCommand.java b/src/main/java/org/apache/commons/net/telnet/TelnetCommand.java index cd1ae813a..e483d6acf 100644 --- a/src/main/java/org/apache/commons/net/telnet/TelnetCommand.java +++ b/src/main/java/org/apache/commons/net/telnet/TelnetCommand.java @@ -92,7 +92,7 @@ public final class TelnetCommand { public static final int SYNCH = 242; /** String representations of commands. */ - private static final String commandString[] = { "IAC", "DONT", "DO", "WONT", "WILL", "SB", "GA", "EL", "EC", "AYT", "AO", "IP", "BRK", "DMARK", "NOP", "SE", + private static final String[] commandString = { "IAC", "DONT", "DO", "WONT", "WILL", "SB", "GA", "EL", "EC", "AYT", "AO", "IP", "BRK", "DMARK", "NOP", "SE", "EOR", "ABORT", "SUSP", "EOF" }; private static final int FIRST_COMMAND = IAC; diff --git a/src/main/java/org/apache/commons/net/telnet/TelnetOption.java b/src/main/java/org/apache/commons/net/telnet/TelnetOption.java index 5fc64dfcf..9d85c461b 100644 --- a/src/main/java/org/apache/commons/net/telnet/TelnetOption.java +++ b/src/main/java/org/apache/commons/net/telnet/TelnetOption.java @@ -117,7 +117,7 @@ public class TelnetOption { private static final int FIRST_OPTION = BINARY; private static final int LAST_OPTION = EXTENDED_OPTIONS_LIST; - private static final String optionString[] = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", + private static final String[] optionString = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING", "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", "ENCRYPT", "NEW-ENVIRON", "TN3270E", "XAUTH", "CHARSET", "RSP", diff --git a/src/main/java/org/apache/commons/net/telnet/TelnetOptionHandler.java b/src/main/java/org/apache/commons/net/telnet/TelnetOptionHandler.java index bd7de0a38..3648847ee 100644 --- a/src/main/java/org/apache/commons/net/telnet/TelnetOptionHandler.java +++ b/src/main/java/org/apache/commons/net/telnet/TelnetOptionHandler.java @@ -21,6 +21,7 @@ * The TelnetOptionHandler class is the base class to be used for implementing handlers for telnet options. *

    * TelnetOptionHandler implements basic option handling functionality and defines abstract methods that must be implemented to define subnegotiation behavior. + *

    */ public abstract class TelnetOptionHandler { /** @@ -61,7 +62,6 @@ public abstract class TelnetOptionHandler { /** * Constructor for the TelnetOptionHandler. Allows defining desired initial setting for local/remote activation of this option and behavior in case a * local/remote activation request for this option is received. - *

    * * @param optcode - Option code. * @param initlocal - if set to true, a {@code WILL} is sent upon connection. @@ -82,11 +82,10 @@ public TelnetOptionHandler(final int optcode, final boolean initlocal, final boo *

    * This implementation returns null, and must be overridden by the actual TelnetOptionHandler to specify which response must be sent for the subnegotiation * request. - *

    + *

    * * @param suboptionData - the sequence received, without IAC SB & IAC SE * @param suboptionLength - the length of data in suboption_data - *

    * @return response to be sent to the subnegotiation sequence. TelnetClient will add IAC SB & IAC SE. null means no response */ public int[] answerSubnegotiation(final int suboptionData[], final int suboptionLength) { @@ -94,8 +93,7 @@ public int[] answerSubnegotiation(final int suboptionData[], final int suboption } /** - * Returns a boolean indicating whether to accept a DO request coming from the other end. - *

    + * Gets a boolean indicating whether to accept a DO request coming from the other end. * * @return true if a {@code DO} request shall be accepted. */ @@ -104,8 +102,7 @@ public boolean getAcceptLocal() { } /** - * Returns a boolean indicating whether to accept a WILL request coming from the other end. - *

    + * Gets a boolean indicating whether to accept a WILL request coming from the other end. * * @return true if a {@code WILL} request shall be accepted. */ @@ -114,8 +111,7 @@ public boolean getAcceptRemote() { } /** - * Returns a boolean indicating whether a {@code DO} request sent to the other side has been acknowledged. - *

    + * Gets a boolean indicating whether a {@code DO} request sent to the other side has been acknowledged. * * @return true if a {@code DO} sent to the other side has been acknowledged. */ @@ -124,8 +120,7 @@ boolean getDo() { } /** - * Returns a boolean indicating whether to send a WILL request to the other end upon connection. - *

    + * Gets a boolean indicating whether to send a WILL request to the other end upon connection. * * @return true if a {@code WILL} request shall be sent upon connection. */ @@ -134,8 +129,7 @@ public boolean getInitLocal() { } /** - * Returns a boolean indicating whether to send a DO request to the other end upon connection. - *

    + * Gets a boolean indicating whether to send a DO request to the other end upon connection. * * @return true if a {@code DO} request shall be sent upon connection. */ @@ -144,8 +138,7 @@ public boolean getInitRemote() { } /** - * Returns the option code for this option. - *

    + * Gets the option code for this option. * * @return Option code. */ @@ -154,8 +147,7 @@ public int getOptionCode() { } /** - * Returns a boolean indicating whether a {@code WILL} request sent to the other side has been acknowledged. - *

    + * Gets a boolean indicating whether a {@code WILL} request sent to the other side has been acknowledged. * * @return true if a {@code WILL} sent to the other side has been acknowledged. */ @@ -164,8 +156,7 @@ boolean getWill() { } /** - * Set behavior of the option for DO requests coming from the other end. - *

    + * Sets behavior of the option for DO requests coming from the other end. * * @param accept - if true, subsequent DO requests will be accepted. */ @@ -174,8 +165,7 @@ public void setAcceptLocal(final boolean accept) { } /** - * Set behavior of the option for {@code WILL} requests coming from the other end. - *

    + * Sets behavior of the option for {@code WILL} requests coming from the other end. * * @param accept - if true, subsequent {@code WILL} requests will be accepted. */ @@ -184,8 +174,7 @@ public void setAcceptRemote(final boolean accept) { } /** - * Tells this option whether a {@code DO} request sent to the other side has been acknowledged (invoked by TelnetClient). - *

    + * Sets this option whether a {@code DO} request sent to the other side has been acknowledged (invoked by TelnetClient). * * @param state - if true, a {@code DO} request has been acknowledged. */ @@ -194,8 +183,7 @@ void setDo(final boolean state) { } /** - * Tells this option whether to send a {@code WILL} request upon connection. - *

    + * Sets this option whether to send a {@code WILL} request upon connection. * * @param init - if true, a {@code WILL} request will be sent upon subsequent connections. */ @@ -204,8 +192,7 @@ public void setInitLocal(final boolean init) { } /** - * Tells this option whether to send a {@code DO} request upon connection. - *

    + * Sets this option whether to send a {@code DO} request upon connection. * * @param init - if true, a {@code DO} request will be sent upon subsequent connections. */ @@ -214,8 +201,7 @@ public void setInitRemote(final boolean init) { } /** - * Tells this option whether a {@code WILL} request sent to the other side has been acknowledged (invoked by TelnetClient). - *

    + * Sets this option whether a {@code WILL} request sent to the other side has been acknowledged (invoked by TelnetClient). * * @param state - if true, a {@code WILL} request has been acknowledged. */ @@ -229,6 +215,7 @@ void setWill(final boolean state) { *

    * This implementation returns null, and must be overriden by the actual TelnetOptionHandler to specify which response must be sent for the subnegotiation * request. + *

    * * @return subnegotiation sequence to be sent by TelnetClient. TelnetClient will add IAC SB & IAC SE. null means no subnegotiation. */ @@ -242,6 +229,7 @@ public int[] startSubnegotiationLocal() { *

    * This implementation returns null, and must be overridden by the actual TelnetOptionHandler to specify which response must be sent for the subnegotiation * request. + *

    * * @return subnegotiation sequence to be sent by TelnetClient. TelnetClient will add IAC SB & IAC SE. null means no subnegotiation. */ diff --git a/src/main/java/org/apache/commons/net/telnet/TerminalTypeOptionHandler.java b/src/main/java/org/apache/commons/net/telnet/TerminalTypeOptionHandler.java index 64ab01b66..d02daf86c 100644 --- a/src/main/java/org/apache/commons/net/telnet/TerminalTypeOptionHandler.java +++ b/src/main/java/org/apache/commons/net/telnet/TerminalTypeOptionHandler.java @@ -80,9 +80,9 @@ public TerminalTypeOptionHandler(final String termtype, final boolean initlocal, */ @Override public int[] answerSubnegotiation(final int suboptionData[], final int suboptionLength) { - if ((suboptionData != null) && (suboptionLength > 1) && (termType != null)) { - if ((suboptionData[0] == TERMINAL_TYPE) && (suboptionData[1] == TERMINAL_TYPE_SEND)) { - final int response[] = new int[termType.length() + 2]; + if (suboptionData != null && suboptionLength > 1 && termType != null) { + if (suboptionData[0] == TERMINAL_TYPE && suboptionData[1] == TERMINAL_TYPE_SEND) { + final int[] response = new int[termType.length() + 2]; response[0] = TERMINAL_TYPE; response[1] = TERMINAL_TYPE_IS; diff --git a/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java b/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java index 68a35784a..f54746134 100644 --- a/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java +++ b/src/main/java/org/apache/commons/net/telnet/WindowSizeOptionHandler.java @@ -105,7 +105,7 @@ public int[] startSubnegotiationLocal() { // // allocate response array // - final int response[] = new int[nResponseSize]; + final int[] response = new int[nResponseSize]; // // Build response array. diff --git a/src/main/java/org/apache/commons/net/tftp/TFTPDataPacket.java b/src/main/java/org/apache/commons/net/tftp/TFTPDataPacket.java index 2a1c7477a..32ba24c2d 100644 --- a/src/main/java/org/apache/commons/net/tftp/TFTPDataPacket.java +++ b/src/main/java/org/apache/commons/net/tftp/TFTPDataPacket.java @@ -69,7 +69,7 @@ public final class TFTPDataPacket extends TFTPPacket { throw new TFTPPacketException("TFTP operator code does not match type."); } - this.blockNumber = (((this.data[2] & 0xff) << 8) | (this.data[3] & 0xff)); + this.blockNumber = (this.data[2] & 0xff) << 8 | this.data[3] & 0xff; this.length = datagram.getLength() - 4; diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java b/src/main/java/org/apache/commons/net/util/SubnetUtils.java index c722d6a80..74606ea82 100644 --- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java +++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java @@ -195,7 +195,7 @@ private long networkLong() { * Converts a packed integer address into a 4-element array */ private int[] toArray(final int val) { - final int ret[] = new int[4]; + final int[] ret = new int[4]; for (int j = 3; j >= 0; --j) { ret[j] |= val >>> 8 * (3 - j) & 0xff; } diff --git a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java index bf8250b11..85b0c60d9 100644 --- a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java +++ b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java @@ -24,7 +24,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; import org.apache.commons.net.util.SubnetUtils; import org.apache.commons.net.util.SubnetUtils.SubnetInfo; @@ -275,23 +274,13 @@ public void testNET521() { info = utils.getInfo(); assertEquals("0.0.0.0", info.getNetmask()); assertEquals(4294967296L, info.getAddressCountLong()); - try { - info.getAddressCount(); - fail("Expected RuntimeException"); - } catch (final RuntimeException expected) { - // ignored - } + assertThrows(RuntimeException.class, info::getAddressCount); utils = new SubnetUtils("128.0.0.0/1"); utils.setInclusiveHostCount(true); info = utils.getInfo(); assertEquals("128.0.0.0", info.getNetmask()); assertEquals(2147483648L, info.getAddressCountLong()); - try { - info.getAddressCount(); - fail("Expected RuntimeException"); - } catch (final RuntimeException expected) { - // ignored - } + assertThrows(RuntimeException.class, info::getAddressCount); // if we exclude the broadcast and network addresses, the count is less than Integer.MAX_VALUE utils.setInclusiveHostCount(false); info = utils.getInfo(); @@ -341,15 +330,15 @@ public void testNext() { @Test public void testParseSimpleNetmask() { final String address = "192.168.0.1"; - final String masks[] = { "255.0.0.0", "255.255.0.0", "255.255.255.0", "255.255.255.248" }; - final String bcastAddresses[] = { "192.255.255.255", "192.168.255.255", "192.168.0.255", "192.168.0.7" }; - final String lowAddresses[] = { "192.0.0.1", "192.168.0.1", "192.168.0.1", "192.168.0.1" }; - final String highAddresses[] = { "192.255.255.254", "192.168.255.254", "192.168.0.254", "192.168.0.6" }; - final String nextAddresses[] = { "192.168.0.2", "192.168.0.2", "192.168.0.2", "192.168.0.2" }; - final String previousAddresses[] = { "192.168.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" }; - final String networkAddresses[] = { "192.0.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" }; - final String cidrSignatures[] = { "192.168.0.1/8", "192.168.0.1/16", "192.168.0.1/24", "192.168.0.1/29" }; - final int usableAddresses[] = { 16777214, 65534, 254, 6 }; + final String[] masks = { "255.0.0.0", "255.255.0.0", "255.255.255.0", "255.255.255.248" }; + final String[] bcastAddresses = { "192.255.255.255", "192.168.255.255", "192.168.0.255", "192.168.0.7" }; + final String[] lowAddresses = { "192.0.0.1", "192.168.0.1", "192.168.0.1", "192.168.0.1" }; + final String[] highAddresses = { "192.255.255.254", "192.168.255.254", "192.168.0.254", "192.168.0.6" }; + final String[] nextAddresses = { "192.168.0.2", "192.168.0.2", "192.168.0.2", "192.168.0.2" }; + final String[] previousAddresses = { "192.168.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" }; + final String[] networkAddresses = { "192.0.0.0", "192.168.0.0", "192.168.0.0", "192.168.0.0" }; + final String[] cidrSignatures = { "192.168.0.1/8", "192.168.0.1/16", "192.168.0.1/24", "192.168.0.1/29" }; + final int[] usableAddresses = { 16777214, 65534, 254, 6 }; for (int i = 0; i < masks.length; ++i) { final SubnetUtils utils = new SubnetUtils(address, masks[i]); @@ -369,13 +358,13 @@ public void testParseSimpleNetmask() { @Test public void testParseSimpleNetmaskExclusive() { final String address = "192.168.15.7"; - final String masks[] = { "255.255.255.252", "255.255.255.254", "255.255.255.255" }; - final String bcast[] = { "192.168.15.7", "192.168.15.7", "192.168.15.7" }; - final String netwk[] = { "192.168.15.4", "192.168.15.6", "192.168.15.7" }; - final String lowAd[] = { "192.168.15.5", "0.0.0.0", "0.0.0.0" }; - final String highA[] = { "192.168.15.6", "0.0.0.0", "0.0.0.0" }; - final String cidrS[] = { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" }; - final int usableAd[] = { 2, 0, 0 }; + final String[] masks = { "255.255.255.252", "255.255.255.254", "255.255.255.255" }; + final String[] bcast = { "192.168.15.7", "192.168.15.7", "192.168.15.7" }; + final String[] netwk = { "192.168.15.4", "192.168.15.6", "192.168.15.7" }; + final String[] lowAd = { "192.168.15.5", "0.0.0.0", "0.0.0.0" }; + final String[] highA = { "192.168.15.6", "0.0.0.0", "0.0.0.0" }; + final String[] cidrS = { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" }; + final int[] usableAd = { 2, 0, 0 }; // low and high addresses don't exist for (int i = 0; i < masks.length; ++i) { @@ -394,13 +383,13 @@ public void testParseSimpleNetmaskExclusive() { @Test public void testParseSimpleNetmaskInclusive() { final String address = "192.168.15.7"; - final String masks[] = { "255.255.255.252", "255.255.255.254", "255.255.255.255" }; - final String bcast[] = { "192.168.15.7", "192.168.15.7", "192.168.15.7" }; - final String netwk[] = { "192.168.15.4", "192.168.15.6", "192.168.15.7" }; - final String lowAd[] = { "192.168.15.4", "192.168.15.6", "192.168.15.7" }; - final String highA[] = { "192.168.15.7", "192.168.15.7", "192.168.15.7" }; - final String cidrS[] = { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" }; - final int usableAd[] = { 4, 2, 1 }; + final String[] masks = { "255.255.255.252", "255.255.255.254", "255.255.255.255" }; + final String[] bcast = { "192.168.15.7", "192.168.15.7", "192.168.15.7" }; + final String[] netwk = { "192.168.15.4", "192.168.15.6", "192.168.15.7" }; + final String[] lowAd = { "192.168.15.4", "192.168.15.6", "192.168.15.7" }; + final String[] highA = { "192.168.15.7", "192.168.15.7", "192.168.15.7" }; + final String[] cidrS = { "192.168.15.7/30", "192.168.15.7/31", "192.168.15.7/32" }; + final int[] usableAd = { 4, 2, 1 }; for (int i = 0; i < masks.length; ++i) { final SubnetUtils utils = new SubnetUtils(address, masks[i]); diff --git a/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java b/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java index 0ba88105b..b5318190a 100644 --- a/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java +++ b/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.net.ftp; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.text.DateFormatSymbols; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -69,24 +71,9 @@ public void testFTPClientConfigStringStringStringStringStringString() { public void testGetDateFormatSymbols() { - try { - FTPClientConfig.getDateFormatSymbols(badDelim); - fail("bad delimiter"); - } catch (final IllegalArgumentException e) { - // should have failed - } - try { - FTPClientConfig.getDateFormatSymbols(tooLong); - fail("more than 12 months"); - } catch (final IllegalArgumentException e) { - // should have failed - } - try { - FTPClientConfig.getDateFormatSymbols(tooShort); - fail("fewer than 12 months"); - } catch (final IllegalArgumentException e) { - // should have failed - } + assertThrows(IllegalArgumentException.class, () -> FTPClientConfig.getDateFormatSymbols(badDelim), "bad delimiter"); + assertThrows(IllegalArgumentException.class, () -> FTPClientConfig.getDateFormatSymbols(tooLong), "more than 12 months"); + assertThrows(IllegalArgumentException.class, () -> FTPClientConfig.getDateFormatSymbols(tooShort), "fewer than 12 months"); DateFormatSymbols dfs2 = null; try { dfs2 = FTPClientConfig.getDateFormatSymbols(fakeLang); @@ -111,19 +98,8 @@ public void testGetDateFormatSymbols() { assertEquals("different.parser.same.date", d1, d2); - try { - sdf1.parse("hij 31, 2004"); - fail("should.have.failed.to.parse.weird"); - } catch (final ParseException px) { - // expected - } - try { - sdf2.parse("dec 31, 2004"); - fail("should.have.failed.to.parse.standard"); - } catch (final ParseException px) { - // expected - } - + assertThrows(ParseException.class, () -> sdf1.parse("hij 31, 2004")); + assertThrows(ParseException.class, () -> sdf2.parse("dec 31, 2004")); } public void testGetServerLanguageCode() { diff --git a/src/test/java/org/apache/commons/net/ftp/parser/FTPParseTestFramework.java b/src/test/java/org/apache/commons/net/ftp/parser/AbstractFTPParseTest.java similarity index 98% rename from src/test/java/org/apache/commons/net/ftp/parser/FTPParseTestFramework.java rename to src/test/java/org/apache/commons/net/ftp/parser/AbstractFTPParseTest.java index 2fbba3abd..0975ed89f 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/FTPParseTestFramework.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/AbstractFTPParseTest.java @@ -28,7 +28,7 @@ /** */ -public abstract class FTPParseTestFramework extends TestCase { +public abstract class AbstractFTPParseTest extends TestCase { // associate Calendar unit ints with a readable string // MUST be listed least significant first, as the routine needs to // find the previous - less significant - entry @@ -50,7 +50,7 @@ protected enum CalendarUnit { /** * @see junit.framework.TestCase#TestCase(String) */ - public FTPParseTestFramework(final String name) { + public AbstractFTPParseTest(final String name) { super(name); } diff --git a/src/test/java/org/apache/commons/net/ftp/parser/CompositeFTPParseTestFramework.java b/src/test/java/org/apache/commons/net/ftp/parser/CompositeFTPParseTestFramework.java index 59e9723d7..836546a8c 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/CompositeFTPParseTestFramework.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/CompositeFTPParseTestFramework.java @@ -21,7 +21,7 @@ /** */ -public abstract class CompositeFTPParseTestFramework extends FTPParseTestFramework { +public abstract class CompositeFTPParseTestFramework extends AbstractFTPParseTest { public CompositeFTPParseTestFramework(final String name) { super(name); } diff --git a/src/test/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactoryTest.java b/src/test/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactoryTest.java index 60023143a..08c3df148 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactoryTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/DefaultFTPFileEntryParserFactoryTest.java @@ -16,6 +16,8 @@ */ package org.apache.commons.net.ftp.parser; +import static org.junit.jupiter.api.Assertions.assertThrows; + import org.apache.commons.net.ftp.FTPClientConfig; import org.apache.commons.net.ftp.FTPFileEntryParser; @@ -96,8 +98,7 @@ public void testDefaultParserFactory() { factory.createFileEntryParser("org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory"); fail("Exception should have been thrown. \"DefaultFTPFileEntryParserFactory\" does not implement FTPFileEntryParser"); } catch (final ParserInitializationException pie) { - final Throwable root = pie.getCause(); - assertTrue(root instanceof ClassCastException); + assertTrue(pie.getCause() instanceof ClassCastException); } try { @@ -105,28 +106,21 @@ public void testDefaultParserFactory() { factory.createFileEntryParser("org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory"); fail("ParserInitializationException should have been thrown."); } catch (final ParserInitializationException pie) { - final Throwable root = pie.getCause(); - assertTrue(root instanceof InstantiationException); + assertTrue(pie.getCause() instanceof InstantiationException); } try { // Class exists, but is abstract factory.createFileEntryParser("org.apache.commons.net.ftp.FTPFileEntryParserImpl"); fail("ParserInitializationException should have been thrown."); } catch (final ParserInitializationException pie) { - final Throwable root = pie.getCause(); - assertTrue(root instanceof InstantiationException); + assertTrue(pie.getCause() instanceof InstantiationException); } } public void testDefaultParserFactoryConfig() throws Exception { final DefaultFTPFileEntryParserFactory factory = new DefaultFTPFileEntryParserFactory(); - try { - factory.createFileEntryParser((FTPClientConfig) null); - fail("Expected NullPointerException"); - } catch (final NullPointerException npe) { - // expected - } + assertThrows(NullPointerException.class, () -> factory.createFileEntryParser((FTPClientConfig) null)); checkParserClass(factory, null, UnixFTPEntryParser.class); checkParserClass(factory, FTPClientConfig.SYST_OS400, OS400FTPEntryParser.class); diff --git a/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java index 0ab1bdb7e..4028a7482 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/EnterpriseUnixFTPEntryParserTest.java @@ -29,7 +29,7 @@ /** * Tests the EnterpriseUnixFTPEntryParser */ -public class EnterpriseUnixFTPEntryParserTest extends FTPParseTestFramework { +public class EnterpriseUnixFTPEntryParserTest extends AbstractFTPParseTest { private static final String[] BADSAMPLES = { "zrwxr-xr-x 2 root root 4096 Mar 2 15:13 zxbox", "dxrwr-xr-x 2 root root 4096 Aug 24 2001 zxjdbc", "drwxr-xr-x 2 root root 4096 Jam 4 00:03 zziplib", @@ -78,7 +78,7 @@ private void checkPermisions(final FTPFile dir) { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getBadListing() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#getBadListing() */ @Override protected String[] getBadListing() { @@ -86,7 +86,7 @@ protected String[] getBadListing() { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getGoodListing() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#getGoodListing() */ @Override protected String[] getGoodListing() { @@ -94,7 +94,7 @@ protected String[] getGoodListing() { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#getParser() */ @Override protected FTPFileEntryParser getParser() { @@ -107,7 +107,7 @@ public void testDefaultPrecision() { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#testParseFieldsOnDirectory() */ @Override public void testParseFieldsOnDirectory() throws Exception { @@ -115,7 +115,7 @@ public void testParseFieldsOnDirectory() throws Exception { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#testParseFieldsOnFile() */ @Override public void testParseFieldsOnFile() throws Exception { 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 7e3c7538d..541474e4d 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 @@ -16,6 +16,8 @@ */ package org.apache.commons.net.ftp.parser; +import static org.junit.jupiter.api.Assertions.assertThrows; + import java.text.Format; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -151,18 +153,8 @@ public void testFeb29NonLeapYear() { // Note: we use a known leap year for the target date to avoid rounding up final GregorianCalendar input = new GregorianCalendar(2000, Calendar.FEBRUARY, 29); final GregorianCalendar expected = new GregorianCalendar(1999, Calendar.FEBRUARY, 29); - try { - checkShortParse("Feb 29th 1999", server, input, expected, true); - fail("Should have failed to parse Feb 29th 1999"); - } catch (final ParseException pe) { - // expected - } - try { - checkShortParse("Feb 29th 1999", server, input, expected, false); - fail("Should have failed to parse Feb 29th 1999"); - } catch (final ParseException pe) { - // expected - } + assertThrows(ParseException.class, () -> checkShortParse("Feb 29th 1999", server, input, expected, true)); + assertThrows(ParseException.class, () -> checkShortParse("Feb 29th 1999", server, input, expected, false)); } // Lenient mode allows for dates up to 1 day in the future @@ -210,67 +202,30 @@ public void testParseJan01Lenient() throws Exception { checkShortParse("2008-1-1", now, target, true); } - public void testParser() { + public void testParser() throws ParseException { // This test requires an English Locale final Locale locale = Locale.getDefault(); try { Locale.setDefault(Locale.ENGLISH); final FTPTimestampParserImpl parser = new FTPTimestampParserImpl(); - try { - parser.parseTimestamp("feb 22 2002"); - } catch (final ParseException e) { - fail("failed.to.parse.default"); - } - try { - final Calendar c = parser.parseTimestamp("f\u00e9v 22 2002"); - fail("should.have.failed.to.parse.default, but was: " + c.getTime().toString()); - } catch (final ParseException e) { - // this is the success case - } + parser.parseTimestamp("feb 22 2002"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("f\u00e9v 22 2002")); final FTPClientConfig config = new FTPClientConfig(); config.setDefaultDateFormatStr("d MMM yyyy"); config.setRecentDateFormatStr("d MMM HH:mm"); config.setServerLanguageCode("fr"); parser.configure(config); - try { - parser.parseTimestamp("d\u00e9c 22 2002"); - fail("incorrect.field.order"); - } catch (final ParseException e) { - // this is the success case - } + assertThrows(ParseException.class, () -> parser.parseTimestamp("d\u00e9c 22 2002"), "incorrect.field.order"); try { parser.parseTimestamp("22 d\u00e9c 2002"); } catch (final ParseException e) { fail("failed.to.parse.french"); } - - try { - parser.parseTimestamp("22 dec 2002"); - fail("incorrect.language"); - } catch (final ParseException e) { - // this is the success case - } - try { - parser.parseTimestamp("29 f\u00e9v 2002"); - fail("nonexistent.date"); - } catch (final ParseException e) { - // this is the success case - } - - try { - parser.parseTimestamp("22 ao\u00fb 30:02"); - fail("bad.hour"); - } catch (final ParseException e) { - // this is the success case - } - - try { - parser.parseTimestamp("22 ao\u00fb 20:74"); - fail("bad.minute"); - } catch (final ParseException e) { - // this is the success case - } + assertThrows(ParseException.class, () -> parser.parseTimestamp("22 dec 2002"), "incorrect.language"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("29 f\u00e9v 2002"), "nonexistent.date"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("22 ao\u00fb 30:02"), "bad.hour"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("22 ao\u00fb 20:74"), "bad.minute"); try { parser.parseTimestamp("28 ao\u00fb 20:02"); } catch (final ParseException e) { diff --git a/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java index 01c2fe101..3cc807709 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/MLSxEntryParserTest.java @@ -21,7 +21,7 @@ /** */ -public class MLSxEntryParserTest extends FTPParseTestFramework { +public class MLSxEntryParserTest extends AbstractFTPParseTest { private static final String[] badsamples = { "Type=cdir;Modify=20141022065101;UNIX.mode=0775;/no/space", // no space between facts and name "Type=cdir;Modify=20141022065103;UNIX.mode=0775;", // no name or space diff --git a/src/test/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java index 5cd868d72..2772d4200 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/MVSFTPEntryParserTest.java @@ -26,7 +26,7 @@ /** * Test suite addapted to new MVSFTPEntryParser.java. */ -public class MVSFTPEntryParserTest extends FTPParseTestFramework { +public class MVSFTPEntryParserTest extends AbstractFTPParseTest { private static final String[] goodsamplesDatasetList = { /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */ @@ -34,14 +34,22 @@ public class MVSFTPEntryParserTest extends FTPParseTestFramework { "SAVE00 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.RPTBM023.D061704", "SAVE01 3390 2004/06/23 1 1 FB 128 6144 PO INCOMING.RPTBM024.D061704", "SAVE02 3390 2004/06/23 1 1 FB 128 6144 PO-E INCOMING.RPTBM025.D061704", - "PSMLC1 3390 2005/04/04 1 1 VB 27994 27998 PS file3.I", "PSMLB9 3390 2005/04/04 1 1 VB 27994 27998 PS file4.I.BU", - "PSMLB6 3390 2005/04/05 1 1 VB 27994 27998 PS file3.I.BU", "PSMLC6 3390 2005/04/05 1 1 VB 27994 27998 PS file6.I", - "PSMLB7 3390 2005/04/04 1 1 VB 27994 27998 PS file7.O", "PSMLC6 3390 2005/04/05 1 1 VB 27994 27998 PS file7.O.BU", + "PSMLC1 3390 2005/04/04 1 1 VB 27994 27998 PS file3.I", + "PSMLB9 3390 2005/04/04 1 1 VB 27994 27998 PS file4.I.BU", + "PSMLB6 3390 2005/04/05 1 1 VB 27994 27998 PS file3.I.BU", + "PSMLC6 3390 2005/04/05 1 1 VB 27994 27998 PS file6.I", + "PSMLB7 3390 2005/04/04 1 1 VB 27994 27998 PS file7.O", + "PSMLC6 3390 2005/04/05 1 1 VB 27994 27998 PS file7.O.BU", "FPFS49 3390 2004/06/23 1 1 FB 128 6144 PO-E INCOMING.RPTBM026.D061704", "FPFS41 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.RPTBM056.D061704", "FPFS25 3390 2004/06/23 1 1 FB 128 6144 PS INCOMING.WTM204.D061704", "PEX26F 3390 2017/07/03 115807 FB 29600 29600 PS INCOMING.FIN.D170630.T160630", - "VVVVVV 3390 2020/04/18 1 60 U 32760 32760 PO NAME" }; + "VVVVVV 3390 2020/04/18 1 60 U 32760 32760 PO NAME", + "TST017 3390 2023/09/08 2 59 FBA 133 32718 PO NAME", + "TST063 3390 2023/09/11 1 1 VBA 133 27930 PS NAME", + "Migrated NAME", + "ARCIVE Not Direct Access Device NAME" + }; private static final String[] goodsamplesMemberList = { /* Note, if the string begins with SAVE, the parsed entry is stored in the List saveftpfiles */ @@ -110,7 +118,7 @@ protected String[] getGoodListing() { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#getParser() */ @Override protected FTPFileEntryParser getParser() { diff --git a/src/test/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParserTest.java index 6aa6a4d2b..3dd88cd7e 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/MacOsPeterFTPEntryParserTest.java @@ -21,7 +21,7 @@ import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFileEntryParser; -public class MacOsPeterFTPEntryParserTest extends FTPParseTestFramework { +public class MacOsPeterFTPEntryParserTest extends AbstractFTPParseTest { private static final String[] badsamples = { "drwxr-xr-x 123 folder 0 Jan 4 14:49 Steak", }; diff --git a/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java index 5db1de1e7..ebafc2045 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/NTFTPEntryParserTest.java @@ -125,7 +125,7 @@ protected String[][] getGoodListings() { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#getParser() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#getParser() */ @Override protected FTPFileEntryParser getParser() { @@ -202,7 +202,7 @@ private int testNET516(final String charset) throws Exception { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnDirectory() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#testParseFieldsOnDirectory() */ @Override public void testParseFieldsOnDirectory() throws Exception { @@ -222,7 +222,7 @@ public void testParseFieldsOnDirectory() throws Exception { } /** - * @see org.apache.commons.net.ftp.parser.FTPParseTestFramework#testParseFieldsOnFile() + * @see org.apache.commons.net.ftp.parser.AbstractFTPParseTest#testParseFieldsOnFile() */ @Override public void testParseFieldsOnFile() throws Exception { diff --git a/src/test/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java index a41dfc62f..5f1406490 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/NetwareFTPEntryParserTest.java @@ -23,7 +23,7 @@ /** */ -public class NetwareFTPEntryParserTest extends FTPParseTestFramework { +public class NetwareFTPEntryParserTest extends AbstractFTPParseTest { private static final String[] badsamples = { "a [-----F--] SCION_SYS 512 Apr 13 23:52 SYS", "d [----AF--] 0 512 10-04-2001 _ADMIN" }; diff --git a/src/test/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParserTest.java index af3bf2e57..da9d2d63d 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/OS2FTPEntryParserTest.java @@ -19,7 +19,7 @@ import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPFileEntryParser; -public class OS2FTPEntryParserTest extends FTPParseTestFramework { +public class OS2FTPEntryParserTest extends AbstractFTPParseTest { private static final String[] badsamples = { " DIR 12-30-97 12:32 jbrekke", " 0 rsa DIR 11-25-97 09:42 junk", " 0 dir 05-12-97 16:44 LANGUAGE", " 0 DIR 13-05-97 25:49 MPTN", diff --git a/src/test/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParserTest.java index 07f473e23..b67b4f78f 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/OS400FTPEntryParserTest.java @@ -57,7 +57,7 @@ protected void doAdditionalGoodTests(final String test, final FTPFile f) { } /** - * @see FTPParseTestFramework#getBadListing() + * @see AbstractFTPParseTest#getBadListing() */ @Override protected String[][] getBadListings() { @@ -65,7 +65,7 @@ protected String[][] getBadListings() { } /** - * @see FTPParseTestFramework#getGoodListing() + * @see AbstractFTPParseTest#getGoodListing() */ @Override protected String[][] getGoodListings() { @@ -73,7 +73,7 @@ protected String[][] getGoodListings() { } /** - * @see FTPParseTestFramework#getParser() + * @see AbstractFTPParseTest#getParser() */ @Override protected FTPFileEntryParser getParser() { @@ -110,7 +110,7 @@ public void testNET573() { } /** - * @see FTPParseTestFramework#testParseFieldsOnDirectory() + * @see AbstractFTPParseTest#testParseFieldsOnDirectory() */ @Override public void testParseFieldsOnDirectory() throws Exception { @@ -134,7 +134,7 @@ public void testParseFieldsOnDirectory() throws Exception { } /** - * @see FTPParseTestFramework#testParseFieldsOnFile() + * @see AbstractFTPParseTest#testParseFieldsOnFile() */ @Override public void testParseFieldsOnFile() throws Exception { diff --git a/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java index da2884658..2dc1da96e 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/UnixFTPEntryParserTest.java @@ -23,7 +23,7 @@ /** */ -public class UnixFTPEntryParserTest extends FTPParseTestFramework { +public class UnixFTPEntryParserTest extends AbstractFTPParseTest { private static final String[] badsamples = { "zrwxr-xr-x 2 root root 4096 Mar 2 15:13 zxbox", "dxrwr-xr-x 2 root root 4096 Aug 24 2001 zxjdbc", "drwxr-xr-x 2 root root 4096 Jam 4 00:03 zziplib", diff --git a/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java b/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java index e3afde28d..29be8edcd 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/VMSFTPEntryParserTest.java @@ -25,7 +25,7 @@ /** */ -public class VMSFTPEntryParserTest extends FTPParseTestFramework { +public class VMSFTPEntryParserTest extends AbstractFTPParseTest { private static final String[] BAD_SAMPLES = { "1-JUN.LIS;2 9/9 JUN-2-1998 07:32:04 [GROUP,OWNER] (RWED,RWED,RWED,)", diff --git a/src/test/java/org/apache/commons/net/telnet/TelnetOptionHandlerTestAbstract.java b/src/test/java/org/apache/commons/net/telnet/AbstractTelnetOptionHandlerTest.java similarity index 98% rename from src/test/java/org/apache/commons/net/telnet/TelnetOptionHandlerTestAbstract.java rename to src/test/java/org/apache/commons/net/telnet/AbstractTelnetOptionHandlerTest.java index 272e26981..d7942b49f 100644 --- a/src/test/java/org/apache/commons/net/telnet/TelnetOptionHandlerTestAbstract.java +++ b/src/test/java/org/apache/commons/net/telnet/AbstractTelnetOptionHandlerTest.java @@ -22,7 +22,7 @@ * The TelnetOptionHandlerTest is the abstract class for testing TelnetOptionHandler. It can be used to derive the actual test classes for TelnetOptionHadler * derived classes, by adding creation of three new option handlers and testing of the specific subnegotiation behavior. */ -public abstract class TelnetOptionHandlerTestAbstract extends TestCase { +public abstract class AbstractTelnetOptionHandlerTest extends TestCase { TelnetOptionHandler opthand1; TelnetOptionHandler opthand2; TelnetOptionHandler opthand3; diff --git a/src/test/java/org/apache/commons/net/telnet/EchoOptionHandlerTest.java b/src/test/java/org/apache/commons/net/telnet/EchoOptionHandlerTest.java index be9b3680e..f547b2712 100644 --- a/src/test/java/org/apache/commons/net/telnet/EchoOptionHandlerTest.java +++ b/src/test/java/org/apache/commons/net/telnet/EchoOptionHandlerTest.java @@ -19,7 +19,7 @@ /** * JUnit test class for EchoOptionHandler */ -public class EchoOptionHandlerTest extends TelnetOptionHandlerTestAbstract { +public class EchoOptionHandlerTest extends AbstractTelnetOptionHandlerTest { /** * setUp for the test. @@ -36,9 +36,9 @@ protected void setUp() { */ @Override public void testAnswerSubnegotiation() { - final int subn[] = { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.ECHO, 1, TelnetCommand.IAC, TelnetCommand.SE, }; + final int[] subn = { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.ECHO, 1, TelnetCommand.IAC, TelnetCommand.SE, }; - final int resp1[] = opthand1.answerSubnegotiation(subn, subn.length); + final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); assertNull(resp1); } @@ -57,8 +57,8 @@ public void testConstructors() { */ @Override public void testStartSubnegotiation() { - final int resp1[] = opthand1.startSubnegotiationLocal(); - final int resp2[] = opthand1.startSubnegotiationRemote(); + final int[] resp1 = opthand1.startSubnegotiationLocal(); + final int[] resp2 = opthand1.startSubnegotiationRemote(); assertNull(resp1); assertNull(resp2); diff --git a/src/test/java/org/apache/commons/net/telnet/SimpleOptionHandlerTest.java b/src/test/java/org/apache/commons/net/telnet/SimpleOptionHandlerTest.java index a559f4729..74d62a96f 100644 --- a/src/test/java/org/apache/commons/net/telnet/SimpleOptionHandlerTest.java +++ b/src/test/java/org/apache/commons/net/telnet/SimpleOptionHandlerTest.java @@ -19,7 +19,7 @@ /** * JUnit test class for SimpleOptionHandler */ -public class SimpleOptionHandlerTest extends TelnetOptionHandlerTestAbstract { +public class SimpleOptionHandlerTest extends AbstractTelnetOptionHandlerTest { /** * setUp for the test. */ @@ -35,9 +35,9 @@ protected void setUp() { */ @Override public void testAnswerSubnegotiation() { - final int subn[] = { TelnetCommand.IAC, TelnetCommand.SB, 4, 1, TelnetCommand.IAC, TelnetCommand.SE, }; + final int[] subn = { TelnetCommand.IAC, TelnetCommand.SB, 4, 1, TelnetCommand.IAC, TelnetCommand.SE, }; - final int resp1[] = opthand1.answerSubnegotiation(subn, subn.length); + final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); assertNull(resp1); } @@ -59,8 +59,8 @@ public void testConstructors() { @Override public void testStartSubnegotiation() { - final int resp1[] = opthand1.startSubnegotiationLocal(); - final int resp2[] = opthand1.startSubnegotiationRemote(); + final int[] resp1 = opthand1.startSubnegotiationLocal(); + final int[] resp2 = opthand1.startSubnegotiationRemote(); assertNull(resp1); assertNull(resp2); diff --git a/src/test/java/org/apache/commons/net/telnet/SuppressGAOptionHandlerTest.java b/src/test/java/org/apache/commons/net/telnet/SuppressGAOptionHandlerTest.java index f1b8e7276..73c94025b 100644 --- a/src/test/java/org/apache/commons/net/telnet/SuppressGAOptionHandlerTest.java +++ b/src/test/java/org/apache/commons/net/telnet/SuppressGAOptionHandlerTest.java @@ -19,7 +19,7 @@ /** * JUnit test class for SuppressGAOptionHandler */ -public class SuppressGAOptionHandlerTest extends TelnetOptionHandlerTestAbstract { +public class SuppressGAOptionHandlerTest extends AbstractTelnetOptionHandlerTest { /** * setUp for the test. @@ -36,9 +36,9 @@ protected void setUp() { */ @Override public void testAnswerSubnegotiation() { - final int subn[] = { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.SUPPRESS_GO_AHEAD, 1, TelnetCommand.IAC, TelnetCommand.SE, }; + final int[] subn = { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.SUPPRESS_GO_AHEAD, 1, TelnetCommand.IAC, TelnetCommand.SE, }; - final int resp1[] = opthand1.answerSubnegotiation(subn, subn.length); + final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); assertNull(resp1); } @@ -58,8 +58,8 @@ public void testConstructors() { @Override public void testStartSubnegotiation() { - final int resp1[] = opthand1.startSubnegotiationLocal(); - final int resp2[] = opthand1.startSubnegotiationRemote(); + final int[] resp1 = opthand1.startSubnegotiationLocal(); + final int[] resp2 = opthand1.startSubnegotiationRemote(); assertNull(resp1); assertNull(resp2); diff --git a/src/test/java/org/apache/commons/net/telnet/TelnetClientFunctionalTest.java b/src/test/java/org/apache/commons/net/telnet/TelnetClientFunctionalTest.java index a759391c7..a41a99dd9 100644 --- a/src/test/java/org/apache/commons/net/telnet/TelnetClientFunctionalTest.java +++ b/src/test/java/org/apache/commons/net/telnet/TelnetClientFunctionalTest.java @@ -73,11 +73,11 @@ public void testFunctionalTest() throws Exception { * Helper method. waits for a string with timeout */ public boolean waitForString(final InputStream is, final String end, final long timeout) throws Exception { - final byte buffer[] = new byte[32]; + final byte[] buffer = new byte[32]; final long starttime = System.currentTimeMillis(); String readbytes = ""; - while ((readbytes.indexOf(end) < 0) && ((System.currentTimeMillis() - starttime) < timeout)) { + while (readbytes.indexOf(end) < 0 && System.currentTimeMillis() - starttime < timeout) { if (is.available() > 0) { final int ret_read = is.read(buffer); readbytes = readbytes + new String(buffer, 0, ret_read); @@ -86,9 +86,6 @@ public boolean waitForString(final InputStream is, final String end, final long } } - if (readbytes.indexOf(end) >= 0) { - return (true); - } - return (false); + return readbytes.indexOf(end) >= 0; } } \ No newline at end of file diff --git a/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java b/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java index 3daa56dd8..a95e21956 100644 --- a/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java +++ b/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java @@ -223,10 +223,10 @@ public void testAYT() throws Exception { boolean ayt_true_ok = false; boolean ayt_false_ok = false; - final byte AYT[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.AYT }; - final byte response[] = { (byte) '[', (byte) 'Y', (byte) 'e', (byte) 's', (byte) ']' }; - final String inputs[] = new String[1]; - final String outputs[] = new String[1]; + final byte[] AYT = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.AYT }; + final byte[] response = { (byte) '[', (byte) 'Y', (byte) 'e', (byte) 's', (byte) ']' }; + final String[] inputs = new String[1]; + final String[] outputs = new String[1]; inputs[0] = new String(AYT); outputs[0] = new String(response); @@ -261,11 +261,11 @@ public void testDeleteOptionHandler() throws Exception { boolean remove_invalid_ok1 = false; boolean remove_invalid_ok2 = false; - final byte buffread[] = new byte[6]; - final byte send[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, + final byte[] buffread = new byte[6]; + final byte[] send = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte expected[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, + final byte[] expected = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; final InputStream is = OPTIONS.server.getInputStream(); @@ -316,8 +316,8 @@ public void testInitial() throws Exception { boolean init2_ok = false; boolean add_invalid_ok1 = false; boolean add_invalid_ok2 = false; - final byte buffread2[] = new byte[9]; - final byte expected2[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, + final byte[] buffread2 = new byte[9]; + final byte[] expected2 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.SUPPRESS_GO_AHEAD, }; @@ -375,7 +375,7 @@ public void testInitial() throws Exception { * test of max subnegotiation length */ public void testMaxSubnegotiationLength() throws Exception { - final byte send[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) 99, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6, + final byte[] send = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) 99, (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6, (byte) 7, (byte) 8, (byte) 9, (byte) 10, (byte) 11, (byte) 12, (byte) 13, (byte) 14, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.SE, }; @@ -418,15 +418,15 @@ public void testMaxSubnegotiationLength() throws Exception { * test of option negotiation notification */ public void testNotification() throws Exception { - final byte buffread1[] = new byte[6]; - final byte send1[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) 15, }; + final byte[] buffread1 = new byte[6]; + final byte[] send1 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) 15, }; - final byte buffread2[] = new byte[9]; - final byte send2[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, + final byte[] buffread2 = new byte[9]; + final byte[] send2 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte buffread2b[] = new byte[11]; + final byte[] buffread2b = new byte[11]; numdo = 0; numdont = 0; @@ -470,36 +470,36 @@ public void testNotification() throws Exception { */ public void testOptionNegotiation() throws Exception { boolean negotiation1_ok = false; - final byte buffread1[] = new byte[6]; - final byte send1[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) 15, }; - final byte expected1[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, + final byte[] buffread1 = new byte[6]; + final byte[] send1 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) 15, }; + final byte[] expected1 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) 15, }; boolean negotiation2_ok = false; - final byte buffread2[] = new byte[9]; - final byte send2[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, + final byte[] buffread2 = new byte[9]; + final byte[] send2 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte expected2[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, + final byte[] expected2 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte buffread2b[] = new byte[11]; - final byte send2b[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 1, (byte) TelnetCommand.IAC, + final byte[] buffread2b = new byte[11]; + final byte[] send2b = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 1, (byte) TelnetCommand.IAC, (byte) TelnetCommand.SE, }; - final byte expected2b[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 0, (byte) 'V', (byte) 'T', + final byte[] expected2b = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 0, (byte) 'V', (byte) 'T', (byte) '1', (byte) '0', (byte) '0', (byte) TelnetCommand.IAC, (byte) TelnetCommand.SE, }; boolean negotiation3_ok = false; - final byte buffread3[] = new byte[6]; - final byte send3[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, + final byte[] buffread3 = new byte[6]; + final byte[] send3 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte expected3[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, + final byte[] expected3 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) TelnetOption.TERMINAL_TYPE, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte buffread3b[] = new byte[10]; - final byte send3b[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 1, (byte) TelnetCommand.IAC, + final byte[] buffread3b = new byte[10]; + final byte[] send3b = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 1, (byte) TelnetCommand.IAC, (byte) TelnetCommand.SE, }; - final byte expected3b[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 0, (byte) 'A', (byte) 'N', + final byte[] expected3b = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.SB, (byte) TelnetOption.TERMINAL_TYPE, (byte) 0, (byte) 'A', (byte) 'N', (byte) 'S', (byte) 'I', (byte) TelnetCommand.IAC, (byte) TelnetCommand.SE, }; final InputStream is1 = STANDARD.server.getInputStream(); @@ -594,15 +594,15 @@ public void testOptionNegotiation() throws Exception { public void testOptionRenegotiation() throws Exception { boolean negotiation1_ok = false; - final byte buffread[] = new byte[6]; - final byte send[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, + final byte[] buffread = new byte[6]; + final byte[] send = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) TelnetOption.ECHO, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte expected[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, + final byte[] expected = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.SUPPRESS_GO_AHEAD }; - final byte buffread2[] = new byte[3]; - final byte send2[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.ECHO, }; - final byte expected2[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.ECHO, }; + final byte[] buffread2 = new byte[3]; + final byte[] send2 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) TelnetOption.ECHO, }; + final byte[] expected2 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) TelnetOption.ECHO, }; final InputStream is = OPTIONS.server.getInputStream(); final OutputStream os = OPTIONS.server.getOutputStream(); @@ -643,9 +643,9 @@ public void testSetReaderThread() throws Exception { boolean negotiation1_ok = false; boolean negotiation2_ok = false; boolean read_ok = false; - final byte buffread1[] = new byte[6]; - final byte send1[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) 15, }; - final byte expected1[] = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, + final byte[] buffread1 = new byte[6]; + final byte[] send1 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.DO, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.WILL, (byte) 15, }; + final byte[] expected1 = { (byte) TelnetCommand.IAC, (byte) TelnetCommand.WONT, (byte) 15, (byte) TelnetCommand.IAC, (byte) TelnetCommand.DONT, (byte) 15, }; final InputStream is1 = NOREAD.server.getInputStream(); @@ -664,7 +664,7 @@ public void testSetReaderThread() throws Exception { read_ok = true; } - // if(is1.available() == 6) + // if (is1.available() == 6) // { int read = 0; int pos = 0; @@ -695,7 +695,7 @@ public void testSetReaderThread() throws Exception { System.arraycopy(tmp, 0, buffread1, pos, read); pos += read; } - // if(is2.available() == 6) + // if (is2.available() == 6) // { is2.read(buffread1); @@ -718,8 +718,8 @@ public void testSpy() throws Exception { boolean test1spy_ok = false; boolean test2spy_ok = false; boolean stopspy_ok = false; - final byte expected1[] = { (byte) 't', (byte) 'e', (byte) 's', (byte) 't', (byte) '1' }; - final byte expected2[] = { (byte) 't', (byte) 'e', (byte) 's', (byte) 't', (byte) '2' }; + final byte[] expected1 = { (byte) 't', (byte) 'e', (byte) 's', (byte) 't', (byte) '1' }; + final byte[] expected2 = { (byte) 't', (byte) 'e', (byte) 's', (byte) 't', (byte) '2' }; try (final PipedOutputStream po = new PipedOutputStream(); final PipedInputStream pi = new PipedInputStream(po)) { @@ -732,7 +732,7 @@ public void testSpy() throws Exception { os.flush(); Thread.sleep(1000); - final byte buffer[] = new byte[5]; + final byte[] buffer = new byte[5]; if (pi.available() == 5) { pi.read(buffer); diff --git a/src/test/java/org/apache/commons/net/telnet/TelnetTestResponder.java b/src/test/java/org/apache/commons/net/telnet/TelnetTestResponder.java index 5910fb1f0..79f8cb8d3 100644 --- a/src/test/java/org/apache/commons/net/telnet/TelnetTestResponder.java +++ b/src/test/java/org/apache/commons/net/telnet/TelnetTestResponder.java @@ -56,7 +56,7 @@ public TelnetTestResponder(final InputStream is, final OutputStream os, final St @Override public void run() { boolean result = false; - final byte buffer[] = new byte[32]; + final byte[] buffer = new byte[32]; final long starttime = System.currentTimeMillis(); try { diff --git a/src/test/java/org/apache/commons/net/telnet/TerminalTypeOptionHandlerTest.java b/src/test/java/org/apache/commons/net/telnet/TerminalTypeOptionHandlerTest.java index 7859e48da..e8de47149 100644 --- a/src/test/java/org/apache/commons/net/telnet/TerminalTypeOptionHandlerTest.java +++ b/src/test/java/org/apache/commons/net/telnet/TerminalTypeOptionHandlerTest.java @@ -16,7 +16,7 @@ */ package org.apache.commons.net.telnet; -public class TerminalTypeOptionHandlerTest extends TelnetOptionHandlerTestAbstract { +public class TerminalTypeOptionHandlerTest extends AbstractTelnetOptionHandlerTest { /* * compares two arrays of int */ @@ -45,14 +45,14 @@ protected void setUp() { */ @Override public void testAnswerSubnegotiation() { - final int subn[] = { TelnetOption.TERMINAL_TYPE, 1 }; + final int[] subn = { TelnetOption.TERMINAL_TYPE, 1 }; - final int expected1[] = { TelnetOption.TERMINAL_TYPE, 0, 'V', 'T', '1', '0', '0' }; + final int[] expected1 = { TelnetOption.TERMINAL_TYPE, 0, 'V', 'T', '1', '0', '0' }; - final int expected2[] = { TelnetOption.TERMINAL_TYPE, 0, 'A', 'N', 'S', 'I' }; + final int[] expected2 = { TelnetOption.TERMINAL_TYPE, 0, 'A', 'N', 'S', 'I' }; - final int resp1[] = opthand1.answerSubnegotiation(subn, subn.length); - final int resp2[] = opthand2.answerSubnegotiation(subn, subn.length); + final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); + final int[] resp2 = opthand2.answerSubnegotiation(subn, subn.length); assertTrue(equalInts(resp1, expected1)); assertTrue(equalInts(resp2, expected2)); @@ -70,8 +70,8 @@ public void testConstructors() { @Override public void testStartSubnegotiation() { - final int resp1[] = opthand1.startSubnegotiationLocal(); - final int resp2[] = opthand1.startSubnegotiationRemote(); + final int[] resp1 = opthand1.startSubnegotiationLocal(); + final int[] resp2 = opthand1.startSubnegotiationRemote(); assertNull(resp1); assertNull(resp2); diff --git a/src/test/java/org/apache/commons/net/telnet/WindowSizeOptionHandlerTest.java b/src/test/java/org/apache/commons/net/telnet/WindowSizeOptionHandlerTest.java index 8fe0c7167..c94924319 100644 --- a/src/test/java/org/apache/commons/net/telnet/WindowSizeOptionHandlerTest.java +++ b/src/test/java/org/apache/commons/net/telnet/WindowSizeOptionHandlerTest.java @@ -19,7 +19,7 @@ /** * JUnit test class for TerminalTypeOptionHandler */ -public class WindowSizeOptionHandlerTest extends TelnetOptionHandlerTestAbstract { +public class WindowSizeOptionHandlerTest extends AbstractTelnetOptionHandlerTest { /** * compares two arrays of int */ @@ -45,11 +45,11 @@ protected void setUp() { */ @Override public void testAnswerSubnegotiation() { - final int subn[] = { TelnetOption.WINDOW_SIZE, 24, 80 }; + final int[] subn = { TelnetOption.WINDOW_SIZE, 24, 80 }; - final int resp1[] = opthand1.answerSubnegotiation(subn, subn.length); - final int resp2[] = opthand2.answerSubnegotiation(subn, subn.length); - final int resp3[] = opthand3.answerSubnegotiation(subn, subn.length); + final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); + final int[] resp2 = opthand2.answerSubnegotiation(subn, subn.length); + final int[] resp3 = opthand3.answerSubnegotiation(subn, subn.length); assertNull(resp1); assertNull(resp2); diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java index bfa642e73..ffd26d72d 100644 --- a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java +++ b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java @@ -523,7 +523,7 @@ public TFTPServer(final File serverReadDirectory, final File serverWriteDirector InetAddress inetAddress = null; if (localiface != null) { final Enumeration ifaddrs = localiface.getInetAddresses(); - if ((ifaddrs != null) && ifaddrs.hasMoreElements()) { + if (ifaddrs != null && ifaddrs.hasMoreElements()) { inetAddress = ifaddrs.nextElement(); } } diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPTest.java b/src/test/java/org/apache/commons/net/tftp/TFTPTest.java index 36c17f807..63f8f0a11 100644 --- a/src/test/java/org/apache/commons/net/tftp/TFTPTest.java +++ b/src/test/java/org/apache/commons/net/tftp/TFTPTest.java @@ -76,33 +76,8 @@ private static File createFile(final File file, final int size) throws IOExcepti return file; } - private boolean filesIdentical(final File a, final File b) throws IOException { - if (!a.exists() || !b.exists()) { - return false; - } - - if (a.length() != b.length()) { - return false; - } - - try (final InputStream fisA = new BufferedInputStream(new FileInputStream(a)); - final InputStream fisB = new BufferedInputStream(new FileInputStream(b))) { - - int aBit = fisA.read(); - int bBit = fisB.read(); - - while (aBit != -1) { - if (aBit != bBit) { - fisA.close(); - fisB.close(); - return false; - } - aBit = fisA.read(); - bBit = fisB.read(); - } - - } - return true; + private boolean contentEquals(final File a, final File b) throws IOException { + return FileUtils.contentEquals(a, b); } @Override @@ -155,7 +130,7 @@ private void testDownload(final int mode, final File file) throws IOException { } assertTrue("file not created", out.exists()); - assertTrue("FILES not identical on file " + file, filesIdentical(out, file)); + assertTrue("FILES not identical on file " + file, contentEquals(out, file)); // delete the downloaded file out.delete(); @@ -208,7 +183,7 @@ private void testUpload(final int mode, final File file) throws Exception { // close out its file buffers, etc. Thread.sleep(100); assertTrue("file not created", in.exists()); - assertTrue("FILES not identical on file " + file, filesIdentical(file, in)); + assertTrue("FILES not identical on file " + file, contentEquals(file, in)); in.delete(); } diff --git a/src/test/java/org/apache/commons/net/util/Base64Test.java b/src/test/java/org/apache/commons/net/util/Base64Test.java index 984af904a..576fe00f5 100644 --- a/src/test/java/org/apache/commons/net/util/Base64Test.java +++ b/src/test/java/org/apache/commons/net/util/Base64Test.java @@ -157,24 +157,14 @@ public void testEncodeBase64ByteArrayBooleanBooleanInt() { encoded = Base64.encodeBase64(binaryData, false, false); assertNotNull(encoded); assertEquals(4, encoded.length); - try { - Base64.encodeBase64(binaryData, false, false, 3); - fail("Expected IllegalArgumentException"); - } catch (final IllegalArgumentException expected) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> Base64.encodeBase64(binaryData, false, false, 3)); encoded = Base64.encodeBase64(binaryData, false, false, 4); // NET-483 assertNotNull(encoded); assertEquals(4, encoded.length); encoded = Base64.encodeBase64(binaryData, true, false); assertNotNull(encoded); assertEquals(6, encoded.length); // always adds trailer - try { - Base64.encodeBase64(binaryData, true, false, 5); - fail("Expected IllegalArgumentException"); - } catch (final IllegalArgumentException expected) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> Base64.encodeBase64(binaryData, true, false, 5)); encoded = Base64.encodeBase64(binaryData, true, false, 6); assertNotNull(encoded); assertEquals(6, encoded.length);