├── .asf.yaml ├── .gitattributes ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── codeql-analysis.yml │ ├── dependency-review.yml │ ├── maven.yml │ ├── maven_adhoc.yml │ └── scorecards-analysis.yml ├── .gitignore ├── BUILDING.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE-NOTES.txt ├── SECURITY.md ├── pom.xml └── src ├── assembly ├── bin.xml └── src.xml ├── changes ├── changes.xml └── release-notes.vm ├── conf ├── checkstyle-suppressions.xml ├── checkstyle.xml ├── findbugs-exclude-filter.xml └── pmd-ruleset.xml ├── main ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── net │ │ ├── DatagramSocketClient.java │ │ ├── DatagramSocketFactory.java │ │ ├── DefaultDatagramSocketFactory.java │ │ ├── DefaultSocketFactory.java │ │ ├── MalformedServerReplyException.java │ │ ├── PrintCommandListener.java │ │ ├── ProtocolCommandEvent.java │ │ ├── ProtocolCommandListener.java │ │ ├── ProtocolCommandSupport.java │ │ ├── SocketClient.java │ │ ├── bsd │ │ ├── RCommandClient.java │ │ ├── RExecClient.java │ │ ├── RLoginClient.java │ │ └── package-info.java │ │ ├── chargen │ │ ├── CharGenTCPClient.java │ │ ├── CharGenUDPClient.java │ │ └── package-info.java │ │ ├── daytime │ │ ├── DaytimeTCPClient.java │ │ ├── DaytimeUDPClient.java │ │ └── package-info.java │ │ ├── discard │ │ ├── DiscardTCPClient.java │ │ ├── DiscardUDPClient.java │ │ └── package-info.java │ │ ├── echo │ │ ├── EchoTCPClient.java │ │ ├── EchoUDPClient.java │ │ └── package-info.java │ │ ├── examples │ │ ├── Main.java │ │ ├── PrintCommandListeners.java │ │ ├── cidr │ │ │ └── SubnetUtilsExample.java │ │ ├── ftp │ │ │ ├── FTPClientExample.java │ │ │ ├── ServerToServerFTP.java │ │ │ └── TFTPExample.java │ │ ├── mail │ │ │ ├── IMAPExportMbox.java │ │ │ ├── IMAPImportMbox.java │ │ │ ├── IMAPMail.java │ │ │ ├── IMAPUtils.java │ │ │ ├── POP3ExportMbox.java │ │ │ ├── POP3Mail.java │ │ │ ├── SMTPMail.java │ │ │ └── Utils.java │ │ ├── nntp │ │ │ ├── ArticleReader.java │ │ │ ├── ExtendedNNTPOps.java │ │ │ ├── ListNewsgroups.java │ │ │ ├── MessageThreading.java │ │ │ ├── NNTPUtils.java │ │ │ └── PostMessage.java │ │ ├── ntp │ │ │ ├── NTPClient.java │ │ │ ├── SimpleNTPServer.java │ │ │ └── TimeClient.java │ │ ├── package-info.java │ │ ├── telnet │ │ │ ├── TelnetClientExample.java │ │ │ └── WeatherTelnet.java │ │ ├── unix │ │ │ ├── chargen.java │ │ │ ├── daytime.java │ │ │ ├── echo.java │ │ │ ├── finger.java │ │ │ ├── fwhois.java │ │ │ ├── rdate.java │ │ │ ├── rexec.java │ │ │ ├── rlogin.java │ │ │ └── rshell.java │ │ └── util │ │ │ └── IOUtil.java │ │ ├── finger │ │ ├── FingerClient.java │ │ └── package-info.java │ │ ├── ftp │ │ ├── Configurable.java │ │ ├── DeflateSocket.java │ │ ├── DelegateSocket.java │ │ ├── DurationUtils.java │ │ ├── FTP.java │ │ ├── FTPClient.java │ │ ├── FTPClientConfig.java │ │ ├── FTPCmd.java │ │ ├── FTPCommand.java │ │ ├── FTPConnectionClosedException.java │ │ ├── FTPFile.java │ │ ├── FTPFileEntryParser.java │ │ ├── FTPFileEntryParserImpl.java │ │ ├── FTPFileFilter.java │ │ ├── FTPFileFilters.java │ │ ├── FTPHTTPClient.java │ │ ├── FTPListParseEngine.java │ │ ├── FTPReply.java │ │ ├── FTPSClient.java │ │ ├── FTPSCommand.java │ │ ├── FTPSServerSocketFactory.java │ │ ├── FTPSSocketFactory.java │ │ ├── FTPSTrustManager.java │ │ ├── package-info.java │ │ └── parser │ │ │ ├── CompositeFileEntryParser.java │ │ │ ├── ConfigurableFTPFileEntryParserImpl.java │ │ │ ├── DefaultFTPFileEntryParserFactory.java │ │ │ ├── EnterpriseUnixFTPEntryParser.java │ │ │ ├── FTPFileEntryParserFactory.java │ │ │ ├── FTPTimestampParser.java │ │ │ ├── FTPTimestampParserImpl.java │ │ │ ├── MLSxEntryParser.java │ │ │ ├── MVSFTPEntryParser.java │ │ │ ├── MacOsPeterFTPEntryParser.java │ │ │ ├── NTFTPEntryParser.java │ │ │ ├── NetwareFTPEntryParser.java │ │ │ ├── OS2FTPEntryParser.java │ │ │ ├── OS400FTPEntryParser.java │ │ │ ├── ParserInitializationException.java │ │ │ ├── RegexFTPFileEntryParserImpl.java │ │ │ ├── UnixFTPEntryParser.java │ │ │ ├── VMSFTPEntryParser.java │ │ │ ├── VMSVersioningFTPEntryParser.java │ │ │ └── package-info.java │ │ ├── imap │ │ ├── AuthenticatingIMAPClient.java │ │ ├── IMAP.java │ │ ├── IMAPClient.java │ │ ├── IMAPCommand.java │ │ ├── IMAPReply.java │ │ ├── IMAPSClient.java │ │ └── package-info.java │ │ ├── io │ │ ├── CRLFLineReader.java │ │ ├── CopyStreamAdapter.java │ │ ├── CopyStreamEvent.java │ │ ├── CopyStreamException.java │ │ ├── CopyStreamListener.java │ │ ├── DotTerminatedMessageReader.java │ │ ├── DotTerminatedMessageWriter.java │ │ ├── FromNetASCIIInputStream.java │ │ ├── FromNetASCIIOutputStream.java │ │ ├── SocketInputStream.java │ │ ├── SocketOutputStream.java │ │ ├── ToNetASCIIInputStream.java │ │ ├── ToNetASCIIOutputStream.java │ │ ├── Util.java │ │ └── package-info.java │ │ ├── nntp │ │ ├── Article.java │ │ ├── ArticleInfo.java │ │ ├── ArticleIterator.java │ │ ├── ArticlePointer.java │ │ ├── NNTP.java │ │ ├── NNTPClient.java │ │ ├── NNTPCommand.java │ │ ├── NNTPConnectionClosedException.java │ │ ├── NNTPReply.java │ │ ├── NewGroupsOrNewsQuery.java │ │ ├── NewsgroupInfo.java │ │ ├── NewsgroupIterator.java │ │ ├── NntpThreadContainer.java │ │ ├── ReplyIterator.java │ │ ├── SimpleNNTPHeader.java │ │ ├── Threadable.java │ │ ├── Threader.java │ │ └── package-info.java │ │ ├── ntp │ │ ├── NTPUDPClient.java │ │ ├── NtpUtils.java │ │ ├── NtpV3Impl.java │ │ ├── NtpV3Packet.java │ │ ├── TimeInfo.java │ │ ├── TimeStamp.java │ │ └── package-info.java │ │ ├── package-info.java │ │ ├── pop3 │ │ ├── ExtendedPOP3Client.java │ │ ├── POP3.java │ │ ├── POP3Client.java │ │ ├── POP3Command.java │ │ ├── POP3MessageInfo.java │ │ ├── POP3Reply.java │ │ ├── POP3SClient.java │ │ └── package-info.java │ │ ├── smtp │ │ ├── AuthenticatingSMTPClient.java │ │ ├── RelayPath.java │ │ ├── SMTP.java │ │ ├── SMTPClient.java │ │ ├── SMTPCommand.java │ │ ├── SMTPConnectionClosedException.java │ │ ├── SMTPReply.java │ │ ├── SMTPSClient.java │ │ ├── SimpleSMTPHeader.java │ │ └── package-info.java │ │ ├── telnet │ │ ├── EchoOptionHandler.java │ │ ├── InvalidTelnetOptionException.java │ │ ├── SimpleOptionHandler.java │ │ ├── SuppressGAOptionHandler.java │ │ ├── Telnet.java │ │ ├── TelnetClient.java │ │ ├── TelnetCommand.java │ │ ├── TelnetInputListener.java │ │ ├── TelnetInputStream.java │ │ ├── TelnetNotificationHandler.java │ │ ├── TelnetOption.java │ │ ├── TelnetOptionHandler.java │ │ ├── TelnetOutputStream.java │ │ ├── TerminalTypeOptionHandler.java │ │ ├── WindowSizeOptionHandler.java │ │ └── package-info.java │ │ ├── tftp │ │ ├── TFTP.java │ │ ├── TFTPAckPacket.java │ │ ├── TFTPClient.java │ │ ├── TFTPDataPacket.java │ │ ├── TFTPErrorPacket.java │ │ ├── TFTPPacket.java │ │ ├── TFTPPacketException.java │ │ ├── TFTPReadRequestPacket.java │ │ ├── TFTPRequestPacket.java │ │ ├── TFTPWriteRequestPacket.java │ │ └── package-info.java │ │ ├── time │ │ ├── TimeTCPClient.java │ │ ├── TimeUDPClient.java │ │ └── package-info.java │ │ ├── util │ │ ├── Base64.java │ │ ├── Charsets.java │ │ ├── KeyManagerUtils.java │ │ ├── ListenerList.java │ │ ├── NetConstants.java │ │ ├── SSLContextUtils.java │ │ ├── SSLSocketUtils.java │ │ ├── SubnetUtils.java │ │ ├── TrustManagerUtils.java │ │ └── package-info.java │ │ └── whois │ │ ├── WhoisClient.java │ │ └── package-info.java └── resources │ └── org │ └── apache │ └── commons │ └── net │ └── examples │ └── examples.properties ├── media └── net-logo-white.xcf ├── site ├── custom │ └── project-info-report.properties ├── resources │ ├── download_net.cgi │ └── images │ │ └── net-logo-white.png ├── site.xml └── xdoc │ ├── code-standards.xml │ ├── download_net.xml │ ├── faq.xml │ ├── index.xml │ ├── issue-tracking.xml │ ├── mail-lists.xml │ ├── migration.xml │ ├── security.xml │ └── tasks.xml └── test ├── java └── org │ └── apache │ └── commons │ └── net │ ├── MockTcpServer.java │ ├── SocketClientFunctionalTest.java │ ├── SocketClientTest.java │ ├── bsd │ ├── RCommandClientTest.java │ ├── RExecClientTest.java │ └── RLoginClientTest.java │ ├── chargen │ ├── CharGenTCPClientTest.java │ └── CharGenUDPClientTest.java │ ├── daytime │ ├── DaytimeTCPClientTest.java │ ├── DaytimeUDPClientTest.java │ └── MockDaytimeTCPServer.java │ ├── discard │ ├── DiscardTCPClientTest.java │ └── DiscardUDPClientTest.java │ ├── echo │ ├── EchoTCPClientTest.java │ └── EchoUDPClientTest.java │ ├── examples │ └── MainTest.java │ ├── finger │ └── FingerClientTest.java │ ├── ftp │ ├── AbstractFtpsTest.java │ ├── FTPClientConfigFunctionalTest.java │ ├── FTPClientConfigTest.java │ ├── FTPClientTest.java │ ├── FTPClientTransferModeTest.java │ ├── FTPCommandTest.java │ ├── FTPFileTest.java │ ├── FTPSClientGettersTest.java │ ├── FTPSClientTest.java │ ├── GZIPSocket.java │ ├── ListingFunctionalTest.java │ ├── NoProtocolSslConfigurationProxy.java │ ├── TestConnectTimeout.java │ └── parser │ │ ├── AbstractFTPParseTest.java │ │ ├── CompositeFTPParseTestFramework.java │ │ ├── DefaultFTPFileEntryParserFactoryTest.java │ │ ├── DownloadListings.java │ │ ├── EnterpriseUnixFTPEntryParserTest.java │ │ ├── FTPConfigEntryParserTest.java │ │ ├── FTPTimestampParserImplTest.java │ │ ├── MLSDComparison.java │ │ ├── MLSxEntryParserTest.java │ │ ├── MVSFTPEntryParserTest.java │ │ ├── MacOsPeterFTPEntryParserTest.java │ │ ├── NTFTPEntryParserTest.java │ │ ├── NetwareFTPEntryParserTest.java │ │ ├── OS2FTPEntryParserTest.java │ │ ├── OS400FTPEntryParserAdditionalTest.java │ │ ├── OS400FTPEntryParserTest.java │ │ ├── UnixFTPEntryParserTest.java │ │ └── VMSFTPEntryParserTest.java │ ├── imap │ ├── AuthenticatingIMAPClientTest.java │ ├── IMAPCommandTest.java │ ├── IMAPReplyTest.java │ └── IMAPTest.java │ ├── io │ ├── DotTerminatedMessageReaderTest.java │ └── ToNetASCIIInputStreamTest.java │ ├── nntp │ └── TestThreader.java │ ├── ntp │ ├── TestNtpClient.java │ ├── TestNtpPacket.java │ ├── TestTimeInfo.java │ └── TimeStampTest.java │ ├── pop3 │ ├── POP3ClientCommandsTest.java │ ├── POP3ClientTest.java │ ├── POP3Constants.java │ └── POP3ConstructorTest.java │ ├── smtp │ └── SimpleSMTPHeaderTestCase.java │ ├── telnet │ ├── AbstractTelnetOptionHandlerTest.java │ ├── EchoOptionHandlerTest.java │ ├── InvalidTelnetOptionExceptionTest.java │ ├── SimpleOptionHandlerTest.java │ ├── SuppressGAOptionHandlerTest.java │ ├── TelnetClientFunctionalTest.java │ ├── TelnetClientTest.java │ ├── TelnetOptionTest.java │ ├── TelnetTestResponder.java │ ├── TelnetTestSimpleServer.java │ ├── TerminalTypeOptionHandlerTest.java │ └── WindowSizeOptionHandlerTest.java │ ├── tftp │ ├── TFTPAckPacketTest.java │ ├── TFTPDataPacketTest.java │ ├── TFTPErrorPacketTest.java │ ├── TFTPPacketExceptionTest.java │ ├── TFTPReadRequestPacketTest.java │ ├── TFTPRequestPacketTest.java │ ├── TFTPServer.java │ ├── TFTPServerMain.java │ ├── TFTPServerPathTest.java │ ├── TFTPTest.java │ └── TFTPWriteRequestPacketTest.java │ ├── time │ ├── TimeTCPClientTest.java │ ├── TimeTestSimpleServer.java │ └── TimeUDPClientTest.java │ ├── util │ ├── Base64Test.java │ ├── CharsetsTest.java │ ├── ListenerListTest.java │ ├── SubnetUtilsNet728Test.java │ ├── SubnetUtilsTest.java │ ├── TrustManagerUtilsTest.java │ └── UtilTest.java │ └── whois │ └── WhoisClientTest.java └── resources └── org └── apache └── commons └── net ├── ftpsserver ├── ftpserver.jks └── users.properties ├── test-data └── file.txt └── test.properties /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Net" 18 | homepage: https://commons.apache.org/net/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | issues_bot_dependabot: notifications@commons.apache.org 27 | pullrequests_bot_dependabot: notifications@commons.apache.org 28 | issues_bot_codecov-commenter: notifications@commons.apache.org 29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 30 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | * text=auto 17 | *.patch -text 18 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "weekly" 22 | day: "friday" 23 | ignore: 24 | - dependency-name: "org.slf4j:slf4j-simple" 25 | - package-ecosystem: "github-actions" 26 | directory: "/" 27 | schedule: 28 | interval: "weekly" 29 | day: "friday" 30 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! 21 | 22 | Before you push a pull request, review this list: 23 | 24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. 25 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. 26 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice. 27 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 28 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge. 29 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Dependency Review' 19 | on: [pull_request] 20 | 21 | permissions: 22 | contents: read 23 | 24 | jobs: 25 | dependency-review: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: 'Checkout Repository' 29 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 30 | - name: 'Dependency Review PR' 31 | uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 32 | -------------------------------------------------------------------------------- /.github/workflows/scorecards-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache license, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the license for the specific language governing permissions and 14 | # limitations under the license. 15 | 16 | name: "Scorecards supply-chain security" 17 | 18 | on: 19 | workflow_dispatch: 20 | branch_protection_rule: 21 | push: 22 | branches: [ "master" ] 23 | paths-ignore: 24 | - '**/workflows/*.yml' 25 | - '!**/workflows/scorecards-analysis.yml' 26 | 27 | permissions: read-all 28 | 29 | jobs: 30 | 31 | analysis: 32 | 33 | name: "Scorecards analysis" 34 | runs-on: ubuntu-latest 35 | permissions: 36 | # Needed to upload the results to the code-scanning dashboard. 37 | security-events: write 38 | actions: read 39 | id-token: write # This is required for requesting the JWT 40 | contents: read # This is required for actions/checkout 41 | 42 | steps: 43 | 44 | - name: "Checkout code" 45 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 46 | with: 47 | persist-credentials: false 48 | 49 | - name: "Run analysis" 50 | uses: ossf/scorecard-action@f49aabe0b5af0936a0987cfb85d86b75731b0186 # 2.4.1 51 | with: 52 | results_file: results.sarif 53 | results_format: sarif 54 | # A read-only PAT token, which is sufficient for the action to function. 55 | # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188 56 | repo_token: ${{ secrets.GITHUB_TOKEN }} 57 | # Publish the results for public repositories to enable scorecard badges. 58 | # For more details: https://github.com/ossf/scorecard-action#publishing-results 59 | publish_results: true 60 | 61 | - name: "Upload artifact" 62 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 63 | with: 64 | name: SARIF file 65 | path: results.sarif 66 | retention-days: 5 67 | 68 | - name: "Upload to code-scanning" 69 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 70 | with: 71 | sarif_file: results.sarif 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.classpath 2 | /.project 3 | /.settings/ 4 | /target/ 5 | /.vscode/ 6 | .idea/ 7 | *.iml 8 | /site-content/ 9 | -------------------------------------------------------------------------------- /BUILDING.txt: -------------------------------------------------------------------------------- 1 | The code requires at least Java 8 to build. 2 | 3 | For setting up your Maven installation to enable the use of the profile, please see: 4 | 5 | https://commons.apache.org/commons-parent-pom.html#Testing_with_different_Java_versions 6 | 7 | Building the site will also generally require at least Java 8 to run Maven. 8 | 9 | To build the site from scratch, you can use: 10 | 11 | $ mvn clean site 12 | 13 | To install the component locally: 14 | 15 | $ mvn install 16 | 17 | To deploy: 18 | 19 | $ mvn deploy -Prelease -Duser.name=*ASF ID* [-Ptest-deploy] 20 | 21 | The test-deploy profile deploys to target/deploy rather than Nexus 22 | 23 | [1] http://maven.apache.org/docs/history.html 24 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Net 2 | Copyright 2001-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (https://www.apache.org/). 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | src 22 | 23 | tar.gz 24 | zip 25 | 26 | ${artifactId}-${version}-src 27 | 28 | 29 | 30 | BUILDING.txt 31 | CODE_OF_CONDUCT.md 32 | CONTRIBUTING.md 33 | LICENSE.txt 34 | NOTICE.txt 35 | pom.xml 36 | README.md 37 | RELEASE-NOTES.txt 38 | SECURITY.md 39 | 40 | 41 | 42 | src 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/conf/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/DatagramSocketFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net; 19 | 20 | import java.net.DatagramSocket; 21 | import java.net.InetAddress; 22 | import java.net.SocketException; 23 | 24 | /** 25 | * The DatagramSocketFactory interface provides a means for the programmer to control the creation of datagram sockets and provide his own DatagramSocket 26 | * implementations for use by all classes derived from {@link org.apache.commons.net.DatagramSocketClient} . This allows you to provide your own DatagramSocket 27 | * implementations and to perform security checks or browser capability requests before creating a DatagramSocket. 28 | */ 29 | public interface DatagramSocketFactory { 30 | 31 | /** 32 | * Creates a DatagramSocket on the local host at the first available port. 33 | * 34 | * @return the socket 35 | * @throws SocketException If the socket could not be created. 36 | */ 37 | DatagramSocket createDatagramSocket() throws SocketException; 38 | 39 | /** 40 | * Creates a DatagramSocket on the local host at a specified port. 41 | * 42 | * @param port The port to use for the socket. 43 | * @return the socket 44 | * @throws SocketException If the socket could not be created. 45 | */ 46 | DatagramSocket createDatagramSocket(int port) throws SocketException; 47 | 48 | /** 49 | * Creates a DatagramSocket at the specified address on the local host at a specified port. 50 | * 51 | * @param port The port to use for the socket. 52 | * @param localAddress The local address to use. 53 | * @return the socket 54 | * @throws SocketException If the socket could not be created. 55 | */ 56 | DatagramSocket createDatagramSocket(int port, InetAddress localAddress) throws SocketException; 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/MalformedServerReplyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * This exception is used to indicate that the reply from a server could not be interpreted. Most of the NetComponents classes attempt to be as lenient as 24 | * possible when receiving server replies. Many server implementations deviate from IETF protocol specifications, making it necessary to be as flexible as 25 | * possible. However, there will be certain situations where it is not possible to continue an operation because the server reply could not be interpreted in a 26 | * meaningful manner. In these cases, a MalformedServerReplyException should be thrown. 27 | */ 28 | public class MalformedServerReplyException extends IOException { 29 | 30 | private static final long serialVersionUID = 6006765264250543945L; 31 | 32 | /** Constructs a MalformedServerReplyException with no message */ 33 | public MalformedServerReplyException() { 34 | } 35 | 36 | /** 37 | * Constructs a MalformedServerReplyException with a specified message. 38 | * 39 | * @param message The message explaining the reason for the exception. 40 | */ 41 | public MalformedServerReplyException(final String message) { 42 | super(message); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ProtocolCommandListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net; 19 | 20 | import java.util.EventListener; 21 | 22 | /** 23 | * There exists a large class of IETF protocols that work by sending an ASCII text command and arguments to a server, and then receiving an ASCII text reply. 24 | * For debugging and other purposes, it is extremely useful to log or keep track of the contents of the protocol messages. The ProtocolCommandListener interface 25 | * coupled with the {@link ProtocolCommandEvent} class facilitate this process. 26 | *

27 | * To receive ProtocolCommandEvents, you merely implement the ProtocolCommandListener interface and register the class as a listener with a ProtocolCommandEvent 28 | * source such as {@link org.apache.commons.net.ftp.FTPClient}. 29 | *

30 | * 31 | * @see ProtocolCommandEvent 32 | * @see ProtocolCommandSupport 33 | */ 34 | public interface ProtocolCommandListener extends EventListener { 35 | 36 | /** 37 | * This method is invoked by a ProtocolCommandEvent source after sending a protocol command to a server. 38 | * 39 | * @param event The ProtocolCommandEvent fired. 40 | */ 41 | void protocolCommandSent(ProtocolCommandEvent event); 42 | 43 | /** 44 | * This method is invoked by a ProtocolCommandEvent source after receiving a reply from a server. 45 | * 46 | * @param event The ProtocolCommandEvent fired. 47 | */ 48 | void protocolReplyReceived(ProtocolCommandEvent event); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/bsd/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Classes for rcommand, rexec, rlogin 20 | */ 21 | package org.apache.commons.net.bsd; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/chargen/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Chargen over TCP and UDP 20 | */ 21 | package org.apache.commons.net.chargen; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/daytime/DaytimeTCPClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.daytime; 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.commons.io.IOUtils; 23 | import org.apache.commons.net.SocketClient; 24 | 25 | /** 26 | * The DaytimeTCPClient class is a TCP implementation of a client for the Daytime protocol described in RFC 867. To use the class, merely establish a connection 27 | * with {@link org.apache.commons.net.SocketClient#connect connect} and call {@link #getTime getTime()} to retrieve the daytime string, then call 28 | * {@link org.apache.commons.net.SocketClient#disconnect disconnect} to close the connection properly. 29 | * 30 | * @see DaytimeUDPClient 31 | */ 32 | public final class DaytimeTCPClient extends SocketClient { 33 | 34 | /** 35 | * The default daytime port {@value} per RFC 867. 36 | */ 37 | public static final int DEFAULT_PORT = 13; 38 | 39 | /** 40 | * The default DaytimeTCPClient constructor. It merely sets the default port to DEFAULT_PORT. 41 | */ 42 | public DaytimeTCPClient() { 43 | setDefaultPort(DEFAULT_PORT); 44 | } 45 | 46 | /** 47 | * Gets the time string from the server and returns it. The server will have closed the connection at this point, so you should call 48 | * {@link org.apache.commons.net.SocketClient#disconnect disconnect} after calling this method. To retrieve another time, you must initiate another 49 | * connection with {@link org.apache.commons.net.SocketClient#connect connect} before calling {@code getTime()} again. 50 | * 51 | * @return The time string retrieved from the server. 52 | * @throws IOException If an error occurs while fetching the time string. 53 | */ 54 | public String getTime() throws IOException { 55 | return IOUtils.toString(_input_, getCharset()); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/daytime/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Daytime over TCP and UDP 20 | */ 21 | package org.apache.commons.net.daytime; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/discard/DiscardTCPClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.discard; 19 | 20 | import java.io.OutputStream; 21 | 22 | import org.apache.commons.net.SocketClient; 23 | 24 | /** 25 | * The DiscardTCPClient class is a TCP implementation of a client for the Discard protocol described in RFC 863. To use the class, merely establish a connection 26 | * with {@link org.apache.commons.net.SocketClient#connect connect} and call {@link #getOutputStream getOutputStream()} to retrieve the discard output stream. 27 | * Don't close the output stream when you're done writing to it. Rather, call {@link org.apache.commons.net.SocketClient#disconnect disconnect} to clean up 28 | * properly. 29 | * 30 | * @see DiscardUDPClient 31 | */ 32 | public class DiscardTCPClient extends SocketClient { 33 | 34 | /** The default discard port. It is set to 9 according to RFC 863. */ 35 | public static final int DEFAULT_PORT = 9; 36 | 37 | /** 38 | * The default DiscardTCPClient constructor. It merely sets the default port to {@code DEFAULT_PORT}. 39 | */ 40 | public DiscardTCPClient() { 41 | setDefaultPort(DEFAULT_PORT); 42 | } 43 | 44 | /** 45 | * Gets an OutputStream through which you may write data to the server. You should NOT close the OutputStream when you're finished reading from it. 46 | * Rather, you should call {@link org.apache.commons.net.SocketClient#disconnect disconnect} to clean up properly. 47 | * 48 | * @return An OutputStream through which you can write data to the server. 49 | */ 50 | public OutputStream getOutputStream() { 51 | return _output_; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/discard/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Discard over TCP and UDP 20 | */ 21 | package org.apache.commons.net.discard; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/echo/EchoTCPClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.echo; 19 | 20 | import java.io.InputStream; 21 | 22 | import org.apache.commons.net.discard.DiscardTCPClient; 23 | 24 | /** 25 | * The EchoTCPClient class is a TCP implementation of a client for the Echo protocol described in RFC 862. To use the class, merely establish a connection with 26 | * {@link org.apache.commons.net.SocketClient#connect connect} and call {@link DiscardTCPClient#getOutputStream getOutputStream()} to retrieve the echo output 27 | * stream and {@link #getInputStream getInputStream()} to get the echo input stream. Don't close either stream when you're done using them. Rather, call 28 | * {@link org.apache.commons.net.SocketClient#disconnect disconnect} to clean up properly. 29 | * 30 | * @see EchoUDPClient 31 | * @see DiscardTCPClient 32 | */ 33 | public final class EchoTCPClient extends DiscardTCPClient { 34 | 35 | /** The default echo port. It is set to 7 according to RFC 862. */ 36 | public static final int DEFAULT_PORT = 7; 37 | 38 | /** 39 | * The default EchoTCPClient constructor. It merely sets the default port to {@code DEFAULT_PORT}. 40 | */ 41 | public EchoTCPClient() { 42 | setDefaultPort(DEFAULT_PORT); 43 | } 44 | 45 | /** 46 | * Gets the time string from the specified server and port and returns it. an InputStream from which you may read echoed data from the server. You should 47 | * NOT close the InputStream when you're finished reading from it. Rather, you should call {@link org.apache.commons.net.SocketClient#disconnect disconnect 48 | * } to clean up properly. 49 | * 50 | * @return An InputStream from which you can read echoed data from the server. 51 | */ 52 | public InputStream getInputStream() { 53 | return _input_; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/echo/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Echo over TCP and UDP 20 | */ 21 | package org.apache.commons.net.echo; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/examples/PrintCommandListeners.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.examples; 19 | 20 | import org.apache.commons.net.PrintCommandListener; 21 | import org.apache.commons.net.io.Util; 22 | 23 | /** 24 | * Factory of {@link PrintCommandListener} for examples. 25 | */ 26 | public class PrintCommandListeners { 27 | 28 | /** 29 | * Creates a new PrintCommandListener on system out. 30 | * 31 | * @return a new PrintCommandListener on system out. 32 | */ 33 | public static PrintCommandListener sysOutPrintCommandListener() { 34 | return new PrintCommandListener(Util.newPrintWriter(System.out), true); 35 | } 36 | 37 | /** 38 | * Constructs a new instance. 39 | * 40 | * @deprecated Will be private in the next major release. 41 | */ 42 | @Deprecated 43 | public PrintCommandListeners() { 44 | // empty 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/examples/mail/IMAPMail.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.examples.mail; 19 | 20 | import java.io.IOException; 21 | import java.net.URI; 22 | 23 | import org.apache.commons.net.PrintCommandListener; 24 | import org.apache.commons.net.imap.IMAPClient; 25 | 26 | /** 27 | * This is an example program demonstrating how to use the IMAP[S]Client class. This program connects to a IMAP[S] server, lists its capabilities and shows the 28 | * status of the Inbox. 29 | *

30 | * Usage: IMAPMail imap[s]://user:password@server/ 31 | *

32 | * For example
33 | * IMAPMail imaps://user:password@imap.mail.yahoo.com/
34 | * or
35 | * IMAPMail imaps://user:password@imap.googlemail.com/ 36 | */ 37 | public final class IMAPMail { 38 | 39 | public static void main(final String[] args) throws IOException { 40 | if (args.length != 1) { 41 | System.err.println("Usage: IMAPMail imap[s]://user:password@server/"); 42 | System.err.println("Connects to server; lists capabilities and shows Inbox status"); 43 | System.exit(1); 44 | } 45 | 46 | final URI uri = URI.create(args[0]); 47 | 48 | // Connect and login 49 | final IMAPClient imap = IMAPUtils.imapLogin(uri, 10000, null); 50 | 51 | // suppress login details 52 | imap.addProtocolCommandListener(new PrintCommandListener(System.out, true)); 53 | 54 | try { 55 | imap.setSoTimeout(6000); 56 | 57 | imap.capability(); 58 | 59 | imap.select("inbox"); 60 | 61 | imap.examine("inbox"); 62 | 63 | imap.status("inbox", new String[] { "MESSAGES" }); 64 | 65 | imap.list("", "*"); // Show the folders 66 | 67 | } catch (final IOException e) { 68 | System.out.println(imap.getReplyString()); 69 | e.printStackTrace(); 70 | System.exit(10); 71 | } finally { 72 | imap.logout(); 73 | imap.disconnect(); 74 | } 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/examples/nntp/NNTPUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.examples.nntp; 18 | 19 | import java.io.IOException; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import org.apache.commons.net.nntp.Article; 24 | import org.apache.commons.net.nntp.NNTPClient; 25 | 26 | /** 27 | * Some convenience methods for NNTP example classes. 28 | */ 29 | public class NNTPUtils { 30 | 31 | /** 32 | * Given an {@link NNTPClient} instance, and an integer range of messages, return an array of {@link Article} instances. 33 | * 34 | * @param client the client to use 35 | * @param lowArticleNumber low number 36 | * @param highArticleNumber high number 37 | * @return Article[] An array of Article 38 | * @throws IOException on error 39 | */ 40 | public static List

getArticleInfo(final NNTPClient client, final long lowArticleNumber, final long highArticleNumber) throws IOException { 41 | final List
articles = new ArrayList<>(); 42 | final Iterable
arts = client.iterateArticleInfo(lowArticleNumber, highArticleNumber); 43 | for (final Article article : arts) { 44 | articles.add(article); 45 | } 46 | return articles; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/examples/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Example classes. 20 | *

21 | * These do not form part of the public API and may change without notice. 22 | */ 23 | package org.apache.commons.net.examples; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/examples/telnet/WeatherTelnet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.examples.telnet; 19 | 20 | import java.io.IOException; 21 | 22 | import org.apache.commons.net.examples.util.IOUtil; 23 | import org.apache.commons.net.telnet.TelnetClient; 24 | 25 | /** 26 | * This is an example of a trivial use of the TelnetClient class. It connects to the weather server at the University of Michigan, um-weather.sprl.umich.edu 27 | * port 3000, and allows the user to interact with the server via standard input. You could use this example to connect to any Telnet server, but it is 28 | * obviously not general purpose because it reads from standard input a line at a time, making it inconvenient for use with a remote interactive shell. The 29 | * TelnetClient class used by itself is mostly intended for automating access to Telnet resources rather than interactive use. 30 | */ 31 | 32 | // This class requires the IOUtil support class! 33 | public final class WeatherTelnet { 34 | 35 | public static void main(final String[] args) { 36 | final TelnetClient telnet; 37 | 38 | telnet = new TelnetClient(); 39 | 40 | try { 41 | telnet.connect("rainmaker.wunderground.com", 3000); 42 | } catch (final IOException e) { 43 | e.printStackTrace(); 44 | System.exit(1); 45 | } 46 | 47 | IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(), System.in, System.out); 48 | 49 | try { 50 | telnet.disconnect(); 51 | } catch (final IOException e) { 52 | e.printStackTrace(); 53 | System.exit(1); 54 | } 55 | 56 | System.exit(0); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/examples/unix/fwhois.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.examples.unix; 19 | 20 | import java.io.IOException; 21 | import java.net.InetAddress; 22 | import java.net.UnknownHostException; 23 | 24 | import org.apache.commons.net.whois.WhoisClient; 25 | 26 | /** 27 | * This is an example of how you would implement the Linux fwhois command in Java using NetComponents. The Java version is much shorter. 28 | */ 29 | public final class fwhois { 30 | 31 | public static void main(final String[] args) { 32 | final int index; 33 | final String handle; 34 | final String host; 35 | InetAddress address = null; 36 | final WhoisClient whois; 37 | 38 | if (args.length != 1) { 39 | System.err.println("usage: fwhois handle[@]"); 40 | System.exit(1); 41 | } 42 | 43 | index = args[0].lastIndexOf('@'); 44 | 45 | whois = new WhoisClient(); 46 | // We want to timeout if a response takes longer than 60 seconds 47 | whois.setDefaultTimeout(60000); 48 | 49 | if (index == -1) { 50 | handle = args[0]; 51 | host = WhoisClient.DEFAULT_HOST; 52 | } else { 53 | handle = args[0].substring(0, index); 54 | host = args[0].substring(index + 1); 55 | } 56 | 57 | try { 58 | address = InetAddress.getByName(host); 59 | System.out.println("[" + address.getHostName() + "]"); 60 | } catch (final UnknownHostException e) { 61 | System.err.println("Error unknown host: " + e.getMessage()); 62 | System.exit(1); 63 | } 64 | 65 | try { 66 | whois.connect(address); 67 | System.out.print(whois.query(handle)); 68 | whois.disconnect(); 69 | } catch (final IOException e) { 70 | System.err.println("Error I/O exception: " + e.getMessage()); 71 | System.exit(1); 72 | } 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/finger/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Finger implementation 20 | */ 21 | package org.apache.commons.net.finger; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/Configurable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | /** 21 | * This interface adds the aspect of configurability by means of a supplied FTPClientConfig object to other classes in the system, especially listing parsers. 22 | */ 23 | public interface Configurable { 24 | 25 | /** 26 | * Configures this instance using an FTPClientConfig. 27 | * 28 | * @param config the object containing the configuration data. 29 | * @throws IllegalArgumentException if the elements of the {@code config} are somehow inadequate to configure the Configurable object. 30 | */ 31 | void configure(FTPClientConfig config); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/DeflateSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.io.OutputStream; 23 | import java.net.Socket; 24 | import java.util.zip.DeflaterOutputStream; 25 | import java.util.zip.InflaterInputStream; 26 | 27 | /** 28 | * Wrapper class for FTP data channel sockets when compressing data in the "deflate" compression format. All methods except of {@link #getInputStream()} and 29 | * {@link #getOutputStream()} are calling the delegate methods directly. 30 | */ 31 | final class DeflateSocket extends DelegateSocket { 32 | 33 | DeflateSocket(final Socket delegate) { 34 | super(delegate); 35 | } 36 | 37 | @Override 38 | public InputStream getInputStream() throws IOException { 39 | return new InflaterInputStream(delegate.getInputStream()); 40 | } 41 | 42 | @Override 43 | public OutputStream getOutputStream() throws IOException { 44 | return new DeflaterOutputStream(delegate.getOutputStream()); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/DurationUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.time.Duration; 21 | 22 | /** Temporary until Commons Lang 3.12.0. */ 23 | final class DurationUtils { 24 | 25 | /** 26 | * Tests whether the given Duration is positive (>0). 27 | * 28 | * @param duration the value to test 29 | * @return whether the given Duration is positive (>0). 30 | */ 31 | static boolean isPositive(final Duration duration) { 32 | return duration != null && !duration.isNegative() && !duration.isZero(); 33 | } 34 | 35 | static int toMillisInt(final Duration duration) { 36 | final long millis = duration.toMillis(); 37 | return millis > 0 ? (int) Math.min(millis, Integer.MAX_VALUE) : (int) Math.max(millis, Integer.MIN_VALUE); 38 | } 39 | 40 | static Duration zeroIfNull(final Duration controlIdle) { 41 | return controlIdle == null ? Duration.ZERO : controlIdle; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/FTPConnectionClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * FTPConnectionClosedException is used to indicate the premature or unexpected closing of an FTP connection resulting from a 24 | * {@link org.apache.commons.net.ftp.FTPReply#SERVICE_NOT_AVAILABLE FTPReply.SERVICE_NOT_AVAILABLE} response (FTP reply code 421) to a failed FTP command. This 25 | * exception is derived from IOException and therefore may be caught either as an IOException or specifically as an FTPConnectionClosedException. 26 | * 27 | * @see FTP 28 | * @see FTPClient 29 | */ 30 | public class FTPConnectionClosedException extends IOException { 31 | 32 | private static final long serialVersionUID = 3500547241659379952L; 33 | 34 | /** Constructs a FTPConnectionClosedException with no message */ 35 | public FTPConnectionClosedException() { 36 | } 37 | 38 | /** 39 | * Constructs a FTPConnectionClosedException with a specified message. 40 | * 41 | * @param message The message explaining the reason for the exception. 42 | */ 43 | public FTPConnectionClosedException(final String message) { 44 | super(message); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/FTPFileEntryParserImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.IOException; 22 | import java.util.List; 23 | 24 | /** 25 | * This abstract class implements both the older FTPFileListParser and newer FTPFileEntryParser interfaces with default functionality. All the classes in the 26 | * parser subpackage inherit from this. 27 | */ 28 | public abstract class FTPFileEntryParserImpl implements FTPFileEntryParser { 29 | /** 30 | * The constructor for a FTPFileEntryParserImpl object. 31 | */ 32 | public FTPFileEntryParserImpl() { 33 | } 34 | 35 | /** 36 | * This method is a hook for those implementors (such as VMSVersioningFTPEntryParser, and possibly others) which need to perform some action upon the 37 | * FTPFileList after it has been created from the server stream, but before any clients see the list. 38 | * 39 | * This default implementation does nothing. 40 | * 41 | * @param original Original list after it has been created from the server stream 42 | * @return {@code original} unmodified. 43 | */ 44 | @Override 45 | public List preParse(final List original) { 46 | return original; 47 | } 48 | 49 | /** 50 | * Reads the next entry using the supplied BufferedReader object up to whatever delimits one entry from the next. This default implementation simply calls 51 | * BufferedReader.readLine(). 52 | * 53 | * @param reader The BufferedReader object from which entries are to be read. 54 | * @return A string representing the next ftp entry or null if none found. 55 | * @throws IOException thrown on any IO Error reading from the reader. 56 | */ 57 | @Override 58 | public String readNextEntry(final BufferedReader reader) throws IOException { 59 | return reader.readLine(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/FTPFileFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | /** 21 | * Performs filtering on {@link FTPFile} instances. 22 | * 23 | * @since 2.2 24 | */ 25 | public interface FTPFileFilter { 26 | 27 | /** 28 | * Checks if an FTPFile entry should be included or not. 29 | * 30 | * @param file entry to be checked for inclusion. May be {@code null}. 31 | * @return {@code true} if the file is to be included, {@code false} otherwise. 32 | */ 33 | boolean accept(FTPFile file); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/FTPFileFilters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.util.Objects; 21 | 22 | /** 23 | * Implements some simple FTPFileFilter classes. 24 | * 25 | * @since 2.2 26 | */ 27 | public class FTPFileFilters { 28 | 29 | /** 30 | * Accepts all FTPFile entries, including null. 31 | */ 32 | public static final FTPFileFilter ALL = file -> true; 33 | 34 | /** 35 | * Accepts all non-null FTPFile entries. 36 | */ 37 | public static final FTPFileFilter NON_NULL = Objects::nonNull; 38 | 39 | /** 40 | * Accepts all (non-null) FTPFile directory entries. 41 | */ 42 | public static final FTPFileFilter DIRECTORIES = file -> file != null && file.isDirectory(); 43 | 44 | /** 45 | * Constructs a new instance. 46 | * 47 | * @deprecated Will be private in the next major release. 48 | */ 49 | @Deprecated 50 | public FTPFileFilters() { 51 | // empty 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/FTPSCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | /** 21 | * FTPS-specific commands. 22 | * 23 | * @since 2.0 24 | * @deprecated 3.0 DO NOT USE 25 | */ 26 | @Deprecated 27 | public final class FTPSCommand { 28 | 29 | /** 30 | * {@value} 31 | */ 32 | public static final int AUTH = 0; 33 | 34 | /** 35 | * {@value} 36 | */ 37 | public static final int ADAT = 1; 38 | 39 | /** 40 | * {@value} 41 | */ 42 | public static final int PBSZ = 2; 43 | 44 | /** 45 | * {@value} 46 | */ 47 | public static final int PROT = 3; 48 | 49 | /** 50 | * {@value} 51 | */ 52 | public static final int CCC = 4; 53 | 54 | /** 55 | * {@value} 56 | */ 57 | public static final int AUTHENTICATION_SECURITY_MECHANISM = AUTH; 58 | 59 | /** 60 | * {@value} 61 | */ 62 | public static final int AUTHENTICATION_SECURITY_DATA = ADAT; 63 | 64 | /** 65 | * {@value} 66 | */ 67 | public static final int PROTECTION_BUFFER_SIZE = PBSZ; 68 | 69 | /** 70 | * {@value} 71 | */ 72 | public static final int DATA_CHANNEL_PROTECTION_LEVEL = PROT; 73 | 74 | /** 75 | * {@value} 76 | */ 77 | public static final int CLEAR_COMMAND_CHANNEL = CCC; 78 | 79 | /** 80 | * {@value} 81 | */ 82 | private static final String[] commands = { "AUTH", "ADAT", "PBSZ", "PROT", "CCC" }; 83 | 84 | /** 85 | * Gets the FTPS command string corresponding to a specified command code. 86 | * 87 | * @param command The command code. 88 | * @return The FTPS command string corresponding to a specified command code. 89 | */ 90 | public static String getCommand(final int command) { 91 | return commands[command]; 92 | } 93 | 94 | /** 95 | * Constructs a new instance. 96 | */ 97 | public FTPSCommand() { 98 | // empty 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/FTPSTrustManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.security.cert.CertificateException; 21 | import java.security.cert.X509Certificate; 22 | 23 | import javax.net.ssl.X509TrustManager; 24 | 25 | import org.apache.commons.net.util.NetConstants; 26 | 27 | /** 28 | * Do not use. 29 | * 30 | * @since 2.0 31 | * @deprecated 3.0 use {@link org.apache.commons.net.util.TrustManagerUtils#getValidateServerCertificateTrustManager() 32 | * TrustManagerUtils#getValidateServerCertificateTrustManager()} instead 33 | */ 34 | @Deprecated 35 | public class FTPSTrustManager implements X509TrustManager { 36 | 37 | /** 38 | * Constructs a new instance. 39 | */ 40 | public FTPSTrustManager() { 41 | // empty 42 | } 43 | 44 | /** 45 | * No-op 46 | */ 47 | @Override 48 | public void checkClientTrusted(final X509Certificate[] certificates, final String authType) { 49 | } 50 | 51 | @Override 52 | public void checkServerTrusted(final X509Certificate[] certificates, final String authType) throws CertificateException { 53 | for (final X509Certificate certificate : certificates) { 54 | certificate.checkValidity(); 55 | } 56 | } 57 | 58 | @Override 59 | public X509Certificate[] getAcceptedIssuers() { 60 | return NetConstants.EMPTY_X509_CERTIFICATE_ARRAY; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * FTP and FTPS support classes 20 | */ 21 | package org.apache.commons.net.ftp; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/parser/CompositeFileEntryParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp.parser; 19 | 20 | import org.apache.commons.net.ftp.FTPFile; 21 | import org.apache.commons.net.ftp.FTPFileEntryParser; 22 | import org.apache.commons.net.ftp.FTPFileEntryParserImpl; 23 | 24 | /** 25 | * This implementation allows to pack some FileEntryParsers together and handle the case where the returned dir style isn't clearly defined. The matching parser 26 | * will be cached. If the cached parser won't match due to the server changed the dir style, a new matching parser will be searched. 27 | */ 28 | public class CompositeFileEntryParser extends FTPFileEntryParserImpl { 29 | private final FTPFileEntryParser[] ftpFileEntryParsers; 30 | private FTPFileEntryParser cachedFtpFileEntryParser; 31 | 32 | /** 33 | * Constructs a new instance. 34 | * 35 | * @param ftpFileEntryParsers An array of FTPFileEntryParser. 36 | */ 37 | public CompositeFileEntryParser(final FTPFileEntryParser[] ftpFileEntryParsers) { 38 | this.cachedFtpFileEntryParser = null; 39 | this.ftpFileEntryParsers = ftpFileEntryParsers; 40 | } 41 | 42 | @Override 43 | public FTPFile parseFTPEntry(final String listEntry) { 44 | if (cachedFtpFileEntryParser != null) { 45 | return cachedFtpFileEntryParser.parseFTPEntry(listEntry); 46 | } 47 | for (final FTPFileEntryParser ftpFileEntryParser : ftpFileEntryParsers) { 48 | final FTPFile matched = ftpFileEntryParser.parseFTPEntry(listEntry); 49 | if (matched != null) { 50 | cachedFtpFileEntryParser = ftpFileEntryParser; 51 | return matched; 52 | } 53 | } 54 | return null; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/parser/FTPFileEntryParserFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp.parser; 19 | 20 | import org.apache.commons.net.ftp.FTPClientConfig; 21 | import org.apache.commons.net.ftp.FTPFileEntryParser; 22 | 23 | /** 24 | * The interface describes a factory for creating FTPFileEntryParsers. 25 | * 26 | * @since 1.2 27 | */ 28 | public interface FTPFileEntryParserFactory { 29 | /** 30 | *

31 | * Implementation should be a method that extracts a key from the supplied {@link FTPClientConfig FTPClientConfig} parameter and creates an object 32 | * implementing the interface FTPFileEntryParser and uses the supplied configuration to configure it. 33 | *

34 | *

35 | * Note that this method will generally not be called in scenarios that call for autodetection of parser type but rather, for situations where the user 36 | * knows that the server uses a non-default configuration and knows what that configuration is. 37 | *

38 | * 39 | * @param config A {@link FTPClientConfig FTPClientConfig} used to configure the parser created 40 | * @return the {@link FTPFileEntryParser} so created. 41 | * @throws ParserInitializationException Thrown on any exception in instantiation 42 | * @since 1.4 43 | */ 44 | FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException; 45 | 46 | /** 47 | * Implementation should be a method that decodes the supplied key and creates an object implementing the interface FTPFileEntryParser. 48 | * 49 | * @param key A string that somehow identifies an FTPFileEntryParser to be created. 50 | * @return the FTPFileEntryParser created. 51 | * @throws ParserInitializationException Thrown on any exception in instantiation 52 | */ 53 | FTPFileEntryParser createFileEntryParser(String key) throws ParserInitializationException; 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/parser/FTPTimestampParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp.parser; 19 | 20 | import java.text.ParseException; 21 | import java.util.Calendar; 22 | 23 | /** 24 | * This interface specifies the concept of parsing an FTP server's timestamp. 25 | * 26 | * @since 1.4 27 | */ 28 | public interface FTPTimestampParser { 29 | 30 | /** 31 | * the default default date format. 32 | */ 33 | String DEFAULT_SDF = UnixFTPEntryParser.DEFAULT_DATE_FORMAT; 34 | /** 35 | * the default recent date format. 36 | */ 37 | String DEFAULT_RECENT_SDF = UnixFTPEntryParser.DEFAULT_RECENT_DATE_FORMAT; 38 | 39 | /** 40 | * Parses the supplied datestamp parameter. This parameter typically would have been pulled from a longer FTP listing via the regular expression mechanism 41 | * 42 | * @param timestampStr the timestamp portion of the FTP directory listing to be parsed 43 | * @return a {@code java.util.Calendar} object initialized to the date parsed by the parser 44 | * @throws ParseException if none of the parser mechanisms belonging to the implementor can parse the input. 45 | */ 46 | Calendar parseTimestamp(String timestampStr) throws ParseException; 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/parser/ParserInitializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp.parser; 19 | 20 | /** 21 | * This class encapsulates all errors that may be thrown by the process of an FTPFileEntryParserFactory creating and instantiating an FTPFileEntryParser. 22 | */ 23 | public class ParserInitializationException extends RuntimeException { 24 | 25 | private static final long serialVersionUID = 5563335279583210658L; 26 | 27 | /** 28 | * Constructs a ParserInitializationException with just a message 29 | * 30 | * @param message Exception message 31 | */ 32 | public ParserInitializationException(final String message) { 33 | super(message); 34 | } 35 | 36 | /** 37 | * Constructs a ParserInitializationException with a message and a root cause. 38 | * 39 | * @param message Exception message 40 | * @param rootCause root cause throwable that caused this to be thrown 41 | */ 42 | public ParserInitializationException(final String message, final Throwable rootCause) { 43 | super(message, rootCause); 44 | } 45 | 46 | /** 47 | * Gets the root cause of this exception or null if no root cause was specified. 48 | * 49 | * @return the root cause of this exception being thrown 50 | * @deprecated use {@link #getCause()} instead 51 | */ 52 | @Deprecated 53 | public Throwable getRootCause() { 54 | return super.getCause(); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ftp/parser/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * FTP file listing parser classes 20 | */ 21 | package org.apache.commons.net.ftp.parser; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/imap/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Basic IMAP and IMAPS support classes 20 | */ 21 | package org.apache.commons.net.imap; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/io/CRLFLineReader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.io; 19 | 20 | import java.io.BufferedReader; 21 | import java.io.IOException; 22 | import java.io.Reader; 23 | 24 | import org.apache.commons.net.util.NetConstants; 25 | 26 | /** 27 | * CRLFLineReader implements a readLine() method that requires exactly CRLF to terminate an input line. This is required for IMAP, which allows bare CR and LF. 28 | * 29 | * @since 3.0 30 | */ 31 | public final class CRLFLineReader extends BufferedReader { 32 | private static final char LF = '\n'; 33 | private static final char CR = '\r'; 34 | 35 | /** 36 | * Creates a CRLFLineReader that wraps an existing Reader input source. 37 | * 38 | * @param reader The Reader input source. 39 | */ 40 | public CRLFLineReader(final Reader reader) { 41 | super(reader); 42 | } 43 | 44 | /** 45 | * Reads a line of text. A line is considered to be terminated by carriage return followed immediately by a linefeed. This contrasts with BufferedReader 46 | * which also allows other combinations. 47 | * 48 | * @since 3.0 49 | */ 50 | @Override 51 | public String readLine() throws IOException { 52 | final StringBuilder sb = new StringBuilder(); 53 | int intch; 54 | boolean prevWasCR = false; 55 | synchronized (lock) { // make thread-safe (hopefully!) 56 | while ((intch = read()) != NetConstants.EOS) { 57 | if (prevWasCR && intch == LF) { 58 | return sb.substring(0, sb.length() - 1); 59 | } 60 | prevWasCR = intch == CR; 61 | sb.append((char) intch); 62 | } 63 | } 64 | final String string = sb.toString(); 65 | if (string.isEmpty()) { // immediate EOF 66 | return null; 67 | } 68 | return string; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/io/SocketInputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.io; 19 | 20 | import java.io.FilterInputStream; 21 | import java.io.IOException; 22 | import java.io.InputStream; 23 | import java.net.Socket; 24 | 25 | /** 26 | * This class wraps an input stream, storing a reference to its originating socket. When the stream is closed, it will also close the socket immediately 27 | * afterward. This class is useful for situations where you are dealing with a stream originating from a socket, but do not have a reference to the socket, and 28 | * want to make sure it closes when the stream closes. 29 | * 30 | * @see SocketOutputStream 31 | */ 32 | public class SocketInputStream extends FilterInputStream { 33 | private final Socket socket; 34 | 35 | /** 36 | * Creates a SocketInputStream instance wrapping an input stream and storing a reference to a socket that should be closed on closing the stream. 37 | * 38 | * @param socket The socket to close on closing the stream. 39 | * @param stream The input stream to wrap. 40 | */ 41 | public SocketInputStream(final Socket socket, final InputStream stream) { 42 | super(stream); 43 | this.socket = socket; 44 | } 45 | 46 | /** 47 | * Closes the stream and immediately afterward closes the referenced socket. 48 | * 49 | * @throws IOException If there is an error in closing the stream or socket. 50 | */ 51 | @Override 52 | public void close() throws IOException { 53 | super.close(); 54 | socket.close(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/io/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Utility classes for IO support. 20 | */ 21 | package org.apache.commons.net.io; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/ArticleInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | /** 21 | * Class contains details about an article. Create an instance of the class and pass it to the appropriate NNTP method. The values will be populated on return. 22 | */ 23 | public class ArticleInfo { 24 | 25 | /** 26 | * Article ID. 27 | */ 28 | public String articleId; 29 | 30 | /** 31 | * Article number. 32 | */ 33 | public long articleNumber; 34 | 35 | /** 36 | * Constructs a new instance. 37 | */ 38 | public ArticleInfo() { 39 | // empty 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/ArticleIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | import java.util.Iterator; 21 | 22 | /** 23 | * Class which wraps an {@code Iterable} of raw article information to generate an {@code Iterable
} of the parsed information. 24 | * 25 | * @since 3.0 26 | */ 27 | final class ArticleIterator implements Iterator
, Iterable
{ 28 | 29 | private final Iterator stringIterator; 30 | 31 | public ArticleIterator(final Iterable iterableString) { 32 | stringIterator = iterableString.iterator(); 33 | } 34 | 35 | @Override 36 | public boolean hasNext() { 37 | return stringIterator.hasNext(); 38 | } 39 | 40 | @Override 41 | public Iterator
iterator() { 42 | return this; 43 | } 44 | 45 | /** 46 | * Gets the next Article 47 | * 48 | * @return the next {@link Article}, never {@code null}, if unparseable then isDummy() will be true, and the subject will contain the raw info. 49 | */ 50 | @Override 51 | public Article next() { 52 | final String line = stringIterator.next(); 53 | return NNTPClient.parseArticleEntry(line); 54 | } 55 | 56 | @Override 57 | public void remove() { 58 | stringIterator.remove(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/ArticlePointer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | /** 21 | * This class is a structure used to return article number and unique id information extracted from an NNTP server reply. You will normally want this 22 | * information when issuing a STAT command, implemented by {@link NNTPClient#selectArticle selectArticle}. 23 | * 24 | * @see NNTPClient 25 | * @deprecated 3.0 use {@link ArticleInfo} instead 26 | */ 27 | @Deprecated 28 | public final class ArticlePointer { 29 | /** The number of the referenced article. */ 30 | public int articleNumber; 31 | /** 32 | * The unique id of the referenced article, including the enclosing < and > symbols which are technically not part of the identifier, but are required 33 | * by all NNTP commands taking an article id as an argument. 34 | */ 35 | public String articleId; 36 | 37 | /** 38 | * Constructs a new instance. 39 | */ 40 | public ArticlePointer() { 41 | // empty 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/NNTPConnectionClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * NNTPConnectionClosedException is used to indicate the premature or unexpected closing of an NNTP connection resulting from a 24 | * {@link org.apache.commons.net.nntp.NNTPReply#SERVICE_DISCONTINUED NNTPReply.SERVICE_DISCONTINUED} response (NNTP reply code 400) to a failed NNTP command. 25 | * This exception is derived from IOException and therefore may be caught either as an IOException or specifically as an NNTPConnectionClosedException. 26 | * 27 | * @see NNTP 28 | * @see NNTPClient 29 | */ 30 | 31 | public final class NNTPConnectionClosedException extends IOException { 32 | 33 | private static final long serialVersionUID = 1029785635891040770L; 34 | 35 | /** Constructs a NNTPConnectionClosedException with no message */ 36 | public NNTPConnectionClosedException() { 37 | } 38 | 39 | /** 40 | * Constructs a NNTPConnectionClosedException with a specified message. 41 | * 42 | * @param message The message explaining the reason for the exception. 43 | */ 44 | public NNTPConnectionClosedException(final String message) { 45 | super(message); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/NewsgroupIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | import java.util.Iterator; 21 | 22 | /** 23 | * Class which wraps an {@code Iterable} of raw newgroup information to generate an {@code Iterable} of the parsed information. 24 | * 25 | * @since 3.0 26 | */ 27 | final class NewsgroupIterator implements Iterator, Iterable { 28 | 29 | private final Iterator stringIterator; 30 | 31 | public NewsgroupIterator(final Iterable iterableString) { 32 | stringIterator = iterableString.iterator(); 33 | } 34 | 35 | @Override 36 | public boolean hasNext() { 37 | return stringIterator.hasNext(); 38 | } 39 | 40 | @Override 41 | public Iterator iterator() { 42 | return this; 43 | } 44 | 45 | @Override 46 | public NewsgroupInfo next() { 47 | final String line = stringIterator.next(); 48 | return NNTPClient.parseNewsgroupListEntry(line); 49 | } 50 | 51 | @Override 52 | public void remove() { 53 | stringIterator.remove(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/Threadable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | /** 21 | * A placeholder interface for threadable message objects. 22 | * 23 | * @param The Threadable implementation. 24 | */ 25 | public interface Threadable> { 26 | 27 | /** 28 | * Tests whether this is a dummy instance. 29 | * 30 | * @return whether this is a dummy instance. 31 | */ 32 | boolean isDummy(); 33 | 34 | /** 35 | * Creates a dummy instance. 36 | * 37 | * @return a dummy instance. 38 | */ 39 | T makeDummy(); 40 | 41 | /** 42 | * Gets an ID. 43 | * 44 | * @return an ID. 45 | */ 46 | String messageThreadId(); 47 | 48 | /** 49 | * Gets reference strings. 50 | * 51 | * @return reference strings. 52 | */ 53 | String[] messageThreadReferences(); 54 | 55 | /** 56 | * Sets the child instance. 57 | * 58 | * @param child the child instance. 59 | */ 60 | void setChild(T child); 61 | 62 | /** 63 | * Sets the next instance. 64 | * 65 | * @param next the next instance. 66 | */ 67 | void setNext(T next); 68 | 69 | /** 70 | * Gets the simplified subject. 71 | * 72 | * @return the simplified subject. 73 | */ 74 | String simplifiedSubject(); 75 | 76 | /** 77 | * Tests whether this is a reply. 78 | * 79 | * @return whether this is a reply. 80 | */ 81 | boolean subjectIsReply(); 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/nntp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * NNTP - network news transfer protocol 20 | */ 21 | package org.apache.commons.net.nntp; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/ntp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * NTP - network time protocol 20 | */ 21 | package org.apache.commons.net.ntp; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Common socket classes and protocol command utility classes 20 | */ 21 | package org.apache.commons.net; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/pop3/POP3Reply.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.pop3; 19 | 20 | /** 21 | * POP3Reply stores POP3 reply code constants. 22 | */ 23 | 24 | public final class POP3Reply { 25 | /** The reply code indicating success of an operation. */ 26 | public static final int OK = 0; 27 | 28 | /** The reply code indicating failure of an operation. */ 29 | public static final int ERROR = 1; 30 | 31 | /** 32 | * The reply code indicating intermediate response to a command. 33 | * 34 | * @since 3.0 35 | */ 36 | public static final int OK_INT = 2; 37 | 38 | /** Cannot be instantiated. */ 39 | private POP3Reply() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/pop3/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * POP3 and POP3S mail 20 | */ 21 | package org.apache.commons.net.pop3; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/smtp/SMTPConnectionClosedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.smtp; 19 | 20 | import java.io.IOException; 21 | 22 | /** 23 | * SMTPConnectionClosedException is used to indicate the premature or unexpected closing of an SMTP connection resulting from a 24 | * {@link org.apache.commons.net.smtp.SMTPReply#SERVICE_NOT_AVAILABLE SMTPReply.SERVICE_NOT_AVAILABLE} response (SMTP reply code 421) to a failed SMTP command. 25 | * This exception is derived from IOException and therefore may be caught either as an IOException or specifically as an SMTPConnectionClosedException. 26 | * 27 | * 28 | * @see SMTP 29 | * @see SMTPClient 30 | */ 31 | public final class SMTPConnectionClosedException extends IOException { 32 | 33 | private static final long serialVersionUID = 626520434326660627L; 34 | 35 | /** Constructs a SMTPConnectionClosedException with no message */ 36 | public SMTPConnectionClosedException() { 37 | } 38 | 39 | /** 40 | * Constructs a SMTPConnectionClosedException with a specified message. 41 | * 42 | * @param message The message explaining the reason for the exception. 43 | */ 44 | public SMTPConnectionClosedException(final String message) { 45 | super(message); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/smtp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * SMTP and SMTPS mail 20 | */ 21 | package org.apache.commons.net.smtp; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/EchoOptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * Implements the Telnet echo option RFC 857. 22 | */ 23 | public class EchoOptionHandler extends TelnetOptionHandler { 24 | /** 25 | * Constructor for the EchoOptionHandler. Initial and accept behavior flags are set to false 26 | */ 27 | public EchoOptionHandler() { 28 | super(TelnetOption.ECHO, false, false, false, false); 29 | } 30 | 31 | /** 32 | * Constructor for the EchoOptionHandler. Allows defining desired initial setting for local/remote activation of this option and behavior in case a 33 | * local/remote activation request for this option is received. 34 | * 35 | * @param initlocal if set to true, a WILL is sent upon connection. 36 | * @param initremote if set to true, a DO is sent upon connection. 37 | * @param acceptlocal if set to true, any DO request is accepted. 38 | * @param acceptremote if set to true, any WILL request is accepted. 39 | */ 40 | public EchoOptionHandler(final boolean initlocal, final boolean initremote, final boolean acceptlocal, final boolean acceptremote) { 41 | super(TelnetOption.ECHO, initlocal, initremote, acceptlocal, acceptremote); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/InvalidTelnetOptionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * The InvalidTelnetOptionException is the exception that is thrown whenever a TelnetOptionHandler with an invlaid option code is registered in TelnetClient 22 | * with addOptionHandler. 23 | */ 24 | public class InvalidTelnetOptionException extends Exception { 25 | 26 | private static final long serialVersionUID = -2516777155928793597L; 27 | 28 | /** 29 | * Option code 30 | */ 31 | private final int optionCode; 32 | 33 | /** 34 | * Error message 35 | */ 36 | private final String msg; 37 | 38 | /** 39 | * Constructor for the exception. 40 | * 41 | * @param message Error message. 42 | * @param optcode Option code. 43 | */ 44 | public InvalidTelnetOptionException(final String message, final int optcode) { 45 | optionCode = optcode; 46 | msg = message; 47 | } 48 | 49 | /** 50 | * Gets the error message of the exception. 51 | * 52 | * @return the error message. 53 | */ 54 | @Override 55 | public String getMessage() { 56 | return msg + ": " + optionCode; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/SimpleOptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * Simple option handler that can be used for options that don't require subnegotiation. 22 | */ 23 | public class SimpleOptionHandler extends TelnetOptionHandler { 24 | /** 25 | * Constructor for the SimpleOptionHandler. Initial and accept behavior flags are set to false 26 | * 27 | * @param optcode option code. 28 | */ 29 | public SimpleOptionHandler(final int optcode) { 30 | super(optcode, false, false, false, false); 31 | } 32 | 33 | /** 34 | * Constructor for the SimpleOptionHandler. Allows defining desired initial setting for local/remote activation of this option and behavior in case a 35 | * local/remote activation request for this option is received. 36 | * 37 | * @param optcode option code. 38 | * @param initlocal if set to true, a WILL is sent upon connection. 39 | * @param initremote if set to true, a DO is sent upon connection. 40 | * @param acceptlocal if set to true, any DO request is accepted. 41 | * @param acceptremote if set to true, any WILL request is accepted. 42 | */ 43 | public SimpleOptionHandler(final int optcode, final boolean initlocal, final boolean initremote, final boolean acceptlocal, final boolean acceptremote) { 44 | super(optcode, initlocal, initremote, acceptlocal, acceptremote); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/SuppressGAOptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * Implements the Telnet suppress go ahead option RFC 858. 22 | */ 23 | public class SuppressGAOptionHandler extends TelnetOptionHandler { 24 | /** 25 | * Constructor for the SuppressGAOptionHandler. Initial and accept behavior flags are set to false 26 | */ 27 | public SuppressGAOptionHandler() { 28 | super(TelnetOption.SUPPRESS_GO_AHEAD, false, false, false, false); 29 | } 30 | 31 | /** 32 | * Constructor for the SuppressGAOptionHandler. Allows defining desired initial setting for local/remote activation of this option and behavior in case a 33 | * local/remote activation request for this option is received. 34 | * 35 | * @param initlocal if set to true, a WILL is sent upon connection. 36 | * @param initremote if set to true, a DO is sent upon connection. 37 | * @param acceptlocal if set to true, any DO request is accepted. 38 | * @param acceptremote if set to true, any WILL request is accepted. 39 | */ 40 | public SuppressGAOptionHandler(final boolean initlocal, final boolean initremote, final boolean acceptlocal, final boolean acceptremote) { 41 | super(TelnetOption.SUPPRESS_GO_AHEAD, initlocal, initremote, acceptlocal, acceptremote); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/TelnetInputListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * Listener interface used for notification that incoming data is available to be read. 22 | * 23 | * @see TelnetClient 24 | * @since 3.0 25 | */ 26 | public interface TelnetInputListener { 27 | 28 | /** 29 | * Callback method invoked when new incoming data is available on a {@link TelnetClient}'s {@link TelnetClient#getInputStream input stream}. 30 | * 31 | * @see TelnetClient#registerInputListener 32 | */ 33 | void telnetInputAvailable(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/TelnetNotificationHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.telnet; 19 | 20 | /** 21 | * The TelnetNotificationHandler interface can be used to handle notification of options negotiation commands received on a Telnet session. 22 | *

23 | * The user can implement this interface and register a TelnetNotificationHandler by using the registerNotificationHandler() of TelnetClient to be notified of 24 | * option negotiation commands. 25 | *

26 | */ 27 | public interface TelnetNotificationHandler { 28 | /** 29 | * The remote party sent a DO command. 30 | */ 31 | int RECEIVED_DO = 1; 32 | 33 | /** 34 | * The remote party sent a {@code DONT} command. 35 | */ 36 | int RECEIVED_DONT = 2; 37 | 38 | /** 39 | * The remote party sent a {@code WILL} command. 40 | */ 41 | int RECEIVED_WILL = 3; 42 | 43 | /** 44 | * The remote party sent a {@code WONT} command. 45 | */ 46 | int RECEIVED_WONT = 4; 47 | 48 | /** 49 | * The remote party sent a {@code COMMAND}. 50 | * 51 | * @since 2.2 52 | */ 53 | int RECEIVED_COMMAND = 5; 54 | 55 | /** 56 | * Callback method called when TelnetClient receives a command or option negotiation command 57 | * 58 | * @param negotiation_code type of (negotiation) command received (RECEIVED_DO, RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT, RECEIVED_COMMAND) 59 | * @param option_code code of the option negotiated, or the command code itself (e.g. NOP). 60 | */ 61 | void receivedNegotiation(int negotiation_code, int option_code); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/telnet/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Telnet implementation 20 | */ 21 | package org.apache.commons.net.telnet; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/tftp/TFTPPacketException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | /** 21 | * A class used to signify the occurrence of an error in the creation of a TFTP packet. It is not declared final so that it may be subclassed to identify more 22 | * specific errors. You would only want to do this if you were building your own TFTP client or server on top of the {@link org.apache.commons.net.tftp.TFTP} 23 | * class if you wanted more functionality than the {@link org.apache.commons.net.tftp.TFTPClient#receiveFile receiveFile()} and 24 | * {@link org.apache.commons.net.tftp.TFTPClient#sendFile sendFile()} methods provide. 25 | * 26 | * @see TFTPPacket 27 | * @see TFTP 28 | */ 29 | 30 | public class TFTPPacketException extends Exception { 31 | 32 | private static final long serialVersionUID = -8114699256840851439L; 33 | 34 | /** 35 | * Simply calls the corresponding constructor of its superclass. 36 | */ 37 | public TFTPPacketException() { 38 | } 39 | 40 | /** 41 | * Simply calls the corresponding constructor of its superclass. 42 | * 43 | * @param message the message 44 | */ 45 | public TFTPPacketException(final String message) { 46 | super(message); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/tftp/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * TFTP cliemt implementation 20 | */ 21 | package org.apache.commons.net.tftp; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/time/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Time protocol (RFC 868) over TCP and UDP 20 | */ 21 | package org.apache.commons.net.time; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/util/Charsets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.util; 19 | 20 | import java.nio.charset.Charset; 21 | 22 | /** 23 | * Helps to deal with Charsets. 24 | * 25 | * @since 3.3 26 | * @deprecated Use {@link org.apache.commons.io.Charsets}. 27 | */ 28 | @Deprecated 29 | public class Charsets { 30 | 31 | /** 32 | * Returns a charset object for the given charset name. 33 | * 34 | * @param charsetName The name of the requested charset; may be a canonical name, an alias, or null. If null, return the default charset. 35 | * @return A charset object for the named charset 36 | */ 37 | public static Charset toCharset(final String charsetName) { 38 | return charsetName == null ? Charset.defaultCharset() : Charset.forName(charsetName); 39 | } 40 | 41 | /** 42 | * Returns a charset object for the given charset name. 43 | * 44 | * @param charsetName The name of the requested charset; may be a canonical name, an alias, or null. If null, return the default charset. 45 | * @param defaultCharsetName the charset name to use if the requested charset is null 46 | * @return A charset object for the named charset 47 | */ 48 | public static Charset toCharset(final String charsetName, final String defaultCharsetName) { 49 | return charsetName == null ? Charset.forName(defaultCharsetName) : Charset.forName(charsetName); 50 | } 51 | 52 | /** 53 | * Depreacted. 54 | * 55 | * @deprecated Will be removed in 2.0. 56 | */ 57 | @Deprecated 58 | public Charsets() { 59 | // empty 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/util/NetConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.util; 18 | 19 | import java.security.cert.X509Certificate; 20 | 21 | /** 22 | * Constants provided as public only for our own implementation, you can consider this private for now. 23 | * 24 | * @since 3.8.0 25 | */ 26 | public class NetConstants { 27 | 28 | /** 29 | * An empty immutable {@code String} array. 30 | */ 31 | public static final String[] EMPTY_STRING_ARRAY = {}; 32 | 33 | /** 34 | * An empty immutable {@code byte} array. 35 | */ 36 | public static final byte[] EMPTY_BTYE_ARRAY = {}; 37 | 38 | /** 39 | * An empty immutable {link X509Certificate} array. 40 | */ 41 | public static final X509Certificate[] EMPTY_X509_CERTIFICATE_ARRAY = {}; 42 | 43 | /** 44 | * The index value when the end of the stream has been reached {@code -1}. 45 | * 46 | * @since 3.9.0 47 | */ 48 | public static final int EOS = -1; 49 | 50 | /** 51 | * Prevents instantiation. 52 | */ 53 | private NetConstants() { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/util/SSLSocketUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.util; 19 | 20 | import javax.net.ssl.SSLParameters; 21 | import javax.net.ssl.SSLSocket; 22 | 23 | /** 24 | * General utilities for SSLSocket. 25 | * 26 | * @since 3.4 27 | */ 28 | public class SSLSocketUtils { 29 | 30 | /** 31 | * Enable the HTTPS endpoint identification algorithm on an SSLSocket. 32 | * 33 | * @param socket the SSL socket 34 | * @return Always returns {@code true} 35 | */ 36 | // TODO for 4.0: becomes a void method. 37 | public static boolean enableEndpointNameVerification(final SSLSocket socket) { 38 | final SSLParameters sslParameters = socket.getSSLParameters(); 39 | sslParameters.setEndpointIdentificationAlgorithm("HTTPS"); 40 | socket.setSSLParameters(sslParameters); 41 | return true; 42 | } 43 | 44 | private SSLSocketUtils() { 45 | // Not instantiable 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Utility classes 20 | */ 21 | package org.apache.commons.net.util; -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/net/whois/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * Whois client 20 | */ 21 | package org.apache.commons.net.whois; -------------------------------------------------------------------------------- /src/media/net-logo-white.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-net/748f200d2ff8b6fce5f7f904c0d875338b26dfcb/src/media/net-logo-white.xcf -------------------------------------------------------------------------------- /src/site/custom/project-info-report.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one or more 3 | # contributor license agreements. See the NOTICE file distributed with 4 | # this work for additional information regarding copyright ownership. 5 | # The ASF licenses this file to You under the Apache License, Version 2.0 6 | # (the "License"); you may not use this file except in compliance with 7 | # the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | # Replace SCM report description in index page 19 | report.scm.description=This document lists ways to access the online source repository. 20 | 21 | # Replace SCM report text for viewvc section 22 | report.scm.webaccess.title=Browser (HTTP) Access 23 | report.scm.webaccess.url=The following is a link to a browsable version of the source repository. \ 24 | Please use the "Anonymous Access" or "Developer Access" URL if you want to check out the source using your SCM client. -------------------------------------------------------------------------------- /src/site/resources/download_net.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/site/resources/images/net-logo-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-net/748f200d2ff8b6fce5f7f904c0d875338b26dfcb/src/site/resources/images/net-logo-white.png -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 21 | Apache Commons Net 22 | /images/net-logo-white.png 23 | /index.html 24 | Apache Commons Net&trade; logo 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/site/xdoc/faq.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 23 | FAQ - Frequently Asked Questions 24 | Apache Commons User Mailing List 25 | 26 | 27 | 28 | 29 |
30 |

31 | This document attempts to answer some of the more frequently asked 32 | questions regarding various aspects of Commons/Net. These questions are 33 | typically asked over and over again on the mailing lists, as a 34 | courtesy to the developers, we ask that you read this document 35 | before posting to the mailing lists. 36 |

37 |

38 | The FAQ is hosted on the Commons Wiki; please see: 39 | CommonsNet/FrequentlyAskedQuestions 40 |

41 |
42 | 43 |
44 | -------------------------------------------------------------------------------- /src/site/xdoc/tasks.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 21 | Tasks 22 | Jeffrey D. Brekke 23 | Rory Winston 24 | 25 | 26 |
27 |
    28 |
  • Add more unit tests, and implement mock servers for testing
  • 29 |
  • 30 | Convert code to specified coding standards. Checkstyle report provided. 31 |
  • 32 |
  • 33 | Clean out any classes that don't belong in this project. Probably classes from 34 | org.apache.commons.net.util and org.apache.commons.net.io could be moved to their corresponding commons projects. 35 |
  • 36 |
  • 37 | Parse the client/server interactions without creating so many 38 | strings. Many operations are slow because of this. 39 |
  • 40 |
  • 41 | Add ESMTP and more extended NNTP commands. 42 |
  • 43 |
  • 44 | Make NNTPClient.listNewsgroups() and NNTPClient.listNewNews() 45 | more efficient. Don't preparse into lots of little objects. 46 |
  • 47 |
  • FTP proxy support
  • 48 |
49 |
50 | 51 |
52 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/SocketClientFunctionalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net; 18 | 19 | import java.net.InetSocketAddress; 20 | import java.net.Proxy; 21 | 22 | import org.apache.commons.net.ftp.FTPClient; 23 | 24 | import junit.framework.TestCase; 25 | 26 | /** 27 | * A simple functional test class for SocketClients. 28 | * 29 | * Requires a Java-compatible SOCK proxy server on 127.0.0.1:9050 and access to ftp.gnu.org. 30 | */ 31 | public class SocketClientFunctionalTest extends TestCase { 32 | private static final String PROXY_HOST = "127.0.0.1"; 33 | private static final int PROXY_PORT = 9050; 34 | private static final String DEST_HOST = "ftp.gnu.org"; 35 | private static final int DEST_PORT = 21; 36 | // any subclass will do, but it should be able to connect to the destination host 37 | SocketClient sc = new FTPClient(); 38 | 39 | /** 40 | * The constructor for this test case. 41 | * 42 | * @param name passed to TestCase 43 | */ 44 | public SocketClientFunctionalTest(final String name) { 45 | super(name); 46 | } 47 | 48 | /** 49 | * A simple test to verify that the Proxy settings work. 50 | * 51 | * @throws Exception in case of connection errors 52 | */ 53 | public void testProxySettings() throws Exception { 54 | // NOTE: HTTP Proxies seem to be invalid for raw sockets 55 | final Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(PROXY_HOST, PROXY_PORT)); 56 | sc.setProxy(proxy); 57 | sc.connect(DEST_HOST, DEST_PORT); 58 | assertTrue(sc.isConnected()); 59 | sc.disconnect(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/bsd/RCommandClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.bsd; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertNull; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests {@link RCommandClient}. 31 | */ 32 | public class RCommandClientTest { 33 | 34 | private RCommandClient newClient() { 35 | return new RCommandClient(); 36 | } 37 | 38 | @Test 39 | public void testConstructor() { 40 | assertDoesNotThrow(RCommandClient::new); 41 | } 42 | 43 | @Test 44 | public void testDefaultPort() { 45 | assertEquals(RCommandClient.DEFAULT_PORT, newClient().getDefaultPort()); 46 | } 47 | 48 | @Test 49 | public void testGetInputStream() throws IOException { 50 | try (InputStream inputStream = newClient().getInputStream()) { 51 | assertNull(inputStream); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/bsd/RExecClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.bsd; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertNull; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.io.OutputStream; 27 | 28 | import org.junit.jupiter.api.Test; 29 | 30 | /** 31 | * Tests {@link RExecClient}. 32 | */ 33 | public class RExecClientTest { 34 | 35 | private RExecClient newClient() { 36 | return new RExecClient(); 37 | } 38 | 39 | @Test 40 | public void testConstructor() { 41 | assertDoesNotThrow(RExecClient::new); 42 | } 43 | 44 | @Test 45 | public void testDefaultPort() { 46 | assertEquals(RExecClient.DEFAULT_PORT, newClient().getDefaultPort()); 47 | } 48 | 49 | @Test 50 | public void testGetErrorStream() throws IOException { 51 | try (InputStream inputStream = newClient().getErrorStream()) { 52 | assertNull(inputStream); 53 | } 54 | } 55 | 56 | @Test 57 | public void testGetInputStream() throws IOException { 58 | try (InputStream inputStream = newClient().getInputStream()) { 59 | assertNull(inputStream); 60 | } 61 | } 62 | 63 | @Test 64 | public void testGetOutputStream() throws IOException { 65 | try (OutputStream outputStream = newClient().getOutputStream()) { 66 | assertNull(outputStream); 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/bsd/RLoginClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.bsd; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertNull; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests {@link RLoginClient}. 31 | */ 32 | public class RLoginClientTest { 33 | 34 | private RLoginClient newClient() { 35 | return new RLoginClient(); 36 | } 37 | 38 | @Test 39 | public void testConstructor() { 40 | assertDoesNotThrow(RLoginClient::new); 41 | } 42 | 43 | @Test 44 | public void testDefaultPort() { 45 | assertEquals(RLoginClient.DEFAULT_PORT, newClient().getDefaultPort()); 46 | } 47 | 48 | @Test 49 | public void testGetInputStream() throws IOException { 50 | try (InputStream inputStream = newClient().getInputStream()) { 51 | assertNull(inputStream); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/chargen/CharGenTCPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.chargen; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertNull; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests {@link CharGenTCPClient}. 31 | */ 32 | public class CharGenTCPClientTest { 33 | 34 | @Test 35 | public void testConstructor() { 36 | assertDoesNotThrow(CharGenTCPClient::new); 37 | } 38 | 39 | @Test 40 | public void testDefaultPort() { 41 | assertEquals(CharGenTCPClient.DEFAULT_PORT, new CharGenTCPClient().getDefaultPort()); 42 | } 43 | 44 | @Test 45 | public void testGetInputStream() throws IOException { 46 | try (InputStream inputStream = new CharGenTCPClient().getInputStream()) { 47 | assertNull(inputStream); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/chargen/CharGenUDPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.chargen; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | import java.net.InetAddress; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link CharGenUDPClient}. 29 | */ 30 | public class CharGenUDPClientTest { 31 | 32 | @SuppressWarnings("resource") 33 | @Test 34 | public void testConstructor() { 35 | assertDoesNotThrow(CharGenUDPClient::new); 36 | } 37 | 38 | @Test 39 | public void testReceiver() { 40 | try (CharGenUDPClient client = new CharGenUDPClient()) { 41 | // Not connected 42 | assertThrows(NullPointerException.class, client::receive); 43 | } 44 | } 45 | 46 | @Test 47 | public void testSend() { 48 | try (CharGenUDPClient client = new CharGenUDPClient()) { 49 | // Not connected 50 | assertThrows(NullPointerException.class, () -> client.send(InetAddress.getLocalHost())); 51 | assertThrows(NullPointerException.class, () -> client.send(InetAddress.getLocalHost(), CharGenUDPClient.DEFAULT_PORT)); 52 | } 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/daytime/DaytimeUDPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.daytime; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | import java.net.InetAddress; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link DaytimeUDPClient}. 29 | */ 30 | public class DaytimeUDPClientTest { 31 | 32 | @Test 33 | public void testClose() { 34 | try (DaytimeUDPClient client = new DaytimeUDPClient()) { 35 | // empty 36 | } 37 | } 38 | 39 | @SuppressWarnings("resource") 40 | @Test 41 | public void testConstructor() { 42 | assertDoesNotThrow(DaytimeUDPClient::new); 43 | } 44 | 45 | @Test 46 | public void testGetTime() { 47 | try (DaytimeUDPClient client = new DaytimeUDPClient()) { 48 | // Not connected 49 | assertThrows(NullPointerException.class, () -> client.getTime(InetAddress.getLocalHost())); 50 | assertThrows(NullPointerException.class, () -> client.getTime(InetAddress.getLocalHost(), 0)); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/discard/DiscardTCPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.discard; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertNull; 23 | 24 | import java.io.IOException; 25 | import java.io.OutputStream; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests {@link DiscardTCPClient}. 31 | */ 32 | public class DiscardTCPClientTest { 33 | 34 | @Test 35 | public void testConstructor() { 36 | assertDoesNotThrow(DiscardTCPClient::new); 37 | } 38 | 39 | @Test 40 | public void testDefaultPort() { 41 | assertEquals(DiscardTCPClient.DEFAULT_PORT, new DiscardTCPClient().getDefaultPort()); 42 | } 43 | 44 | @Test 45 | public void testGetOutputStream() throws IOException { 46 | try (OutputStream outputStream = new DiscardTCPClient().getOutputStream()) { 47 | assertNull(outputStream); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/discard/DiscardUDPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.discard; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | import java.net.InetAddress; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link DiscardUDPClient}. 29 | */ 30 | public class DiscardUDPClientTest { 31 | 32 | @SuppressWarnings("resource") 33 | @Test 34 | public void testConstructor() { 35 | assertDoesNotThrow(DiscardUDPClient::new); 36 | } 37 | 38 | @Test 39 | public void testSend() { 40 | try (DiscardUDPClient client = new DiscardUDPClient()) { 41 | // Not connected 42 | assertThrows(NullPointerException.class, () -> client.send(new byte[0], InetAddress.getLocalHost())); 43 | assertThrows(NullPointerException.class, () -> client.send(new byte[0], 0, InetAddress.getLocalHost())); 44 | assertThrows(NullPointerException.class, () -> client.send(new byte[0], 0, InetAddress.getLocalHost(), DiscardUDPClient.DEFAULT_PORT)); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/echo/EchoTCPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.echo; 19 | 20 | import static org.junit.Assert.assertNull; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link EchoTCPClient}. 30 | */ 31 | public class EchoTCPClientTest { 32 | 33 | @Test 34 | public void testDefaultPort() { 35 | assertEquals(EchoTCPClient.DEFAULT_PORT, new EchoTCPClient().getDefaultPort()); 36 | } 37 | 38 | @Test 39 | public void testDetInputStream() throws IOException { 40 | try (InputStream inputStream = new EchoTCPClient().getInputStream()) { 41 | assertNull(inputStream); 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/echo/EchoUDPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.echo; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertThrows; 21 | 22 | import java.net.InetAddress; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * Tests {@link EchoUDPClient}. 28 | */ 29 | public class EchoUDPClientTest { 30 | 31 | @Test 32 | public void testRecieve() { 33 | try (EchoUDPClient client = new EchoUDPClient()) { 34 | // Not connected 35 | assertThrows(NullPointerException.class, () -> client.receive(new byte[0])); 36 | assertThrows(NullPointerException.class, () -> client.receive(new byte[0], 0)); 37 | } 38 | } 39 | 40 | @Test 41 | public void testSend() { 42 | try (EchoUDPClient client = new EchoUDPClient()) { 43 | // Not connected 44 | assertThrows(NullPointerException.class, () -> client.send(new byte[0], InetAddress.getLocalHost())); 45 | assertThrows(NullPointerException.class, () -> client.send(new byte[0], 0, InetAddress.getLocalHost())); 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/ftp/FTPCommandTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import junit.framework.TestCase; 21 | 22 | public class FTPCommandTest extends TestCase { 23 | 24 | public FTPCommandTest(final String name) { 25 | super(name); 26 | } 27 | 28 | @SuppressWarnings("deprecation") // test of deprecated code 29 | public void testArray() { 30 | FTPCommand.checkArray(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/ftp/GZIPSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.io.IOException; 21 | import java.io.InputStream; 22 | import java.io.OutputStream; 23 | import java.net.Socket; 24 | import java.util.zip.GZIPInputStream; 25 | import java.util.zip.GZIPOutputStream; 26 | 27 | /** 28 | * Experiment, not in an RFC? 29 | * 30 | * Wrapper class for FTP data channel sockets when compressing data in the GZIP compression format. All methods except of {@link #getInputStream()} and 31 | * {@link #getOutputStream()} are calling the delegate methods directly. 32 | */ 33 | final class GZIPSocket extends DelegateSocket { 34 | 35 | GZIPSocket(final Socket delegate) { 36 | super(delegate); 37 | } 38 | 39 | @Override 40 | public InputStream getInputStream() throws IOException { 41 | return new GZIPInputStream(delegate.getInputStream()); 42 | } 43 | 44 | @Override 45 | public OutputStream getOutputStream() throws IOException { 46 | return new GZIPOutputStream(delegate.getOutputStream()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/ftp/NoProtocolSslConfigurationProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.ftp; 19 | 20 | import java.security.GeneralSecurityException; 21 | 22 | import javax.net.ssl.SSLContext; 23 | import javax.net.ssl.SSLSocketFactory; 24 | 25 | import org.apache.ftpserver.ssl.ClientAuth; 26 | import org.apache.ftpserver.ssl.SslConfiguration; 27 | 28 | /** 29 | * Tests FTPSERVER-491. 30 | * 31 | * See 32 | * https://issues.apache.org/jira/browse/FTPSERVER-491 33 | */ 34 | public class NoProtocolSslConfigurationProxy implements SslConfiguration { 35 | 36 | private final SslConfiguration sslConfiguration; 37 | 38 | public NoProtocolSslConfigurationProxy(final SslConfiguration sslConfiguration) { 39 | this.sslConfiguration = sslConfiguration; 40 | } 41 | 42 | @Override 43 | public ClientAuth getClientAuth() { 44 | return sslConfiguration.getClientAuth(); 45 | } 46 | 47 | @Override 48 | public String[] getEnabledCipherSuites() { 49 | return sslConfiguration.getEnabledCipherSuites(); 50 | } 51 | 52 | @Override 53 | public String getEnabledProtocol() { 54 | return DEFAULT_ENABLED_PROTOCOL; 55 | } 56 | 57 | @Override 58 | public SSLSocketFactory getSocketFactory() throws GeneralSecurityException { 59 | return sslConfiguration.getSocketFactory(); 60 | } 61 | 62 | @Override 63 | public SSLContext getSSLContext() throws GeneralSecurityException { 64 | return sslConfiguration.getSSLContext(); 65 | } 66 | 67 | @Override 68 | public SSLContext getSSLContext(final String protocol) throws GeneralSecurityException { 69 | return sslConfiguration.getSSLContext(protocol); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/ftp/TestConnectTimeout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.ftp; 18 | 19 | import java.io.IOException; 20 | import java.net.ConnectException; 21 | import java.net.SocketException; 22 | import java.net.SocketTimeoutException; 23 | import java.net.UnknownHostException; 24 | 25 | import junit.framework.TestCase; 26 | 27 | /** 28 | * Test the socket connect timeout functionality 29 | */ 30 | public class TestConnectTimeout extends TestCase { 31 | 32 | public void testConnectTimeout() throws SocketException, IOException { 33 | final FTPClient client = new FTPClient(); 34 | client.setConnectTimeout(1000); 35 | 36 | try { 37 | // Connect to a valid host on a bogus port 38 | // TODO use a local server if possible 39 | client.connect("www.apache.org", 1234); 40 | fail("Expecting an Exception"); 41 | } catch (final ConnectException | SocketTimeoutException | UnknownHostException ue) { 42 | // Not much we can do about this, we may be firewalled 43 | assertTrue(true); 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/imap/AuthenticatingIMAPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.imap; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | 22 | import java.util.stream.Stream; 23 | 24 | import org.junit.jupiter.params.ParameterizedTest; 25 | import org.junit.jupiter.params.provider.Arguments; 26 | import org.junit.jupiter.params.provider.MethodSource; 27 | 28 | public class AuthenticatingIMAPClientTest { 29 | 30 | private static Stream authMethods() { 31 | return Stream.of( 32 | Arguments.of("PLAIN", AuthenticatingIMAPClient.AUTH_METHOD.PLAIN), 33 | Arguments.of("CRAM-MD5", AuthenticatingIMAPClient.AUTH_METHOD.CRAM_MD5), 34 | Arguments.of("LOGIN", AuthenticatingIMAPClient.AUTH_METHOD.LOGIN), 35 | Arguments.of("XOAUTH", AuthenticatingIMAPClient.AUTH_METHOD.XOAUTH), 36 | Arguments.of("XOAUTH2", AuthenticatingIMAPClient.AUTH_METHOD.XOAUTH2) 37 | ); 38 | } 39 | 40 | @ParameterizedTest(name = "auth method for method {1} is `{0}`") 41 | @MethodSource("authMethods") 42 | public void getAuthName(final String expectedAuthMethodName, final AuthenticatingIMAPClient.AUTH_METHOD authMethod) { 43 | assertEquals(expectedAuthMethodName, authMethod.getAuthName()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/nntp/TestThreader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.nntp; 19 | 20 | import java.util.Arrays; 21 | import java.util.List; 22 | 23 | import org.junit.Assert; 24 | import org.junit.Test; 25 | 26 | /** 27 | * Test the Threader 28 | */ 29 | public class TestThreader { 30 | 31 | private static final Threadable[] EMPTY_THREADABLE_ARRAY = {}; 32 | 33 | @SuppressWarnings("deprecation") // test of deprecated method 34 | @Test 35 | public void testEmptyArray() { // NET-539 36 | final Threader t = new Threader(); 37 | final Threadable[] messages = EMPTY_THREADABLE_ARRAY; 38 | Assert.assertNull(t.thread(messages)); 39 | } 40 | 41 | @Test 42 | public void testEmptyIterable() { // NET-539 43 | final Threader t = new Threader(); 44 | final Threadable[] messages = EMPTY_THREADABLE_ARRAY; 45 | final Iterable asList = Arrays.asList(messages); 46 | Assert.assertNull(t.thread(asList)); 47 | } 48 | 49 | @Test 50 | public void testEmptyList() { // NET-539 51 | final Threader t = new Threader(); 52 | final Threadable[] messages = EMPTY_THREADABLE_ARRAY; 53 | final List asList = Arrays.asList(messages); 54 | Assert.assertNull(t.thread(asList)); 55 | } 56 | 57 | @Test 58 | @SuppressWarnings("deprecation") // test of deprecated method 59 | public void testNullArray() { // NET-539 60 | final Threader t = new Threader(); 61 | final Threadable[] messages = null; 62 | Assert.assertNull(t.thread(messages)); 63 | } 64 | 65 | @Test 66 | public void testNullIterable() { 67 | final Threader t = new Threader(); 68 | final Iterable messages = null; 69 | Assert.assertNull(t.thread(messages)); 70 | } 71 | 72 | @Test 73 | public void testNullList() { 74 | final Threader t = new Threader(); 75 | final List messages = null; 76 | Assert.assertNull(t.thread(messages)); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/pop3/POP3Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.pop3; 18 | 19 | /** 20 | * 21 | * The POP3* tests all presume the existence of the following parameters: mailserver: localhost (running on the default port 110) account: username=test; 22 | * password=password account: username=alwaysempty; password=password. mail: At least four emails in the test account and zero emails in the alwaysempty account 23 | * 24 | * If this won't work for you, you can change these parameters in the TestSetupParameters class. 25 | * 26 | * The tests were originally run on a default installation of James. Your mileage may vary based on the POP3 server you run the tests against. Some servers are 27 | * more standards-compliant than others. 28 | */ 29 | public class POP3Constants { 30 | public static final String user = "test"; 31 | public static final String emptyuser = "alwaysempty"; 32 | public static final String password = "password"; 33 | 34 | public static final String mailhost = "localhost"; 35 | 36 | /** Cannot be instantiated. */ 37 | private POP3Constants() { 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/telnet/EchoOptionHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.telnet; 18 | 19 | /** 20 | * JUnit test class for EchoOptionHandler 21 | */ 22 | public class EchoOptionHandlerTest extends AbstractTelnetOptionHandlerTest { 23 | 24 | /** 25 | * setUp for the test. 26 | */ 27 | @Override 28 | protected void setUp() { 29 | opthand1 = new EchoOptionHandler(); 30 | opthand2 = new EchoOptionHandler(true, true, true, true); 31 | opthand3 = new EchoOptionHandler(false, false, false, false); 32 | } 33 | 34 | /** 35 | * test of server-driven subnegotiation. Checks that no subnegotiation is made. 36 | */ 37 | @Override 38 | public void testAnswerSubnegotiation() { 39 | final int[] subn = { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.ECHO, 1, TelnetCommand.IAC, TelnetCommand.SE, }; 40 | 41 | final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); 42 | 43 | assertNull(resp1); 44 | } 45 | 46 | /** 47 | * test of the constructors. 48 | */ 49 | @Override 50 | public void testConstructors() { 51 | assertEquals(opthand1.getOptionCode(), TelnetOption.ECHO); 52 | super.testConstructors(); 53 | } 54 | 55 | /** 56 | * test of client-driven subnegotiation. Checks that no subnegotiation is made. 57 | */ 58 | @Override 59 | public void testStartSubnegotiation() { 60 | final int[] resp1 = opthand1.startSubnegotiationLocal(); 61 | final int[] resp2 = opthand1.startSubnegotiationRemote(); 62 | 63 | assertNull(resp1); 64 | assertNull(resp2); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/telnet/InvalidTelnetOptionExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.telnet; 18 | 19 | import junit.framework.TestCase; 20 | 21 | /** 22 | * JUnit test class for InvalidTelnetOptionException 23 | */ 24 | public class InvalidTelnetOptionExceptionTest extends TestCase { 25 | private InvalidTelnetOptionException exc1; 26 | private String msg1; 27 | private int code1; 28 | 29 | /** 30 | * setUp for the test. 31 | */ 32 | @Override 33 | protected void setUp() { 34 | msg1 = "MSG"; 35 | code1 = 13; 36 | exc1 = new InvalidTelnetOptionException(msg1, code1); 37 | } 38 | 39 | /** 40 | * test of the constructors. 41 | */ 42 | public void testConstructors() { 43 | assertTrue(exc1.getMessage().contains(msg1)); 44 | assertTrue(exc1.getMessage().contains("" + code1)); 45 | } 46 | } -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/telnet/SimpleOptionHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.telnet; 18 | 19 | /** 20 | * JUnit test class for SimpleOptionHandler 21 | */ 22 | public class SimpleOptionHandlerTest extends AbstractTelnetOptionHandlerTest { 23 | /** 24 | * setUp for the test. 25 | */ 26 | @Override 27 | protected void setUp() { 28 | opthand1 = new SimpleOptionHandler(4); 29 | opthand2 = new SimpleOptionHandler(8, true, true, true, true); 30 | opthand3 = new SimpleOptionHandler(91, false, false, false, false); 31 | } 32 | 33 | /** 34 | * test of server-driven subnegotiation. Checks that no subnegotiation is made. 35 | */ 36 | @Override 37 | public void testAnswerSubnegotiation() { 38 | final int[] subn = { TelnetCommand.IAC, TelnetCommand.SB, 4, 1, TelnetCommand.IAC, TelnetCommand.SE, }; 39 | 40 | final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); 41 | 42 | assertNull(resp1); 43 | } 44 | 45 | /** 46 | * test of the constructors. 47 | */ 48 | @Override 49 | public void testConstructors() { 50 | assertEquals(opthand1.getOptionCode(), 4); 51 | assertEquals(opthand2.getOptionCode(), 8); 52 | assertEquals(opthand3.getOptionCode(), 91); 53 | super.testConstructors(); 54 | } 55 | 56 | /** 57 | * test of client-driven subnegotiation. Checks that no subnegotiation is made. 58 | */ 59 | @Override 60 | public void testStartSubnegotiation() { 61 | 62 | final int[] resp1 = opthand1.startSubnegotiationLocal(); 63 | final int[] resp2 = opthand1.startSubnegotiationRemote(); 64 | 65 | assertNull(resp1); 66 | assertNull(resp2); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/telnet/SuppressGAOptionHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.telnet; 18 | 19 | /** 20 | * JUnit test class for SuppressGAOptionHandler 21 | */ 22 | public class SuppressGAOptionHandlerTest extends AbstractTelnetOptionHandlerTest { 23 | 24 | /** 25 | * setUp for the test. 26 | */ 27 | @Override 28 | protected void setUp() { 29 | opthand1 = new SuppressGAOptionHandler(); 30 | opthand2 = new SuppressGAOptionHandler(true, true, true, true); 31 | opthand3 = new SuppressGAOptionHandler(false, false, false, false); 32 | } 33 | 34 | /** 35 | * test of server-driven subnegotiation. Checks that no subnegotiation is made. 36 | */ 37 | @Override 38 | public void testAnswerSubnegotiation() { 39 | final int[] subn = { TelnetCommand.IAC, TelnetCommand.SB, TelnetOption.SUPPRESS_GO_AHEAD, 1, TelnetCommand.IAC, TelnetCommand.SE, }; 40 | 41 | final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length); 42 | 43 | assertNull(resp1); 44 | } 45 | 46 | /** 47 | * test of the constructors. 48 | */ 49 | @Override 50 | public void testConstructors() { 51 | assertEquals(opthand1.getOptionCode(), TelnetOption.SUPPRESS_GO_AHEAD); 52 | super.testConstructors(); 53 | } 54 | 55 | /** 56 | * test of client-driven subnegotiation. Checks that no subnegotiation is made. 57 | */ 58 | @Override 59 | public void testStartSubnegotiation() { 60 | 61 | final int[] resp1 = opthand1.startSubnegotiationLocal(); 62 | final int[] resp2 = opthand1.startSubnegotiationRemote(); 63 | 64 | assertNull(resp1); 65 | assertNull(resp2); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/telnet/TelnetOptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.commons.net.telnet; 18 | 19 | import junit.framework.TestCase; 20 | 21 | /** 22 | * JUnit test class for TelnetOption 23 | */ 24 | public class TelnetOptionTest extends TestCase { 25 | /** 26 | * test of the getOption method. 27 | */ 28 | public void testGetOption() { 29 | assertEquals(TelnetOption.getOption(0), "BINARY"); 30 | assertEquals(TelnetOption.getOption(91), "UNASSIGNED"); 31 | assertEquals(TelnetOption.getOption(255), "Extended-Options-List"); 32 | } 33 | 34 | /** 35 | * test of the isValidOption method. 36 | */ 37 | public void testisValidOption() { 38 | assertTrue(TelnetOption.isValidOption(0)); 39 | assertTrue(TelnetOption.isValidOption(91)); 40 | assertTrue(TelnetOption.isValidOption(255)); 41 | assertFalse(TelnetOption.isValidOption(256)); 42 | } 43 | } -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/tftp/TFTPAckPacketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | 22 | import java.net.InetAddress; 23 | import java.net.UnknownHostException; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TFTPAckPacket}. 29 | */ 30 | public class TFTPAckPacketTest { 31 | 32 | @Test 33 | public void testNewDatagram() throws UnknownHostException { 34 | assertNotNull(new TFTPAckPacket(InetAddress.getLocalHost(), 0, 0).newDatagram()); 35 | } 36 | 37 | @Test 38 | public void testToString() throws UnknownHostException { 39 | assertNotNull(new TFTPAckPacket(InetAddress.getLocalHost(), 0, 0).toString()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/tftp/TFTPDataPacketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | 22 | import java.net.InetAddress; 23 | import java.net.UnknownHostException; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TFTPDataPacket}. 29 | */ 30 | public class TFTPDataPacketTest { 31 | 32 | @Test 33 | public void testNewDatagram() throws UnknownHostException { 34 | assertNotNull(new TFTPDataPacket(InetAddress.getLocalHost(), 0, 0, new byte[0]).newDatagram()); 35 | } 36 | 37 | @Test 38 | public void testToString() throws UnknownHostException { 39 | assertNotNull(new TFTPDataPacket(InetAddress.getLocalHost(), 0, 0, new byte[0]).toString()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/tftp/TFTPErrorPacketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | 22 | import java.net.InetAddress; 23 | import java.net.UnknownHostException; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TFTPErrorPacket}. 29 | */ 30 | public class TFTPErrorPacketTest { 31 | 32 | @Test 33 | public void testNewDatagram() throws UnknownHostException { 34 | assertNotNull(new TFTPErrorPacket(InetAddress.getLocalHost(), 0, 0, "").newDatagram()); 35 | } 36 | 37 | @Test 38 | public void testToString() throws UnknownHostException { 39 | assertNotNull(new TFTPErrorPacket(InetAddress.getLocalHost(), 0, 0, "").toString()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/tftp/TFTPPacketExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertNull; 22 | 23 | import org.junit.jupiter.api.Test; 24 | 25 | /** 26 | * Tests {@link TFTPPacketException}. 27 | */ 28 | public class TFTPPacketExceptionTest { 29 | 30 | @Test 31 | public void testContructor() { 32 | assertNull(new TFTPPacketException().getMessage()); 33 | assertEquals("A", new TFTPPacketException("A").getMessage()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/tftp/TFTPReadRequestPacketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | 22 | import java.net.InetAddress; 23 | import java.net.UnknownHostException; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TFTPReadRequestPacket}. 29 | */ 30 | public class TFTPReadRequestPacketTest { 31 | 32 | @Test 33 | public void testToString() throws UnknownHostException { 34 | assertNotNull(new TFTPReadRequestPacket(InetAddress.getLocalHost(), 0, "", 0).toString()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/tftp/TFTPWriteRequestPacketTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.tftp; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | 22 | import java.net.InetAddress; 23 | import java.net.UnknownHostException; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TFTPReadRequestPacket}. 29 | */ 30 | public class TFTPWriteRequestPacketTest { 31 | 32 | @Test 33 | public void testToString() throws UnknownHostException { 34 | assertNotNull(new TFTPReadRequestPacket(InetAddress.getLocalHost(), 0, "", 0).toString()); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/time/TimeUDPClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.time; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | import java.net.InetAddress; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TimeUDPClient}. 29 | */ 30 | public class TimeUDPClientTest { 31 | 32 | @Test 33 | public void testConstructor() { 34 | try (TimeUDPClient client = new TimeUDPClient()) { 35 | // empty 36 | } 37 | } 38 | 39 | @Test 40 | public void testGetDate() { 41 | try (TimeUDPClient client = new TimeUDPClient()) { 42 | // Not connected failures 43 | assertThrows(NullPointerException.class, () -> client.getDate(InetAddress.getLocalHost())); 44 | assertThrows(NullPointerException.class, () -> client.getDate(InetAddress.getLocalHost(), TimeUDPClient.DEFAULT_PORT)); 45 | } 46 | } 47 | 48 | @Test 49 | public void testGetTime() { 50 | try (TimeUDPClient client = new TimeUDPClient()) { 51 | // Not connected failures 52 | assertThrows(NullPointerException.class, () -> client.getTime(InetAddress.getLocalHost())); 53 | assertThrows(NullPointerException.class, () -> client.getTime(InetAddress.getLocalHost(), TimeUDPClient.DEFAULT_PORT)); 54 | } 55 | } 56 | 57 | @Test 58 | public void testToTime() { 59 | final byte[] timeData = new byte[4]; 60 | assertEquals(0, TimeUDPClient.toTime(timeData)); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/util/CharsetsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.util; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import java.nio.charset.StandardCharsets; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link Charsets}. 29 | */ 30 | public class CharsetsTest { 31 | 32 | @Test 33 | public void testToCharset() { 34 | assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(StandardCharsets.UTF_8.name())); 35 | } 36 | 37 | @Test 38 | public void testToCharsetDefault() { 39 | assertEquals(StandardCharsets.UTF_8, Charsets.toCharset(null, StandardCharsets.UTF_8.name())); 40 | } 41 | 42 | @SuppressWarnings("deprecation") 43 | @Test 44 | public void testToConstructor() { 45 | assertDoesNotThrow(Charsets::new); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/util/ListenerListTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.util; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertEquals; 21 | import static org.junit.jupiter.api.Assertions.assertSame; 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | import java.util.EventListener; 25 | import java.util.Iterator; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests {@link ListenerList}. 31 | */ 32 | public class ListenerListTest { 33 | 34 | static class EventListenerImpl implements EventListener { 35 | // empty 36 | } 37 | 38 | @Test 39 | public void testAdd() { 40 | final EventListenerImpl eventListenerImpl = new EventListenerImpl(); 41 | final ListenerList listenerList = new ListenerList(); 42 | listenerList.addListener(eventListenerImpl); 43 | assertEquals(1, listenerList.getListenerCount()); 44 | } 45 | 46 | @Test 47 | public void testConstructor() { 48 | assertEquals(0, new ListenerList().getListenerCount()); 49 | } 50 | 51 | @Test 52 | public void testIterator() { 53 | final EventListenerImpl eventListenerImpl = new EventListenerImpl(); 54 | final ListenerList listenerList = new ListenerList(); 55 | listenerList.addListener(eventListenerImpl); 56 | final Iterator iterator = listenerList.iterator(); 57 | assertTrue(iterator.hasNext()); 58 | assertSame(eventListenerImpl, iterator.next()); 59 | } 60 | @Test 61 | public void testRemove() { 62 | final EventListenerImpl eventListenerImpl = new EventListenerImpl(); 63 | final ListenerList listenerList = new ListenerList(); 64 | listenerList.addListener(eventListenerImpl); 65 | assertEquals(1, listenerList.getListenerCount()); 66 | listenerList.removeListener(eventListenerImpl); 67 | assertEquals(0, listenerList.getListenerCount()); 68 | listenerList.iterator(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/util/TrustManagerUtilsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.util; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertNotNull; 22 | 23 | import java.security.GeneralSecurityException; 24 | import java.security.KeyStore; 25 | import java.security.KeyStoreException; 26 | 27 | import org.junit.jupiter.api.Test; 28 | 29 | /** 30 | * Tests {@link TrustManagerUtils}. 31 | */ 32 | public class TrustManagerUtilsTest { 33 | 34 | @Test 35 | public void testGetAcceptAllTrustManager() { 36 | assertNotNull(TrustManagerUtils.getAcceptAllTrustManager()); 37 | } 38 | 39 | @Test 40 | public void testGetDefaultTrustManager() throws KeyStoreException, GeneralSecurityException { 41 | assertNotNull(TrustManagerUtils.getDefaultTrustManager(KeyStore.getInstance(KeyStore.getDefaultType()))); 42 | } 43 | 44 | @Test 45 | public void testGetValidateServerCertificateTrustManager() { 46 | assertNotNull(TrustManagerUtils.getValidateServerCertificateTrustManager()); 47 | } 48 | 49 | @SuppressWarnings("deprecation") 50 | @Test 51 | public void testToConstructor() { 52 | assertDoesNotThrow(TrustManagerUtils::new); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/net/whois/WhoisClientTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * https://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.commons.net.whois; 19 | 20 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | 23 | import java.io.IOException; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link WhoisClient}. 29 | */ 30 | public class WhoisClientTest { 31 | 32 | @Test 33 | public void testConstructor() { 34 | assertDoesNotThrow(WhoisClient::new); 35 | } 36 | 37 | @Test 38 | public void testDefaultPort() { 39 | assertEquals(WhoisClient.DEFAULT_PORT, new WhoisClient().getDefaultPort()); 40 | } 41 | 42 | @Test 43 | public void testDisconnect() throws IOException { 44 | new WhoisClient().disconnect(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/resources/org/apache/commons/net/ftpsserver/ftpserver.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-net/748f200d2ff8b6fce5f7f904c0d875338b26dfcb/src/test/resources/org/apache/commons/net/ftpsserver/ftpserver.jks -------------------------------------------------------------------------------- /src/test/resources/org/apache/commons/net/ftpsserver/users.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | # Password is "admin" 19 | ftpserver.user.admin.userpassword=21232F297A57A5A743894A0E4A801FC3 20 | ftpserver.user.admin.homedirectory=target/test-classes/org/apache/commons/net/test-data 21 | ftpserver.user.admin.enableflag=true 22 | ftpserver.user.admin.writepermission=true 23 | ftpserver.user.admin.maxloginnumber=0 24 | ftpserver.user.admin.maxloginperip=0 25 | ftpserver.user.admin.idletime=0 26 | ftpserver.user.admin.uploadrate=0 27 | ftpserver.user.admin.downloadrate=0 28 | 29 | ftpserver.user.anonymous.userpassword= 30 | ftpserver.user.anonymous.homedirectory=target/test-classes/org/apache/commons/net/test-data 31 | ftpserver.user.anonymous.enableflag=true 32 | ftpserver.user.anonymous.writepermission=false 33 | ftpserver.user.anonymous.maxloginnumber=20 34 | ftpserver.user.anonymous.maxloginperip=2 35 | ftpserver.user.anonymous.idletime=300 36 | ftpserver.user.anonymous.uploadrate=4800 37 | ftpserver.user.anonymous.downloadrate=4800 38 | 39 | # password is "test" 40 | ftpserver.user.test.userpassword=098f6bcd4621d373cade4e832627b4f6 41 | ftpserver.user.test.homedirectory=target/test-classes/org/apache/commons/net/test-data 42 | ftpserver.user.test.enableflag=true 43 | ftpserver.user.test.writepermission=true 44 | -------------------------------------------------------------------------------- /src/test/resources/org/apache/commons/net/test-data/file.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | “We are all in the gutter, but some of us are looking at the stars.” 19 | 20 | ― Oscar Wilde, Lady Windermere's Fan 21 | -------------------------------------------------------------------------------- /src/test/resources/org/apache/commons/net/test.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | a=1 17 | b=2 18 | --------------------------------------------------------------------------------