first commit
This commit is contained in:
commit
4d332ef662
27586 changed files with 3281783 additions and 0 deletions
202
rus/WEB-INF/lib/commons-net-3.3_src/META-INF/LICENSE.txt
Normal file
202
rus/WEB-INF/lib/commons-net-3.3_src/META-INF/LICENSE.txt
Normal file
|
|
@ -0,0 +1,202 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
47
rus/WEB-INF/lib/commons-net-3.3_src/META-INF/MANIFEST.MF
Normal file
47
rus/WEB-INF/lib/commons-net-3.3_src/META-INF/MANIFEST.MF
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
Manifest-Version: 1.0
|
||||
Export-Package: org.apache.commons.net.finger;version="3.3",org.apache
|
||||
.commons.net.imap;version="3.3",org.apache.commons.net.echo;version="
|
||||
3.3",org.apache.commons.net.ntp;version="3.3",org.apache.commons.net.
|
||||
discard;version="3.3",org.apache.commons.net.smtp;version="3.3",org.a
|
||||
pache.commons.net;version="3.3",org.apache.commons.net.pop3;version="
|
||||
3.3",org.apache.commons.net.telnet;version="3.3",org.apache.commons.n
|
||||
et.nntp;version="3.3",org.apache.commons.net.bsd;version="3.3",org.ap
|
||||
ache.commons.net.daytime;version="3.3",org.apache.commons.net.time;ve
|
||||
rsion="3.3",org.apache.commons.net.io;version="3.3",org.apache.common
|
||||
s.net.ftp;version="3.3",org.apache.commons.net.util;version="3.3",org
|
||||
.apache.commons.net.whois;version="3.3",org.apache.commons.net.charge
|
||||
n;version="3.3",org.apache.commons.net.ftp.parser;version="3.3",org.a
|
||||
pache.commons.net.tftp;version="3.3"
|
||||
Private-Package: examples.mail,examples.telnet,examples.cidr,examples.
|
||||
unix,examples.util,examples.nntp,examples.ntp,examples.ftp,examples
|
||||
Implementation-Title: Commons Net
|
||||
Built-By: User
|
||||
Tool: Bnd-1.50.0
|
||||
Implementation-Vendor: The Apache Software Foundation
|
||||
Implementation-Vendor-Id: org.apache
|
||||
Specification-Title: Commons Net
|
||||
Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
|
||||
Bundle-SymbolicName: org.apache.commons.net
|
||||
X-Compile-Target-JDK: 1.5
|
||||
Implementation-Version: 3.3
|
||||
Specification-Vendor: The Apache Software Foundation
|
||||
Bundle-Name: Commons Net
|
||||
Created-By: Apache Maven Bundle Plugin
|
||||
X-Compile-Source-JDK: 1.5
|
||||
Bundle-Vendor: The Apache Software Foundation
|
||||
Build-Jdk: 1.7.0_21
|
||||
Bundle-Version: 3.3.0
|
||||
Bnd-LastModified: 1370645358546
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Description: Apache Commons Net library contains a collection o
|
||||
f network utilities and protocol implementations.Supported protocols
|
||||
include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Telnet, Whoi
|
||||
s
|
||||
Bundle-DocURL: http://commons.apache.org/proper/commons-net/
|
||||
Import-Package: javax.crypto,javax.crypto.spec,javax.net,javax.net.ssl
|
||||
Include-Resource: META-INF/LICENSE.txt=LICENSE.txt,META-INF/NOTICE.txt
|
||||
=NOTICE.txt
|
||||
Specification-Version: 3.3
|
||||
Implementation-Build: trunk@r1490851; 2013-06-07 23:49:06+0100
|
||||
Archiver-Version: Plexus Archiver
|
||||
|
||||
5
rus/WEB-INF/lib/commons-net-3.3_src/META-INF/NOTICE.txt
Normal file
5
rus/WEB-INF/lib/commons-net-3.3_src/META-INF/NOTICE.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Apache Commons Net
|
||||
Copyright 2001-2013 The Apache Software Foundation
|
||||
|
||||
This product includes software developed at
|
||||
The Apache Software Foundation (http://www.apache.org/).
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#Generated by Maven
|
||||
#Fri Jun 07 23:50:38 BST 2013
|
||||
version=3.3
|
||||
groupId=commons-net
|
||||
artifactId=commons-net
|
||||
|
|
@ -0,0 +1,416 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
contributor license agreements. See the NOTICE file distributed with
|
||||
this work for additional information regarding copyright ownership.
|
||||
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
(the "License"); you may not use this file except in compliance with
|
||||
the License. You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-parent</artifactId>
|
||||
<version>30</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.3</version>
|
||||
<name>Commons Net</name>
|
||||
<!-- N.B. the description content is deliberately not indented
|
||||
! to improve the layout of the Release Notes generated by mvn changes:announcement-generate
|
||||
-->
|
||||
<description>
|
||||
Apache Commons Net library contains a collection of network utilities and protocol implementations.
|
||||
Supported protocols include: Echo, Finger, FTP, NNTP, NTP, POP3(S), SMTP(S), Telnet, Whois
|
||||
</description>
|
||||
<url>http://commons.apache.org/proper/commons-net/</url>
|
||||
<issueManagement>
|
||||
<system>jira</system>
|
||||
<url>http://issues.apache.org/jira/browse/NET</url>
|
||||
</issueManagement>
|
||||
<inceptionYear>2001</inceptionYear>
|
||||
<scm>
|
||||
<connection>scm:svn:http://svn.apache.org/repos/asf/commons/proper/net/trunk</connection>
|
||||
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/commons/proper/net/trunk</developerConnection>
|
||||
<url>http://svn.apache.org/viewvc/commons/proper/net/trunk</url>
|
||||
</scm>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Jeffrey D. Brekke</name>
|
||||
<id>brekke</id>
|
||||
<email>Jeff.Brekke@qg.com</email>
|
||||
<organization>Quad/Graphics, Inc.</organization>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Steve Cohen</name>
|
||||
<id>scohen</id>
|
||||
<email>scohen@apache.org</email>
|
||||
<organization>javactivity.org</organization>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Bruno D'Avanzo</name>
|
||||
<id>brudav</id>
|
||||
<email>bruno.davanzo@hp.com</email>
|
||||
<organization>Hewlett-Packard</organization>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Daniel F. Savarese</name>
|
||||
<id>dfs</id>
|
||||
<email>dfs@apache.org</email>
|
||||
<organization>
|
||||
<a href="http://www.savarese.com/">Savarese Software Research</a>
|
||||
</organization>
|
||||
</developer>
|
||||
<developer>
|
||||
<name>Rory Winston</name>
|
||||
<id>rwinston</id>
|
||||
<email>rwinston@apache.org</email>
|
||||
<organization />
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<contributors>
|
||||
<contributor>
|
||||
<name>Rob Hasselbaum</name>
|
||||
<email>rhasselbaum@alumni.ithaca.edu</email>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Mario Ivankovits</name>
|
||||
<email>mario@ops.co.at</email>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Tapan Karecha</name>
|
||||
<email>tapan@india.hp.com</email>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Winston Ojeda</name>
|
||||
<email>Winston.Ojeda@qg.com</email>
|
||||
<organization>Quad/Graphics, Inc.</organization>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Ted Wise</name>
|
||||
<email>ctwise@bellsouth.net</email>
|
||||
</contributor>
|
||||
<contributor>
|
||||
<name>Bogdan Drozdowski</name>
|
||||
<email>bogdandr # op dot pl</email>
|
||||
</contributor>
|
||||
</contributors>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<distributionManagement>
|
||||
<site>
|
||||
<id>apache.website</id>
|
||||
<name>Apache Commons Site</name>
|
||||
<url>${commons.deployment.protocol}://people.apache.org/www/commons.apache.org/${commons.componentid}</url>
|
||||
</site>
|
||||
</distributionManagement>
|
||||
|
||||
<properties>
|
||||
<maven.compile.source>1.5</maven.compile.source>
|
||||
<maven.compile.target>1.5</maven.compile.target>
|
||||
<commons.javadoc.java.link>http://download.oracle.com/javase/1.5.0/docs/api/</commons.javadoc.java.link>
|
||||
<commons.componentid>net</commons.componentid>
|
||||
<commons.release.version>3.3</commons.release.version>
|
||||
<commons.rc.version>RC1</commons.rc.version>
|
||||
<commons.release.desc>(Requires Java 1.5 or later)</commons.release.desc>
|
||||
<commons.release.2.version>1.4.1</commons.release.2.version>
|
||||
<!-- Override Commons parent, as version 1.4.1 does not use the -bin suffix -->
|
||||
<commons.release.2.binary.suffix />
|
||||
<commons.release.2.desc>(Requires Java 1.3 or later)</commons.release.2.desc>
|
||||
<commons.jira.id>NET</commons.jira.id>
|
||||
<commons.jira.pid>12310487</commons.jira.pid>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<!-- Exclude examples from binary jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>examples/**</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Exclude examples from source jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>examples/**</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>**/*FunctionalTest.java</exclude>
|
||||
<exclude>**/*POP3*.java</exclude>
|
||||
<!-- JUnit4 and/or Surefire does not like a class with a private constructor -->
|
||||
<exclude>**/TestSetupParameters.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/assembly/bin.xml</descriptor>
|
||||
<descriptor>src/main/assembly/src.xml</descriptor>
|
||||
</descriptors>
|
||||
<tarLongFileMode>gnu</tarLongFileMode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-antrun-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<target>
|
||||
<jar destfile="target/commons-net-ftp-${project.version}.jar">
|
||||
<metainf dir="${basedir}" includes="NOTICE.txt,LICENSE.txt" />
|
||||
<manifest>
|
||||
<attribute name="Extension-Name" value="org.apache.commons.net" />
|
||||
<attribute name="Specification-Title" value="${project.name}" />
|
||||
<attribute name="Implementation-Title" value="${project.name}" />
|
||||
<attribute name="Implementation-Vendor" value="${project.organization.name}" />
|
||||
<attribute name="Implementation-Version" value="${project.version}" />
|
||||
<attribute name="Implementation-Vendor-Id" value="org.apache" />
|
||||
<attribute name="Implementation-Build" value="${implementation.build}"/>
|
||||
<attribute name="X-Compile-Source-JDK" value="${maven.compile.source}" />
|
||||
<attribute name="X-Compile-Target-JDK" value="${maven.compile.target}" />
|
||||
</manifest>
|
||||
<fileset dir="target/classes" includes="org/apache/commons/net/ftp/**,org/apache/commons/net/*,org/apache/commons/net/io/*,org/apache/commons/net/util/*" />
|
||||
</jar>
|
||||
<!--
|
||||
Create the binary examples jar, which will be added to the binary zip/tgz,
|
||||
but not deployed independently to Maven
|
||||
-->
|
||||
<jar destfile="target/commons-net-examples-${project.version}.jar">
|
||||
<metainf dir="${basedir}" includes="NOTICE.txt,LICENSE.txt" />
|
||||
<manifest>
|
||||
<attribute name="Extension-Name" value="org.apache.commons.net" />
|
||||
<attribute name="Specification-Title" value="${project.name}" />
|
||||
<attribute name="Implementation-Title" value="${project.name}" />
|
||||
<attribute name="Implementation-Vendor" value="${project.organization.name}" />
|
||||
<attribute name="Implementation-Version" value="${project.version}" />
|
||||
<attribute name="Implementation-Vendor-Id" value="org.apache" />
|
||||
<attribute name="Implementation-Build" value="${implementation.build}"/>
|
||||
<attribute name="X-Compile-Source-JDK" value="${maven.compile.source}" />
|
||||
<attribute name="X-Compile-Target-JDK" value="${maven.compile.target}" />
|
||||
<!-- Helper application -->
|
||||
<attribute name="Main-Class" value="examples/Main" />
|
||||
<!-- Allow java -jar examples.jar to work -->
|
||||
<attribute name="Class-Path" value="commons-net-${project.version}.jar" />
|
||||
</manifest>
|
||||
<fileset dir="target/classes" includes="examples/**" />
|
||||
</jar>
|
||||
</target>
|
||||
</configuration>
|
||||
<goals>
|
||||
<goal>run</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Attaches the commons-net-ftp and examples JARs to the Maven lifecycle
|
||||
to ensure they will be signed and deployed as normal -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<version>1.7</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-artifacts</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>attach-artifact</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<artifacts>
|
||||
<artifact>
|
||||
<file>target/commons-net-ftp-${project.version}.jar</file>
|
||||
<type>jar</type>
|
||||
<classifier>ftp</classifier>
|
||||
</artifact>
|
||||
<artifact>
|
||||
<file>target/commons-net-examples-${project.version}.jar</file>
|
||||
<type>jar</type>
|
||||
<classifier>examples</classifier>
|
||||
</artifact>
|
||||
</artifacts>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- Exclude examples from Javadoc jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludePackageNames>examples.*</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Copy the examples sources -->
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>pre-site</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${basedir}/target/site/examples</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java/examples</directory>
|
||||
<excludes>
|
||||
<exclude>**/Main.java</exclude>
|
||||
</excludes>
|
||||
<filtering>false</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-scm-publish-plugin</artifactId>
|
||||
<configuration>
|
||||
<ignorePathsToDelete>
|
||||
<ignorePathToDelete>javadocs</ignorePathToDelete>
|
||||
</ignorePathsToDelete>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<reporting>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-changes-plugin</artifactId>
|
||||
<version>${commons.changes.version}</version>
|
||||
<configuration>
|
||||
<issueLinkTemplatePerSystem>
|
||||
<default>%URL%/%ISSUE%</default>
|
||||
</issueLinkTemplatePerSystem>
|
||||
<template>release-notes.vm</template>
|
||||
<templateDirectory>src/changes</templateDirectory>
|
||||
<!-- Add sample JIRA report - 'mvn changes:jira-report' or 'mvn site' -->
|
||||
<onlyCurrentVersion>false</onlyCurrentVersion>
|
||||
<columnNames>Fix Version,Key,Component,Summary,Type,Resolution,Status</columnNames>
|
||||
<!-- Sort cols have to be reversed in JIRA 4 -->
|
||||
<sortColumnNames>Key DESC,Type,Fix Version DESC</sortColumnNames>
|
||||
<resolutionIds>Fixed</resolutionIds>
|
||||
<statusIds>Resolved,Closed</statusIds>
|
||||
<!-- Don't include sub-task -->
|
||||
<typeIds>Bug,New Feature,Task,Improvement,Wish,Test</typeIds>
|
||||
<fixVersionIds>${commons.release.version}</fixVersionIds>
|
||||
<!-- The default is 100 -->
|
||||
<maxEntries>100</maxEntries>
|
||||
</configuration>
|
||||
<reportSets>
|
||||
<reportSet>
|
||||
<reports>
|
||||
<report>changes-report</report>
|
||||
<report>jira-report</report>
|
||||
</reports>
|
||||
</reportSet>
|
||||
</reportSets>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>findbugs-maven-plugin</artifactId>
|
||||
<version>2.5.2</version>
|
||||
<configuration>
|
||||
<excludeFilterFile>findbugs-exclude-filter.xml</excludeFilterFile>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>clirr-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>examples/**</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludePackageNames>examples.*</excludePackageNames>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-checkstyle-plugin</artifactId>
|
||||
<version>2.10</version>
|
||||
<configuration>
|
||||
<configLocation>${basedir}/checkstyle.xml</configLocation>
|
||||
<suppressionsLocation>${basedir}/checkstyle-suppressions.xml</suppressionsLocation>
|
||||
<enableRulesSummary>false</enableRulesSummary>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.rat</groupId>
|
||||
<artifactId>apache-rat-plugin</artifactId>
|
||||
<!-- Parent pom does not (yet) exclude these -->
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>.checkstyle</exclude>
|
||||
<exclude>.fbprefs</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</reporting>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public abstract class DatagramSocketClient {
|
||||
private static final DatagramSocketFactory __DEFAULT_SOCKET_FACTORY = new DefaultDatagramSocketFactory();
|
||||
|
||||
private Charset charset = Charset.defaultCharset();
|
||||
|
||||
protected int _timeout_;
|
||||
|
||||
protected DatagramSocket _socket_;
|
||||
|
||||
protected boolean _isOpen_;
|
||||
|
||||
protected DatagramSocketFactory _socketFactory_;
|
||||
|
||||
public DatagramSocketClient() {
|
||||
this._socket_ = null;
|
||||
this._timeout_ = 0;
|
||||
this._isOpen_ = false;
|
||||
this._socketFactory_ = __DEFAULT_SOCKET_FACTORY;
|
||||
}
|
||||
|
||||
public void open() throws SocketException {
|
||||
this._socket_ = this._socketFactory_.createDatagramSocket();
|
||||
this._socket_.setSoTimeout(this._timeout_);
|
||||
this._isOpen_ = true;
|
||||
}
|
||||
|
||||
public void open(int port) throws SocketException {
|
||||
this._socket_ = this._socketFactory_.createDatagramSocket(port);
|
||||
this._socket_.setSoTimeout(this._timeout_);
|
||||
this._isOpen_ = true;
|
||||
}
|
||||
|
||||
public void open(int port, InetAddress laddr) throws SocketException {
|
||||
this._socket_ = this._socketFactory_.createDatagramSocket(port, laddr);
|
||||
this._socket_.setSoTimeout(this._timeout_);
|
||||
this._isOpen_ = true;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (this._socket_ != null)
|
||||
this._socket_.close();
|
||||
this._socket_ = null;
|
||||
this._isOpen_ = false;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return this._isOpen_;
|
||||
}
|
||||
|
||||
public void setDefaultTimeout(int timeout) {
|
||||
this._timeout_ = timeout;
|
||||
}
|
||||
|
||||
public int getDefaultTimeout() {
|
||||
return this._timeout_;
|
||||
}
|
||||
|
||||
public void setSoTimeout(int timeout) throws SocketException {
|
||||
this._socket_.setSoTimeout(timeout);
|
||||
}
|
||||
|
||||
public int getSoTimeout() throws SocketException {
|
||||
return this._socket_.getSoTimeout();
|
||||
}
|
||||
|
||||
public int getLocalPort() {
|
||||
return this._socket_.getLocalPort();
|
||||
}
|
||||
|
||||
public InetAddress getLocalAddress() {
|
||||
return this._socket_.getLocalAddress();
|
||||
}
|
||||
|
||||
public void setDatagramSocketFactory(DatagramSocketFactory factory) {
|
||||
if (factory == null) {
|
||||
this._socketFactory_ = __DEFAULT_SOCKET_FACTORY;
|
||||
} else {
|
||||
this._socketFactory_ = factory;
|
||||
}
|
||||
}
|
||||
|
||||
public String getCharsetName() {
|
||||
return this.charset.name();
|
||||
}
|
||||
|
||||
public Charset getCharset() {
|
||||
return this.charset;
|
||||
}
|
||||
|
||||
public void setCharset(Charset charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
|
||||
public interface DatagramSocketFactory {
|
||||
DatagramSocket createDatagramSocket() throws SocketException;
|
||||
|
||||
DatagramSocket createDatagramSocket(int paramInt) throws SocketException;
|
||||
|
||||
DatagramSocket createDatagramSocket(int paramInt, InetAddress paramInetAddress) throws SocketException;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
|
||||
public class DefaultDatagramSocketFactory implements DatagramSocketFactory {
|
||||
public DatagramSocket createDatagramSocket() throws SocketException {
|
||||
return new DatagramSocket();
|
||||
}
|
||||
|
||||
public DatagramSocket createDatagramSocket(int port) throws SocketException {
|
||||
return new DatagramSocket(port);
|
||||
}
|
||||
|
||||
public DatagramSocket createDatagramSocket(int port, InetAddress laddr) throws SocketException {
|
||||
return new DatagramSocket(port, laddr);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
public class DefaultSocketFactory extends SocketFactory {
|
||||
private final Proxy connProxy;
|
||||
|
||||
public DefaultSocketFactory() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public DefaultSocketFactory(Proxy proxy) {
|
||||
this.connProxy = proxy;
|
||||
}
|
||||
|
||||
public Socket createSocket() throws IOException {
|
||||
if (this.connProxy != null)
|
||||
return new Socket(this.connProxy);
|
||||
return new Socket();
|
||||
}
|
||||
|
||||
public Socket createSocket(String host, int port) throws UnknownHostException, IOException {
|
||||
if (this.connProxy != null) {
|
||||
Socket s = new Socket(this.connProxy);
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
return s;
|
||||
}
|
||||
return new Socket(host, port);
|
||||
}
|
||||
|
||||
public Socket createSocket(InetAddress address, int port) throws IOException {
|
||||
if (this.connProxy != null) {
|
||||
Socket s = new Socket(this.connProxy);
|
||||
s.connect(new InetSocketAddress(address, port));
|
||||
return s;
|
||||
}
|
||||
return new Socket(address, port);
|
||||
}
|
||||
|
||||
public Socket createSocket(String host, int port, InetAddress localAddr, int localPort) throws UnknownHostException, IOException {
|
||||
if (this.connProxy != null) {
|
||||
Socket s = new Socket(this.connProxy);
|
||||
s.bind(new InetSocketAddress(localAddr, localPort));
|
||||
s.connect(new InetSocketAddress(host, port));
|
||||
return s;
|
||||
}
|
||||
return new Socket(host, port, localAddr, localPort);
|
||||
}
|
||||
|
||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException {
|
||||
if (this.connProxy != null) {
|
||||
Socket s = new Socket(this.connProxy);
|
||||
s.bind(new InetSocketAddress(localAddr, localPort));
|
||||
s.connect(new InetSocketAddress(address, port));
|
||||
return s;
|
||||
}
|
||||
return new Socket(address, port, localAddr, localPort);
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket(int port) throws IOException {
|
||||
return new ServerSocket(port);
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket(int port, int backlog) throws IOException {
|
||||
return new ServerSocket(port, backlog);
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException {
|
||||
return new ServerSocket(port, backlog, bindAddr);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class MalformedServerReplyException extends IOException {
|
||||
private static final long serialVersionUID = 6006765264250543945L;
|
||||
|
||||
public MalformedServerReplyException() {}
|
||||
|
||||
public MalformedServerReplyException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
public class PrintCommandListener implements ProtocolCommandListener {
|
||||
private final PrintWriter __writer;
|
||||
|
||||
private final boolean __nologin;
|
||||
|
||||
private final char __eolMarker;
|
||||
|
||||
private final boolean __directionMarker;
|
||||
|
||||
public PrintCommandListener(PrintStream stream) {
|
||||
this(new PrintWriter(stream));
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintStream stream, boolean suppressLogin) {
|
||||
this(new PrintWriter(stream), suppressLogin);
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintStream stream, boolean suppressLogin, char eolMarker) {
|
||||
this(new PrintWriter(stream), suppressLogin, eolMarker);
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintStream stream, boolean suppressLogin, char eolMarker, boolean showDirection) {
|
||||
this(new PrintWriter(stream), suppressLogin, eolMarker, showDirection);
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintWriter writer) {
|
||||
this(writer, false);
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintWriter writer, boolean suppressLogin) {
|
||||
this(writer, suppressLogin, '\000');
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintWriter writer, boolean suppressLogin, char eolMarker) {
|
||||
this(writer, suppressLogin, eolMarker, false);
|
||||
}
|
||||
|
||||
public PrintCommandListener(PrintWriter writer, boolean suppressLogin, char eolMarker, boolean showDirection) {
|
||||
this.__writer = writer;
|
||||
this.__nologin = suppressLogin;
|
||||
this.__eolMarker = eolMarker;
|
||||
this.__directionMarker = showDirection;
|
||||
}
|
||||
|
||||
public void protocolCommandSent(ProtocolCommandEvent event) {
|
||||
if (this.__directionMarker)
|
||||
this.__writer.print("> ");
|
||||
if (this.__nologin) {
|
||||
String cmd = event.getCommand();
|
||||
if ("PASS".equalsIgnoreCase(cmd) || "USER".equalsIgnoreCase(cmd)) {
|
||||
this.__writer.print(cmd);
|
||||
this.__writer.println(" *******");
|
||||
} else {
|
||||
String IMAP_LOGIN = "LOGIN";
|
||||
if ("LOGIN".equalsIgnoreCase(cmd)) {
|
||||
String msg = event.getMessage();
|
||||
msg = msg.substring(0, msg.indexOf("LOGIN") + "LOGIN".length());
|
||||
this.__writer.print(msg);
|
||||
this.__writer.println(" *******");
|
||||
} else {
|
||||
this.__writer.print(getPrintableString(event.getMessage()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.__writer.print(getPrintableString(event.getMessage()));
|
||||
}
|
||||
this.__writer.flush();
|
||||
}
|
||||
|
||||
private String getPrintableString(String msg) {
|
||||
if (this.__eolMarker == '\000')
|
||||
return msg;
|
||||
int pos = msg.indexOf("\r\n");
|
||||
if (pos > 0) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(msg.substring(0, pos));
|
||||
sb.append(this.__eolMarker);
|
||||
sb.append(msg.substring(pos));
|
||||
return sb.toString();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void protocolReplyReceived(ProtocolCommandEvent event) {
|
||||
if (this.__directionMarker)
|
||||
this.__writer.print("< ");
|
||||
this.__writer.print(event.getMessage());
|
||||
this.__writer.flush();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class ProtocolCommandEvent extends EventObject {
|
||||
private static final long serialVersionUID = 403743538418947240L;
|
||||
|
||||
private final int __replyCode;
|
||||
|
||||
private final boolean __isCommand;
|
||||
|
||||
private final String __message;
|
||||
|
||||
private final String __command;
|
||||
|
||||
public ProtocolCommandEvent(Object source, String command, String message) {
|
||||
super(source);
|
||||
this.__replyCode = 0;
|
||||
this.__message = message;
|
||||
this.__isCommand = true;
|
||||
this.__command = command;
|
||||
}
|
||||
|
||||
public ProtocolCommandEvent(Object source, int replyCode, String message) {
|
||||
super(source);
|
||||
this.__replyCode = replyCode;
|
||||
this.__message = message;
|
||||
this.__isCommand = false;
|
||||
this.__command = null;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
return this.__command;
|
||||
}
|
||||
|
||||
public int getReplyCode() {
|
||||
return this.__replyCode;
|
||||
}
|
||||
|
||||
public boolean isCommand() {
|
||||
return this.__isCommand;
|
||||
}
|
||||
|
||||
public boolean isReply() {
|
||||
return !isCommand();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.__message;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface ProtocolCommandListener extends EventListener {
|
||||
void protocolCommandSent(ProtocolCommandEvent paramProtocolCommandEvent);
|
||||
|
||||
void protocolReplyReceived(ProtocolCommandEvent paramProtocolCommandEvent);
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.EventListener;
|
||||
import org.apache.commons.net.util.ListenerList;
|
||||
|
||||
public class ProtocolCommandSupport implements Serializable {
|
||||
private static final long serialVersionUID = -8017692739988399978L;
|
||||
|
||||
private final Object __source;
|
||||
|
||||
private final ListenerList __listeners;
|
||||
|
||||
public ProtocolCommandSupport(Object source) {
|
||||
this.__listeners = new ListenerList();
|
||||
this.__source = source;
|
||||
}
|
||||
|
||||
public void fireCommandSent(String command, String message) {
|
||||
ProtocolCommandEvent event = new ProtocolCommandEvent(this.__source, command, message);
|
||||
for (EventListener listener : (Iterable<EventListener>)this.__listeners)
|
||||
((ProtocolCommandListener)listener).protocolCommandSent(event);
|
||||
}
|
||||
|
||||
public void fireReplyReceived(int replyCode, String message) {
|
||||
ProtocolCommandEvent event = new ProtocolCommandEvent(this.__source, replyCode, message);
|
||||
for (EventListener listener : (Iterable<EventListener>)this.__listeners)
|
||||
((ProtocolCommandListener)listener).protocolReplyReceived(event);
|
||||
}
|
||||
|
||||
public void addProtocolCommandListener(ProtocolCommandListener listener) {
|
||||
this.__listeners.addListener(listener);
|
||||
}
|
||||
|
||||
public void removeProtocolCommandListener(ProtocolCommandListener listener) {
|
||||
this.__listeners.removeListener(listener);
|
||||
}
|
||||
|
||||
public int getListenerCount() {
|
||||
return this.__listeners.getListenerCount();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,319 @@
|
|||
package org.apache.commons.net;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.Charset;
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.SocketFactory;
|
||||
|
||||
public abstract class SocketClient {
|
||||
public static final String NETASCII_EOL = "\r\n";
|
||||
|
||||
private static final SocketFactory __DEFAULT_SOCKET_FACTORY = SocketFactory.getDefault();
|
||||
|
||||
private static final ServerSocketFactory __DEFAULT_SERVER_SOCKET_FACTORY = ServerSocketFactory.getDefault();
|
||||
|
||||
private ProtocolCommandSupport __commandSupport;
|
||||
|
||||
protected int _timeout_;
|
||||
|
||||
protected Socket _socket_;
|
||||
|
||||
protected int _defaultPort_;
|
||||
|
||||
protected InputStream _input_;
|
||||
|
||||
protected OutputStream _output_;
|
||||
|
||||
protected SocketFactory _socketFactory_;
|
||||
|
||||
protected ServerSocketFactory _serverSocketFactory_;
|
||||
|
||||
private static final int DEFAULT_CONNECT_TIMEOUT = 0;
|
||||
|
||||
protected int connectTimeout = 0;
|
||||
|
||||
private int receiveBufferSize = -1;
|
||||
|
||||
private int sendBufferSize = -1;
|
||||
|
||||
private Proxy connProxy;
|
||||
|
||||
private Charset charset = Charset.defaultCharset();
|
||||
|
||||
public SocketClient() {
|
||||
this._socket_ = null;
|
||||
this._input_ = null;
|
||||
this._output_ = null;
|
||||
this._timeout_ = 0;
|
||||
this._defaultPort_ = 0;
|
||||
this._socketFactory_ = __DEFAULT_SOCKET_FACTORY;
|
||||
this._serverSocketFactory_ = __DEFAULT_SERVER_SOCKET_FACTORY;
|
||||
}
|
||||
|
||||
protected void _connectAction_() throws IOException {
|
||||
this._socket_.setSoTimeout(this._timeout_);
|
||||
this._input_ = this._socket_.getInputStream();
|
||||
this._output_ = this._socket_.getOutputStream();
|
||||
}
|
||||
|
||||
public void connect(InetAddress host, int port) throws SocketException, IOException {
|
||||
this._socket_ = this._socketFactory_.createSocket();
|
||||
if (this.receiveBufferSize != -1)
|
||||
this._socket_.setReceiveBufferSize(this.receiveBufferSize);
|
||||
if (this.sendBufferSize != -1)
|
||||
this._socket_.setSendBufferSize(this.sendBufferSize);
|
||||
this._socket_.connect(new InetSocketAddress(host, port), this.connectTimeout);
|
||||
_connectAction_();
|
||||
}
|
||||
|
||||
public void connect(String hostname, int port) throws SocketException, IOException {
|
||||
connect(InetAddress.getByName(hostname), port);
|
||||
}
|
||||
|
||||
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SocketException, IOException {
|
||||
this._socket_ = this._socketFactory_.createSocket();
|
||||
if (this.receiveBufferSize != -1)
|
||||
this._socket_.setReceiveBufferSize(this.receiveBufferSize);
|
||||
if (this.sendBufferSize != -1)
|
||||
this._socket_.setSendBufferSize(this.sendBufferSize);
|
||||
this._socket_.bind(new InetSocketAddress(localAddr, localPort));
|
||||
this._socket_.connect(new InetSocketAddress(host, port), this.connectTimeout);
|
||||
_connectAction_();
|
||||
}
|
||||
|
||||
public void connect(String hostname, int port, InetAddress localAddr, int localPort) throws SocketException, IOException {
|
||||
connect(InetAddress.getByName(hostname), port, localAddr, localPort);
|
||||
}
|
||||
|
||||
public void connect(InetAddress host) throws SocketException, IOException {
|
||||
connect(host, this._defaultPort_);
|
||||
}
|
||||
|
||||
public void connect(String hostname) throws SocketException, IOException {
|
||||
connect(hostname, this._defaultPort_);
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
closeQuietly(this._socket_);
|
||||
closeQuietly(this._input_);
|
||||
closeQuietly(this._output_);
|
||||
this._socket_ = null;
|
||||
this._input_ = null;
|
||||
this._output_ = null;
|
||||
}
|
||||
|
||||
private void closeQuietly(Socket socket) {
|
||||
if (socket != null)
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
private void closeQuietly(Closeable close) {
|
||||
if (close != null)
|
||||
try {
|
||||
close.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
if (this._socket_ == null)
|
||||
return false;
|
||||
return this._socket_.isConnected();
|
||||
}
|
||||
|
||||
public boolean isAvailable() {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
if (this._socket_.getInetAddress() == null)
|
||||
return false;
|
||||
if (this._socket_.getPort() == 0)
|
||||
return false;
|
||||
if (this._socket_.getRemoteSocketAddress() == null)
|
||||
return false;
|
||||
if (this._socket_.isClosed())
|
||||
return false;
|
||||
if (this._socket_.isInputShutdown())
|
||||
return false;
|
||||
if (this._socket_.isOutputShutdown())
|
||||
return false;
|
||||
this._socket_.getInputStream();
|
||||
this._socket_.getOutputStream();
|
||||
} catch (IOException ioex) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setDefaultPort(int port) {
|
||||
this._defaultPort_ = port;
|
||||
}
|
||||
|
||||
public int getDefaultPort() {
|
||||
return this._defaultPort_;
|
||||
}
|
||||
|
||||
public void setDefaultTimeout(int timeout) {
|
||||
this._timeout_ = timeout;
|
||||
}
|
||||
|
||||
public int getDefaultTimeout() {
|
||||
return this._timeout_;
|
||||
}
|
||||
|
||||
public void setSoTimeout(int timeout) throws SocketException {
|
||||
this._socket_.setSoTimeout(timeout);
|
||||
}
|
||||
|
||||
public void setSendBufferSize(int size) throws SocketException {
|
||||
this.sendBufferSize = size;
|
||||
}
|
||||
|
||||
protected int getSendBufferSize() {
|
||||
return this.sendBufferSize;
|
||||
}
|
||||
|
||||
public void setReceiveBufferSize(int size) throws SocketException {
|
||||
this.receiveBufferSize = size;
|
||||
}
|
||||
|
||||
protected int getReceiveBufferSize() {
|
||||
return this.receiveBufferSize;
|
||||
}
|
||||
|
||||
public int getSoTimeout() throws SocketException {
|
||||
return this._socket_.getSoTimeout();
|
||||
}
|
||||
|
||||
public void setTcpNoDelay(boolean on) throws SocketException {
|
||||
this._socket_.setTcpNoDelay(on);
|
||||
}
|
||||
|
||||
public boolean getTcpNoDelay() throws SocketException {
|
||||
return this._socket_.getTcpNoDelay();
|
||||
}
|
||||
|
||||
public void setKeepAlive(boolean keepAlive) throws SocketException {
|
||||
this._socket_.setKeepAlive(keepAlive);
|
||||
}
|
||||
|
||||
public boolean getKeepAlive() throws SocketException {
|
||||
return this._socket_.getKeepAlive();
|
||||
}
|
||||
|
||||
public void setSoLinger(boolean on, int val) throws SocketException {
|
||||
this._socket_.setSoLinger(on, val);
|
||||
}
|
||||
|
||||
public int getSoLinger() throws SocketException {
|
||||
return this._socket_.getSoLinger();
|
||||
}
|
||||
|
||||
public int getLocalPort() {
|
||||
return this._socket_.getLocalPort();
|
||||
}
|
||||
|
||||
public InetAddress getLocalAddress() {
|
||||
return this._socket_.getLocalAddress();
|
||||
}
|
||||
|
||||
public int getRemotePort() {
|
||||
return this._socket_.getPort();
|
||||
}
|
||||
|
||||
public InetAddress getRemoteAddress() {
|
||||
return this._socket_.getInetAddress();
|
||||
}
|
||||
|
||||
public boolean verifyRemote(Socket socket) {
|
||||
InetAddress host1 = socket.getInetAddress();
|
||||
InetAddress host2 = getRemoteAddress();
|
||||
return host1.equals(host2);
|
||||
}
|
||||
|
||||
public void setSocketFactory(SocketFactory factory) {
|
||||
if (factory == null) {
|
||||
this._socketFactory_ = __DEFAULT_SOCKET_FACTORY;
|
||||
} else {
|
||||
this._socketFactory_ = factory;
|
||||
}
|
||||
this.connProxy = null;
|
||||
}
|
||||
|
||||
public void setServerSocketFactory(ServerSocketFactory factory) {
|
||||
if (factory == null) {
|
||||
this._serverSocketFactory_ = __DEFAULT_SERVER_SOCKET_FACTORY;
|
||||
} else {
|
||||
this._serverSocketFactory_ = factory;
|
||||
}
|
||||
}
|
||||
|
||||
public void setConnectTimeout(int connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public int getConnectTimeout() {
|
||||
return this.connectTimeout;
|
||||
}
|
||||
|
||||
public ServerSocketFactory getServerSocketFactory() {
|
||||
return this._serverSocketFactory_;
|
||||
}
|
||||
|
||||
public void addProtocolCommandListener(ProtocolCommandListener listener) {
|
||||
getCommandSupport().addProtocolCommandListener(listener);
|
||||
}
|
||||
|
||||
public void removeProtocolCommandListener(ProtocolCommandListener listener) {
|
||||
getCommandSupport().removeProtocolCommandListener(listener);
|
||||
}
|
||||
|
||||
protected void fireReplyReceived(int replyCode, String reply) {
|
||||
if (getCommandSupport().getListenerCount() > 0)
|
||||
getCommandSupport().fireReplyReceived(replyCode, reply);
|
||||
}
|
||||
|
||||
protected void fireCommandSent(String command, String message) {
|
||||
if (getCommandSupport().getListenerCount() > 0)
|
||||
getCommandSupport().fireCommandSent(command, message);
|
||||
}
|
||||
|
||||
protected void createCommandSupport() {
|
||||
this.__commandSupport = new ProtocolCommandSupport(this);
|
||||
}
|
||||
|
||||
protected ProtocolCommandSupport getCommandSupport() {
|
||||
return this.__commandSupport;
|
||||
}
|
||||
|
||||
public void setProxy(Proxy proxy) {
|
||||
setSocketFactory(new DefaultSocketFactory(proxy));
|
||||
this.connProxy = proxy;
|
||||
}
|
||||
|
||||
public Proxy getProxy() {
|
||||
return this.connProxy;
|
||||
}
|
||||
|
||||
public String getCharsetName() {
|
||||
return this.charset.name();
|
||||
}
|
||||
|
||||
public Charset getCharset() {
|
||||
return this.charset;
|
||||
}
|
||||
|
||||
public void setCharset(Charset charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package org.apache.commons.net.bsd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.BindException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import org.apache.commons.net.io.SocketInputStream;
|
||||
|
||||
public class RCommandClient extends RExecClient {
|
||||
public static final int DEFAULT_PORT = 514;
|
||||
|
||||
public static final int MIN_CLIENT_PORT = 512;
|
||||
|
||||
public static final int MAX_CLIENT_PORT = 1023;
|
||||
|
||||
InputStream _createErrorStream() throws IOException {
|
||||
int localPort = 1023;
|
||||
ServerSocket server = null;
|
||||
for (localPort = 1023; localPort >= 512; localPort--) {
|
||||
try {
|
||||
server = this._serverSocketFactory_.createServerSocket(localPort, 1, getLocalAddress());
|
||||
break;
|
||||
} catch (SocketException e) {}
|
||||
}
|
||||
if (server == null)
|
||||
throw new BindException("All ports in use.");
|
||||
this._output_.write(Integer.toString(server.getLocalPort()).getBytes("UTF-8"));
|
||||
this._output_.write(0);
|
||||
this._output_.flush();
|
||||
Socket socket = server.accept();
|
||||
server.close();
|
||||
if (isRemoteVerificationEnabled() && !verifyRemote(socket)) {
|
||||
socket.close();
|
||||
throw new IOException("Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress());
|
||||
}
|
||||
return new SocketInputStream(socket, socket.getInputStream());
|
||||
}
|
||||
|
||||
public RCommandClient() {
|
||||
setDefaultPort(514);
|
||||
}
|
||||
|
||||
public void connect(InetAddress host, int port, InetAddress localAddr) throws SocketException, BindException, IOException {
|
||||
int localPort = 1023;
|
||||
for (localPort = 1023; localPort >= 512; localPort--) {
|
||||
try {
|
||||
this._socket_ = this._socketFactory_.createSocket(host, port, localAddr, localPort);
|
||||
break;
|
||||
} catch (BindException be) {
|
||||
|
||||
} catch (SocketException e) {}
|
||||
}
|
||||
if (localPort < 512)
|
||||
throw new BindException("All ports in use or insufficient permssion.");
|
||||
_connectAction_();
|
||||
}
|
||||
|
||||
public void connect(InetAddress host, int port) throws SocketException, IOException {
|
||||
connect(host, port, InetAddress.getLocalHost());
|
||||
}
|
||||
|
||||
public void connect(String hostname, int port) throws SocketException, IOException, UnknownHostException {
|
||||
connect(InetAddress.getByName(hostname), port, InetAddress.getLocalHost());
|
||||
}
|
||||
|
||||
public void connect(String hostname, int port, InetAddress localAddr) throws SocketException, IOException {
|
||||
connect(InetAddress.getByName(hostname), port, localAddr);
|
||||
}
|
||||
|
||||
public void connect(InetAddress host, int port, InetAddress localAddr, int localPort) throws SocketException, IOException, IllegalArgumentException {
|
||||
if (localPort < 512 || localPort > 1023)
|
||||
throw new IllegalArgumentException("Invalid port number " + localPort);
|
||||
super.connect(host, port, localAddr, localPort);
|
||||
}
|
||||
|
||||
public void connect(String hostname, int port, InetAddress localAddr, int localPort) throws SocketException, IOException, IllegalArgumentException, UnknownHostException {
|
||||
if (localPort < 512 || localPort > 1023)
|
||||
throw new IllegalArgumentException("Invalid port number " + localPort);
|
||||
super.connect(hostname, port, localAddr, localPort);
|
||||
}
|
||||
|
||||
public void rcommand(String localUsername, String remoteUsername, String command, boolean separateErrorStream) throws IOException {
|
||||
rexec(localUsername, remoteUsername, command, separateErrorStream);
|
||||
}
|
||||
|
||||
public void rcommand(String localUsername, String remoteUsername, String command) throws IOException {
|
||||
rcommand(localUsername, remoteUsername, command, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package org.apache.commons.net.bsd;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
import org.apache.commons.net.io.SocketInputStream;
|
||||
|
||||
public class RExecClient extends SocketClient {
|
||||
protected static final char NULL_CHAR = '\000';
|
||||
|
||||
public static final int DEFAULT_PORT = 512;
|
||||
|
||||
private boolean __remoteVerificationEnabled;
|
||||
|
||||
protected InputStream _errorStream_;
|
||||
|
||||
InputStream _createErrorStream() throws IOException {
|
||||
ServerSocket server = this._serverSocketFactory_.createServerSocket(0, 1, getLocalAddress());
|
||||
this._output_.write(Integer.toString(server.getLocalPort()).getBytes("UTF-8"));
|
||||
this._output_.write(0);
|
||||
this._output_.flush();
|
||||
Socket socket = server.accept();
|
||||
server.close();
|
||||
if (this.__remoteVerificationEnabled && !verifyRemote(socket)) {
|
||||
socket.close();
|
||||
throw new IOException("Security violation: unexpected connection attempt by " + socket.getInetAddress().getHostAddress());
|
||||
}
|
||||
return new SocketInputStream(socket, socket.getInputStream());
|
||||
}
|
||||
|
||||
public RExecClient() {
|
||||
this._errorStream_ = null;
|
||||
setDefaultPort(512);
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return this._input_;
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
return this._output_;
|
||||
}
|
||||
|
||||
public InputStream getErrorStream() {
|
||||
return this._errorStream_;
|
||||
}
|
||||
|
||||
public void rexec(String username, String password, String command, boolean separateErrorStream) throws IOException {
|
||||
if (separateErrorStream) {
|
||||
this._errorStream_ = _createErrorStream();
|
||||
} else {
|
||||
this._output_.write(0);
|
||||
}
|
||||
this._output_.write(username.getBytes(getCharsetName()));
|
||||
this._output_.write(0);
|
||||
this._output_.write(password.getBytes(getCharsetName()));
|
||||
this._output_.write(0);
|
||||
this._output_.write(command.getBytes(getCharsetName()));
|
||||
this._output_.write(0);
|
||||
this._output_.flush();
|
||||
int ch = this._input_.read();
|
||||
if (ch > 0) {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
while ((ch = this._input_.read()) != -1 && ch != 10)
|
||||
buffer.append((char)ch);
|
||||
throw new IOException(buffer.toString());
|
||||
}
|
||||
if (ch < 0)
|
||||
throw new IOException("Server closed connection.");
|
||||
}
|
||||
|
||||
public void rexec(String username, String password, String command) throws IOException {
|
||||
rexec(username, password, command, false);
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
if (this._errorStream_ != null)
|
||||
this._errorStream_.close();
|
||||
this._errorStream_ = null;
|
||||
super.disconnect();
|
||||
}
|
||||
|
||||
public final void setRemoteVerificationEnabled(boolean enable) {
|
||||
this.__remoteVerificationEnabled = enable;
|
||||
}
|
||||
|
||||
public final boolean isRemoteVerificationEnabled() {
|
||||
return this.__remoteVerificationEnabled;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package org.apache.commons.net.bsd;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RLoginClient extends RCommandClient {
|
||||
public static final int DEFAULT_PORT = 513;
|
||||
|
||||
public RLoginClient() {
|
||||
setDefaultPort(513);
|
||||
}
|
||||
|
||||
public void rlogin(String localUsername, String remoteUsername, String terminalType, int terminalSpeed) throws IOException {
|
||||
rexec(localUsername, remoteUsername, terminalType + "/" + terminalSpeed, false);
|
||||
}
|
||||
|
||||
public void rlogin(String localUsername, String remoteUsername, String terminalType) throws IOException {
|
||||
rexec(localUsername, remoteUsername, terminalType, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.apache.commons.net.chargen;
|
||||
|
||||
import java.io.InputStream;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
|
||||
public final class CharGenTCPClient extends SocketClient {
|
||||
public static final int SYSTAT_PORT = 11;
|
||||
|
||||
public static final int NETSTAT_PORT = 15;
|
||||
|
||||
public static final int QUOTE_OF_DAY_PORT = 17;
|
||||
|
||||
public static final int CHARGEN_PORT = 19;
|
||||
|
||||
public static final int DEFAULT_PORT = 19;
|
||||
|
||||
public CharGenTCPClient() {
|
||||
setDefaultPort(19);
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return this._input_;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.apache.commons.net.chargen;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import org.apache.commons.net.DatagramSocketClient;
|
||||
|
||||
public final class CharGenUDPClient extends DatagramSocketClient {
|
||||
public static final int SYSTAT_PORT = 11;
|
||||
|
||||
public static final int NETSTAT_PORT = 15;
|
||||
|
||||
public static final int QUOTE_OF_DAY_PORT = 17;
|
||||
|
||||
public static final int CHARGEN_PORT = 19;
|
||||
|
||||
public static final int DEFAULT_PORT = 19;
|
||||
|
||||
private final byte[] __receiveData = new byte[512];
|
||||
|
||||
private final DatagramPacket __receivePacket = new DatagramPacket(this.__receiveData, this.__receiveData.length);
|
||||
|
||||
private final DatagramPacket __sendPacket = new DatagramPacket(new byte[0], 0);
|
||||
|
||||
public void send(InetAddress host, int port) throws IOException {
|
||||
this.__sendPacket.setAddress(host);
|
||||
this.__sendPacket.setPort(port);
|
||||
this._socket_.send(this.__sendPacket);
|
||||
}
|
||||
|
||||
public void send(InetAddress host) throws IOException {
|
||||
send(host, 19);
|
||||
}
|
||||
|
||||
public byte[] receive() throws IOException {
|
||||
this._socket_.receive(this.__receivePacket);
|
||||
int length;
|
||||
byte[] result = new byte[length = this.__receivePacket.getLength()];
|
||||
System.arraycopy(this.__receiveData, 0, result, 0, length);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.apache.commons.net.daytime;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
|
||||
public final class DaytimeTCPClient extends SocketClient {
|
||||
public static final int DEFAULT_PORT = 13;
|
||||
|
||||
private final char[] __buffer = new char[64];
|
||||
|
||||
public DaytimeTCPClient() {
|
||||
setDefaultPort(13);
|
||||
}
|
||||
|
||||
public String getTime() throws IOException {
|
||||
StringBuilder result = new StringBuilder(this.__buffer.length);
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(this._input_, getCharsetName()));
|
||||
while (true) {
|
||||
int read = reader.read(this.__buffer, 0, this.__buffer.length);
|
||||
if (read <= 0)
|
||||
break;
|
||||
result.append(this.__buffer, 0, read);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.apache.commons.net.daytime;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import org.apache.commons.net.DatagramSocketClient;
|
||||
|
||||
public final class DaytimeUDPClient extends DatagramSocketClient {
|
||||
public static final int DEFAULT_PORT = 13;
|
||||
|
||||
private final byte[] __dummyData = new byte[1];
|
||||
|
||||
private final byte[] __timeData = new byte[256];
|
||||
|
||||
public String getTime(InetAddress host, int port) throws IOException {
|
||||
DatagramPacket sendPacket = new DatagramPacket(this.__dummyData, this.__dummyData.length, host, port);
|
||||
DatagramPacket receivePacket = new DatagramPacket(this.__timeData, this.__timeData.length);
|
||||
this._socket_.send(sendPacket);
|
||||
this._socket_.receive(receivePacket);
|
||||
return new String(receivePacket.getData(), 0, receivePacket.getLength(), getCharsetName());
|
||||
}
|
||||
|
||||
public String getTime(InetAddress host) throws IOException {
|
||||
return getTime(host, 13);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.commons.net.discard;
|
||||
|
||||
import java.io.OutputStream;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
|
||||
public class DiscardTCPClient extends SocketClient {
|
||||
public static final int DEFAULT_PORT = 9;
|
||||
|
||||
public DiscardTCPClient() {
|
||||
setDefaultPort(9);
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
return this._output_;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.apache.commons.net.discard;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import org.apache.commons.net.DatagramSocketClient;
|
||||
|
||||
public class DiscardUDPClient extends DatagramSocketClient {
|
||||
public static final int DEFAULT_PORT = 9;
|
||||
|
||||
DatagramPacket _sendPacket = new DatagramPacket(new byte[0], 0);
|
||||
|
||||
public void send(byte[] data, int length, InetAddress host, int port) throws IOException {
|
||||
this._sendPacket.setData(data);
|
||||
this._sendPacket.setLength(length);
|
||||
this._sendPacket.setAddress(host);
|
||||
this._sendPacket.setPort(port);
|
||||
this._socket_.send(this._sendPacket);
|
||||
}
|
||||
|
||||
public void send(byte[] data, int length, InetAddress host) throws IOException {
|
||||
send(data, length, host, 9);
|
||||
}
|
||||
|
||||
public void send(byte[] data, InetAddress host) throws IOException {
|
||||
send(data, data.length, host, 9);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.apache.commons.net.echo;
|
||||
|
||||
import java.io.InputStream;
|
||||
import org.apache.commons.net.discard.DiscardTCPClient;
|
||||
|
||||
public final class EchoTCPClient extends DiscardTCPClient {
|
||||
public static final int DEFAULT_PORT = 7;
|
||||
|
||||
public EchoTCPClient() {
|
||||
setDefaultPort(7);
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
return this._input_;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package org.apache.commons.net.echo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.InetAddress;
|
||||
import org.apache.commons.net.discard.DiscardUDPClient;
|
||||
|
||||
public final class EchoUDPClient extends DiscardUDPClient {
|
||||
public static final int DEFAULT_PORT = 7;
|
||||
|
||||
private final DatagramPacket __receivePacket = new DatagramPacket(new byte[0], 0);
|
||||
|
||||
public void send(byte[] data, int length, InetAddress host) throws IOException {
|
||||
send(data, length, host, 7);
|
||||
}
|
||||
|
||||
public void send(byte[] data, InetAddress host) throws IOException {
|
||||
send(data, data.length, host, 7);
|
||||
}
|
||||
|
||||
public int receive(byte[] data, int length) throws IOException {
|
||||
this.__receivePacket.setData(data);
|
||||
this.__receivePacket.setLength(length);
|
||||
this._socket_.receive(this.__receivePacket);
|
||||
return this.__receivePacket.getLength();
|
||||
}
|
||||
|
||||
public int receive(byte[] data) throws IOException {
|
||||
return receive(data, data.length);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package org.apache.commons.net.finger;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
import org.apache.commons.net.util.Charsets;
|
||||
|
||||
public class FingerClient extends SocketClient {
|
||||
public static final int DEFAULT_PORT = 79;
|
||||
|
||||
private static final String __LONG_FLAG = "/W ";
|
||||
|
||||
private transient char[] __buffer = new char[1024];
|
||||
|
||||
public FingerClient() {
|
||||
setDefaultPort(79);
|
||||
}
|
||||
|
||||
public String query(boolean longOutput, String username) throws IOException {
|
||||
StringBuilder result = new StringBuilder(this.__buffer.length);
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(getInputStream(longOutput, username), getCharsetName()));
|
||||
try {
|
||||
while (true) {
|
||||
int read = input.read(this.__buffer, 0, this.__buffer.length);
|
||||
if (read <= 0)
|
||||
break;
|
||||
result.append(this.__buffer, 0, read);
|
||||
}
|
||||
} finally {
|
||||
input.close();
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public String query(boolean longOutput) throws IOException {
|
||||
return query(longOutput, "");
|
||||
}
|
||||
|
||||
public InputStream getInputStream(boolean longOutput, String username) throws IOException {
|
||||
return getInputStream(longOutput, username, null);
|
||||
}
|
||||
|
||||
public InputStream getInputStream(boolean longOutput, String username, String encoding) throws IOException {
|
||||
StringBuilder buffer = new StringBuilder(64);
|
||||
if (longOutput)
|
||||
buffer.append("/W ");
|
||||
buffer.append(username);
|
||||
buffer.append("\r\n");
|
||||
byte[] encodedQuery = buffer.toString().getBytes(Charsets.toCharset(encoding).name());
|
||||
DataOutputStream output = new DataOutputStream(new BufferedOutputStream(this._output_, 1024));
|
||||
output.write(encodedQuery, 0, encodedQuery.length);
|
||||
output.flush();
|
||||
return this._input_;
|
||||
}
|
||||
|
||||
public InputStream getInputStream(boolean longOutput) throws IOException {
|
||||
return getInputStream(longOutput, "");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
public interface Configurable {
|
||||
void configure(FTPClientConfig paramFTPClientConfig);
|
||||
}
|
||||
|
|
@ -0,0 +1,493 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.SocketException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.ArrayList;
|
||||
import org.apache.commons.net.MalformedServerReplyException;
|
||||
import org.apache.commons.net.ProtocolCommandSupport;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
import org.apache.commons.net.io.CRLFLineReader;
|
||||
|
||||
public class FTP extends SocketClient {
|
||||
public static final int DEFAULT_DATA_PORT = 20;
|
||||
|
||||
public static final int DEFAULT_PORT = 21;
|
||||
|
||||
public static final int ASCII_FILE_TYPE = 0;
|
||||
|
||||
public static final int EBCDIC_FILE_TYPE = 1;
|
||||
|
||||
public static final int BINARY_FILE_TYPE = 2;
|
||||
|
||||
public static final int LOCAL_FILE_TYPE = 3;
|
||||
|
||||
public static final int NON_PRINT_TEXT_FORMAT = 4;
|
||||
|
||||
public static final int TELNET_TEXT_FORMAT = 5;
|
||||
|
||||
public static final int CARRIAGE_CONTROL_TEXT_FORMAT = 6;
|
||||
|
||||
public static final int FILE_STRUCTURE = 7;
|
||||
|
||||
public static final int RECORD_STRUCTURE = 8;
|
||||
|
||||
public static final int PAGE_STRUCTURE = 9;
|
||||
|
||||
public static final int STREAM_TRANSFER_MODE = 10;
|
||||
|
||||
public static final int BLOCK_TRANSFER_MODE = 11;
|
||||
|
||||
public static final int COMPRESSED_TRANSFER_MODE = 12;
|
||||
|
||||
public static final String DEFAULT_CONTROL_ENCODING = "ISO-8859-1";
|
||||
|
||||
public static final int REPLY_CODE_LEN = 3;
|
||||
|
||||
private static final String __modes = "AEILNTCFRPSBC";
|
||||
|
||||
protected int _replyCode;
|
||||
|
||||
protected ArrayList<String> _replyLines;
|
||||
|
||||
protected boolean _newReplyString;
|
||||
|
||||
protected String _replyString;
|
||||
|
||||
protected String _controlEncoding;
|
||||
|
||||
protected ProtocolCommandSupport _commandSupport_;
|
||||
|
||||
protected boolean strictMultilineParsing = false;
|
||||
|
||||
protected BufferedReader _controlInput_;
|
||||
|
||||
protected BufferedWriter _controlOutput_;
|
||||
|
||||
public FTP() {
|
||||
setDefaultPort(21);
|
||||
this._replyLines = new ArrayList<String>();
|
||||
this._newReplyString = false;
|
||||
this._replyString = null;
|
||||
this._controlEncoding = "ISO-8859-1";
|
||||
this._commandSupport_ = new ProtocolCommandSupport(this);
|
||||
}
|
||||
|
||||
private boolean __strictCheck(String line, String code) {
|
||||
return (!line.startsWith(code) || line.charAt(3) != ' ');
|
||||
}
|
||||
|
||||
private boolean __lenientCheck(String line) {
|
||||
return (line.length() <= 3 || line.charAt(3) == '-' || !Character.isDigit(line.charAt(0)));
|
||||
}
|
||||
|
||||
private void __getReply() throws IOException {
|
||||
__getReply(true);
|
||||
}
|
||||
|
||||
protected void __getReplyNoReport() throws IOException {
|
||||
__getReply(false);
|
||||
}
|
||||
|
||||
private void __getReply(boolean reportReply) throws IOException {
|
||||
this._newReplyString = true;
|
||||
this._replyLines.clear();
|
||||
String line = this._controlInput_.readLine();
|
||||
if (line == null)
|
||||
throw new FTPConnectionClosedException("Connection closed without indication.");
|
||||
int length = line.length();
|
||||
if (length < 3)
|
||||
throw new MalformedServerReplyException("Truncated server reply: " + line);
|
||||
String code = null;
|
||||
try {
|
||||
code = line.substring(0, 3);
|
||||
this._replyCode = Integer.parseInt(code);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new MalformedServerReplyException("Could not parse response code.\nServer Reply: " + line);
|
||||
}
|
||||
this._replyLines.add(line);
|
||||
if (length > 3 && line.charAt(3) == '-')
|
||||
while (true) {
|
||||
line = this._controlInput_.readLine();
|
||||
if (line == null)
|
||||
throw new FTPConnectionClosedException("Connection closed without indication.");
|
||||
this._replyLines.add(line);
|
||||
if (isStrictMultilineParsing() ? __strictCheck(line, code) : __lenientCheck(line))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
fireReplyReceived(this._replyCode, getReplyString());
|
||||
if (this._replyCode == 421)
|
||||
throw new FTPConnectionClosedException("FTP response 421 received. Server closed connection.");
|
||||
}
|
||||
|
||||
protected void _connectAction_() throws IOException {
|
||||
super._connectAction_();
|
||||
this._controlInput_ = new CRLFLineReader(new InputStreamReader(this._input_, getControlEncoding()));
|
||||
this._controlOutput_ = new BufferedWriter(new OutputStreamWriter(this._output_, getControlEncoding()));
|
||||
if (this.connectTimeout > 0) {
|
||||
int original = this._socket_.getSoTimeout();
|
||||
this._socket_.setSoTimeout(this.connectTimeout);
|
||||
try {
|
||||
__getReply();
|
||||
if (FTPReply.isPositivePreliminary(this._replyCode))
|
||||
__getReply();
|
||||
} catch (SocketTimeoutException e) {
|
||||
IOException ioe = new IOException("Timed out waiting for initial connect reply");
|
||||
ioe.initCause(e);
|
||||
throw ioe;
|
||||
} finally {
|
||||
this._socket_.setSoTimeout(original);
|
||||
}
|
||||
} else {
|
||||
__getReply();
|
||||
if (FTPReply.isPositivePreliminary(this._replyCode))
|
||||
__getReply();
|
||||
}
|
||||
}
|
||||
|
||||
public void setControlEncoding(String encoding) {
|
||||
this._controlEncoding = encoding;
|
||||
}
|
||||
|
||||
public String getControlEncoding() {
|
||||
return this._controlEncoding;
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
super.disconnect();
|
||||
this._controlInput_ = null;
|
||||
this._controlOutput_ = null;
|
||||
this._newReplyString = false;
|
||||
this._replyString = null;
|
||||
}
|
||||
|
||||
public int sendCommand(String command, String args) throws IOException {
|
||||
if (this._controlOutput_ == null)
|
||||
throw new IOException("Connection is not open");
|
||||
String message = __buildMessage(command, args);
|
||||
__send(message);
|
||||
fireCommandSent(command, message);
|
||||
__getReply();
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
private String __buildMessage(String command, String args) {
|
||||
StringBuilder __commandBuffer = new StringBuilder();
|
||||
__commandBuffer.append(command);
|
||||
if (args != null) {
|
||||
__commandBuffer.append(' ');
|
||||
__commandBuffer.append(args);
|
||||
}
|
||||
__commandBuffer.append("\r\n");
|
||||
return __commandBuffer.toString();
|
||||
}
|
||||
|
||||
private void __send(String message) throws IOException, FTPConnectionClosedException, SocketException {
|
||||
try {
|
||||
this._controlOutput_.write(message);
|
||||
this._controlOutput_.flush();
|
||||
} catch (SocketException e) {
|
||||
if (!isConnected())
|
||||
throw new FTPConnectionClosedException("Connection unexpectedly closed.");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
protected void __noop() throws IOException {
|
||||
String msg = __buildMessage(FTPCmd.NOOP.getCommand(), null);
|
||||
__send(msg);
|
||||
__getReplyNoReport();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int sendCommand(int command, String args) throws IOException {
|
||||
return sendCommand(FTPCommand.getCommand(command), args);
|
||||
}
|
||||
|
||||
public int sendCommand(FTPCmd command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public int sendCommand(FTPCmd command, String args) throws IOException {
|
||||
return sendCommand(command.getCommand(), args);
|
||||
}
|
||||
|
||||
public int sendCommand(String command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public int sendCommand(int command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public int getReplyCode() {
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
public int getReply() throws IOException {
|
||||
__getReply();
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
public String[] getReplyStrings() {
|
||||
return this._replyLines.<String>toArray(new String[this._replyLines.size()]);
|
||||
}
|
||||
|
||||
public String getReplyString() {
|
||||
if (!this._newReplyString)
|
||||
return this._replyString;
|
||||
StringBuilder buffer = new StringBuilder(256);
|
||||
for (String line : this._replyLines) {
|
||||
buffer.append(line);
|
||||
buffer.append("\r\n");
|
||||
}
|
||||
this._newReplyString = false;
|
||||
return this._replyString = buffer.toString();
|
||||
}
|
||||
|
||||
public int user(String username) throws IOException {
|
||||
return sendCommand(FTPCmd.USER, username);
|
||||
}
|
||||
|
||||
public int pass(String password) throws IOException {
|
||||
return sendCommand(FTPCmd.PASS, password);
|
||||
}
|
||||
|
||||
public int acct(String account) throws IOException {
|
||||
return sendCommand(FTPCmd.ACCT, account);
|
||||
}
|
||||
|
||||
public int abor() throws IOException {
|
||||
return sendCommand(FTPCmd.ABOR);
|
||||
}
|
||||
|
||||
public int cwd(String directory) throws IOException {
|
||||
return sendCommand(FTPCmd.CWD, directory);
|
||||
}
|
||||
|
||||
public int cdup() throws IOException {
|
||||
return sendCommand(FTPCmd.CDUP);
|
||||
}
|
||||
|
||||
public int quit() throws IOException {
|
||||
return sendCommand(FTPCmd.QUIT);
|
||||
}
|
||||
|
||||
public int rein() throws IOException {
|
||||
return sendCommand(FTPCmd.REIN);
|
||||
}
|
||||
|
||||
public int smnt(String dir) throws IOException {
|
||||
return sendCommand(FTPCmd.SMNT, dir);
|
||||
}
|
||||
|
||||
public int port(InetAddress host, int port) throws IOException {
|
||||
StringBuilder info = new StringBuilder(24);
|
||||
info.append(host.getHostAddress().replace('.', ','));
|
||||
int num = port >>> 8;
|
||||
info.append(',');
|
||||
info.append(num);
|
||||
info.append(',');
|
||||
num = port & 0xFF;
|
||||
info.append(num);
|
||||
return sendCommand(FTPCmd.PORT, info.toString());
|
||||
}
|
||||
|
||||
public int eprt(InetAddress host, int port) throws IOException {
|
||||
StringBuilder info = new StringBuilder();
|
||||
String h = host.getHostAddress();
|
||||
int num = h.indexOf("%");
|
||||
if (num > 0)
|
||||
h = h.substring(0, num);
|
||||
info.append("|");
|
||||
if (host instanceof java.net.Inet4Address) {
|
||||
info.append("1");
|
||||
} else if (host instanceof java.net.Inet6Address) {
|
||||
info.append("2");
|
||||
}
|
||||
info.append("|");
|
||||
info.append(h);
|
||||
info.append("|");
|
||||
info.append(port);
|
||||
info.append("|");
|
||||
return sendCommand(FTPCmd.EPRT, info.toString());
|
||||
}
|
||||
|
||||
public int pasv() throws IOException {
|
||||
return sendCommand(FTPCmd.PASV);
|
||||
}
|
||||
|
||||
public int epsv() throws IOException {
|
||||
return sendCommand(FTPCmd.EPSV);
|
||||
}
|
||||
|
||||
public int type(int fileType, int formatOrByteSize) throws IOException {
|
||||
StringBuilder arg = new StringBuilder();
|
||||
arg.append("AEILNTCFRPSBC".charAt(fileType));
|
||||
arg.append(' ');
|
||||
if (fileType == 3) {
|
||||
arg.append(formatOrByteSize);
|
||||
} else {
|
||||
arg.append("AEILNTCFRPSBC".charAt(formatOrByteSize));
|
||||
}
|
||||
return sendCommand(FTPCmd.TYPE, arg.toString());
|
||||
}
|
||||
|
||||
public int type(int fileType) throws IOException {
|
||||
return sendCommand(FTPCmd.TYPE, "AEILNTCFRPSBC".substring(fileType, fileType + 1));
|
||||
}
|
||||
|
||||
public int stru(int structure) throws IOException {
|
||||
return sendCommand(FTPCmd.STRU, "AEILNTCFRPSBC".substring(structure, structure + 1));
|
||||
}
|
||||
|
||||
public int mode(int mode) throws IOException {
|
||||
return sendCommand(FTPCmd.MODE, "AEILNTCFRPSBC".substring(mode, mode + 1));
|
||||
}
|
||||
|
||||
public int retr(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.RETR, pathname);
|
||||
}
|
||||
|
||||
public int stor(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.STOR, pathname);
|
||||
}
|
||||
|
||||
public int stou() throws IOException {
|
||||
return sendCommand(FTPCmd.STOU);
|
||||
}
|
||||
|
||||
public int stou(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.STOU, pathname);
|
||||
}
|
||||
|
||||
public int appe(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.APPE, pathname);
|
||||
}
|
||||
|
||||
public int allo(int bytes) throws IOException {
|
||||
return sendCommand(FTPCmd.ALLO, Integer.toString(bytes));
|
||||
}
|
||||
|
||||
public int feat() throws IOException {
|
||||
return sendCommand(FTPCmd.FEAT);
|
||||
}
|
||||
|
||||
public int allo(int bytes, int recordSize) throws IOException {
|
||||
return sendCommand(FTPCmd.ALLO, Integer.toString(bytes) + " R " + Integer.toString(recordSize));
|
||||
}
|
||||
|
||||
public int rest(String marker) throws IOException {
|
||||
return sendCommand(FTPCmd.REST, marker);
|
||||
}
|
||||
|
||||
public int mdtm(String file) throws IOException {
|
||||
return sendCommand(FTPCmd.MDTM, file);
|
||||
}
|
||||
|
||||
public int mfmt(String pathname, String timeval) throws IOException {
|
||||
return sendCommand(FTPCmd.MFMT, timeval + " " + pathname);
|
||||
}
|
||||
|
||||
public int rnfr(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.RNFR, pathname);
|
||||
}
|
||||
|
||||
public int rnto(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.RNTO, pathname);
|
||||
}
|
||||
|
||||
public int dele(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.DELE, pathname);
|
||||
}
|
||||
|
||||
public int rmd(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.RMD, pathname);
|
||||
}
|
||||
|
||||
public int mkd(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.MKD, pathname);
|
||||
}
|
||||
|
||||
public int pwd() throws IOException {
|
||||
return sendCommand(FTPCmd.PWD);
|
||||
}
|
||||
|
||||
public int list() throws IOException {
|
||||
return sendCommand(FTPCmd.LIST);
|
||||
}
|
||||
|
||||
public int list(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.LIST, pathname);
|
||||
}
|
||||
|
||||
public int mlsd() throws IOException {
|
||||
return sendCommand(FTPCmd.MLSD);
|
||||
}
|
||||
|
||||
public int mlsd(String path) throws IOException {
|
||||
return sendCommand(FTPCmd.MLSD, path);
|
||||
}
|
||||
|
||||
public int mlst() throws IOException {
|
||||
return sendCommand(FTPCmd.MLST);
|
||||
}
|
||||
|
||||
public int mlst(String path) throws IOException {
|
||||
return sendCommand(FTPCmd.MLST, path);
|
||||
}
|
||||
|
||||
public int nlst() throws IOException {
|
||||
return sendCommand(FTPCmd.NLST);
|
||||
}
|
||||
|
||||
public int nlst(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.NLST, pathname);
|
||||
}
|
||||
|
||||
public int site(String parameters) throws IOException {
|
||||
return sendCommand(FTPCmd.SITE, parameters);
|
||||
}
|
||||
|
||||
public int syst() throws IOException {
|
||||
return sendCommand(FTPCmd.SYST);
|
||||
}
|
||||
|
||||
public int stat() throws IOException {
|
||||
return sendCommand(FTPCmd.STAT);
|
||||
}
|
||||
|
||||
public int stat(String pathname) throws IOException {
|
||||
return sendCommand(FTPCmd.STAT, pathname);
|
||||
}
|
||||
|
||||
public int help() throws IOException {
|
||||
return sendCommand(FTPCmd.HELP);
|
||||
}
|
||||
|
||||
public int help(String command) throws IOException {
|
||||
return sendCommand(FTPCmd.HELP, command);
|
||||
}
|
||||
|
||||
public int noop() throws IOException {
|
||||
return sendCommand(FTPCmd.NOOP);
|
||||
}
|
||||
|
||||
public boolean isStrictMultilineParsing() {
|
||||
return this.strictMultilineParsing;
|
||||
}
|
||||
|
||||
public void setStrictMultilineParsing(boolean strictMultilineParsing) {
|
||||
this.strictMultilineParsing = strictMultilineParsing;
|
||||
}
|
||||
|
||||
protected ProtocolCommandSupport getCommandSupport() {
|
||||
return this._commandSupport_;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,168 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class FTPClientConfig {
|
||||
public static final String SYST_UNIX = "UNIX";
|
||||
|
||||
public static final String SYST_VMS = "VMS";
|
||||
|
||||
public static final String SYST_NT = "WINDOWS";
|
||||
|
||||
public static final String SYST_OS2 = "OS/2";
|
||||
|
||||
public static final String SYST_OS400 = "OS/400";
|
||||
|
||||
public static final String SYST_AS400 = "AS/400";
|
||||
|
||||
public static final String SYST_MVS = "MVS";
|
||||
|
||||
public static final String SYST_L8 = "TYPE: L8";
|
||||
|
||||
public static final String SYST_NETWARE = "NETWARE";
|
||||
|
||||
public static final String SYST_MACOS_PETER = "MACOS PETER";
|
||||
|
||||
private final String serverSystemKey;
|
||||
|
||||
private String defaultDateFormatStr = null;
|
||||
|
||||
private String recentDateFormatStr = null;
|
||||
|
||||
private boolean lenientFutureDates = true;
|
||||
|
||||
private String serverLanguageCode = null;
|
||||
|
||||
private String shortMonthNames = null;
|
||||
|
||||
private String serverTimeZoneId = null;
|
||||
|
||||
public FTPClientConfig(String systemKey) {
|
||||
this.serverSystemKey = systemKey;
|
||||
}
|
||||
|
||||
public FTPClientConfig() {
|
||||
this("UNIX");
|
||||
}
|
||||
|
||||
public FTPClientConfig(String systemKey, String defaultDateFormatStr, String recentDateFormatStr, String serverLanguageCode, String shortMonthNames, String serverTimeZoneId) {
|
||||
this(systemKey);
|
||||
this.defaultDateFormatStr = defaultDateFormatStr;
|
||||
this.recentDateFormatStr = recentDateFormatStr;
|
||||
this.serverLanguageCode = serverLanguageCode;
|
||||
this.shortMonthNames = shortMonthNames;
|
||||
this.serverTimeZoneId = serverTimeZoneId;
|
||||
}
|
||||
|
||||
private static final Map<String, Object> LANGUAGE_CODE_MAP = new TreeMap<String, Object>();
|
||||
|
||||
static {
|
||||
LANGUAGE_CODE_MAP.put("en", Locale.ENGLISH);
|
||||
LANGUAGE_CODE_MAP.put("de", Locale.GERMAN);
|
||||
LANGUAGE_CODE_MAP.put("it", Locale.ITALIAN);
|
||||
LANGUAGE_CODE_MAP.put("es", new Locale("es", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("pt", new Locale("pt", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("da", new Locale("da", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("sv", new Locale("sv", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("no", new Locale("no", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("nl", new Locale("nl", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("ro", new Locale("ro", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("sq", new Locale("sq", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("sh", new Locale("sh", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("sk", new Locale("sk", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("sl", new Locale("sl", "", ""));
|
||||
LANGUAGE_CODE_MAP.put("fr", "jan|fév|mar|avr|mai|jun|jui|aoû|sep|oct|nov|déc");
|
||||
}
|
||||
|
||||
public String getServerSystemKey() {
|
||||
return this.serverSystemKey;
|
||||
}
|
||||
|
||||
public String getDefaultDateFormatStr() {
|
||||
return this.defaultDateFormatStr;
|
||||
}
|
||||
|
||||
public String getRecentDateFormatStr() {
|
||||
return this.recentDateFormatStr;
|
||||
}
|
||||
|
||||
public String getServerTimeZoneId() {
|
||||
return this.serverTimeZoneId;
|
||||
}
|
||||
|
||||
public String getShortMonthNames() {
|
||||
return this.shortMonthNames;
|
||||
}
|
||||
|
||||
public String getServerLanguageCode() {
|
||||
return this.serverLanguageCode;
|
||||
}
|
||||
|
||||
public boolean isLenientFutureDates() {
|
||||
return this.lenientFutureDates;
|
||||
}
|
||||
|
||||
public void setDefaultDateFormatStr(String defaultDateFormatStr) {
|
||||
this.defaultDateFormatStr = defaultDateFormatStr;
|
||||
}
|
||||
|
||||
public void setRecentDateFormatStr(String recentDateFormatStr) {
|
||||
this.recentDateFormatStr = recentDateFormatStr;
|
||||
}
|
||||
|
||||
public void setLenientFutureDates(boolean lenientFutureDates) {
|
||||
this.lenientFutureDates = lenientFutureDates;
|
||||
}
|
||||
|
||||
public void setServerTimeZoneId(String serverTimeZoneId) {
|
||||
this.serverTimeZoneId = serverTimeZoneId;
|
||||
}
|
||||
|
||||
public void setShortMonthNames(String shortMonthNames) {
|
||||
this.shortMonthNames = shortMonthNames;
|
||||
}
|
||||
|
||||
public void setServerLanguageCode(String serverLanguageCode) {
|
||||
this.serverLanguageCode = serverLanguageCode;
|
||||
}
|
||||
|
||||
public static DateFormatSymbols lookupDateFormatSymbols(String languageCode) {
|
||||
Object lang = LANGUAGE_CODE_MAP.get(languageCode);
|
||||
if (lang != null) {
|
||||
if (lang instanceof Locale)
|
||||
return new DateFormatSymbols((Locale)lang);
|
||||
if (lang instanceof String)
|
||||
return getDateFormatSymbols((String)lang);
|
||||
}
|
||||
return new DateFormatSymbols(Locale.US);
|
||||
}
|
||||
|
||||
public static DateFormatSymbols getDateFormatSymbols(String shortmonths) {
|
||||
String[] months = splitShortMonthString(shortmonths);
|
||||
DateFormatSymbols dfs = new DateFormatSymbols(Locale.US);
|
||||
dfs.setShortMonths(months);
|
||||
return dfs;
|
||||
}
|
||||
|
||||
private static String[] splitShortMonthString(String shortmonths) {
|
||||
StringTokenizer st = new StringTokenizer(shortmonths, "|");
|
||||
int monthcnt = st.countTokens();
|
||||
if (12 != monthcnt)
|
||||
throw new IllegalArgumentException("expecting a pipe-delimited string containing 12 tokens");
|
||||
String[] months = new String[13];
|
||||
int pos = 0;
|
||||
while (st.hasMoreTokens())
|
||||
months[pos++] = st.nextToken();
|
||||
months[pos] = "";
|
||||
return months;
|
||||
}
|
||||
|
||||
public static Collection<String> getSupportedLanguageCodes() {
|
||||
return LANGUAGE_CODE_MAP.keySet();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
public enum FTPCmd {
|
||||
ABOR, ACCT, ALLO, APPE, CDUP, CWD, DELE, EPRT, EPSV, FEAT, HELP, LIST, MDTM, MFMT, MKD, MLSD, MLST, MODE, NLST, NOOP, PASS, PASV, PORT, PWD, QUIT, REIN, REST, RETR, RMD, RNFR, RNTO, SITE, SMNT, STAT, STOR, STOU, STRU, SYST, TYPE, USER;
|
||||
|
||||
public static final FTPCmd ABORT = ABOR;
|
||||
|
||||
public static final FTPCmd ACCOUNT = ACCT;
|
||||
|
||||
public static final FTPCmd ALLOCATE = ALLO;
|
||||
|
||||
public static final FTPCmd APPEND = APPE;
|
||||
|
||||
public static final FTPCmd CHANGE_TO_PARENT_DIRECTORY = CDUP;
|
||||
|
||||
public static final FTPCmd CHANGE_WORKING_DIRECTORY = CWD;
|
||||
|
||||
public static final FTPCmd DATA_PORT = PORT;
|
||||
|
||||
public static final FTPCmd DELETE = DELE;
|
||||
|
||||
public static final FTPCmd FEATURES = FEAT;
|
||||
|
||||
public static final FTPCmd FILE_STRUCTURE = STRU;
|
||||
|
||||
public static final FTPCmd GET_MOD_TIME = MDTM;
|
||||
|
||||
public static final FTPCmd LOGOUT = QUIT;
|
||||
|
||||
public static final FTPCmd MAKE_DIRECTORY = MKD;
|
||||
|
||||
public static final FTPCmd MOD_TIME = MDTM;
|
||||
|
||||
public static final FTPCmd NAME_LIST = NLST;
|
||||
|
||||
public static final FTPCmd PASSIVE = PASV;
|
||||
|
||||
public static final FTPCmd PASSWORD = PASS;
|
||||
|
||||
public static final FTPCmd PRINT_WORKING_DIRECTORY = PWD;
|
||||
|
||||
public static final FTPCmd REINITIALIZE = REIN;
|
||||
|
||||
public static final FTPCmd REMOVE_DIRECTORY = RMD;
|
||||
|
||||
public static final FTPCmd RENAME_FROM = RNFR;
|
||||
|
||||
public static final FTPCmd RENAME_TO = RNTO;
|
||||
|
||||
public static final FTPCmd REPRESENTATION_TYPE = TYPE;
|
||||
|
||||
public static final FTPCmd RESTART = REST;
|
||||
|
||||
public static final FTPCmd RETRIEVE = RETR;
|
||||
|
||||
public static final FTPCmd SET_MOD_TIME = MFMT;
|
||||
|
||||
public static final FTPCmd SITE_PARAMETERS = SITE;
|
||||
|
||||
public static final FTPCmd STATUS = STAT;
|
||||
|
||||
public static final FTPCmd STORE = STOR;
|
||||
|
||||
public static final FTPCmd STORE_UNIQUE = STOU;
|
||||
|
||||
public static final FTPCmd STRUCTURE_MOUNT = SMNT;
|
||||
|
||||
public static final FTPCmd SYSTEM = SYST;
|
||||
|
||||
public static final FTPCmd TRANSFER_MODE = MODE;
|
||||
|
||||
public static final FTPCmd USERNAME = USER;
|
||||
|
||||
public final String getCommand() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,170 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
@Deprecated
|
||||
public final class FTPCommand {
|
||||
public static final int USER = 0;
|
||||
|
||||
public static final int PASS = 1;
|
||||
|
||||
public static final int ACCT = 2;
|
||||
|
||||
public static final int CWD = 3;
|
||||
|
||||
public static final int CDUP = 4;
|
||||
|
||||
public static final int SMNT = 5;
|
||||
|
||||
public static final int REIN = 6;
|
||||
|
||||
public static final int QUIT = 7;
|
||||
|
||||
public static final int PORT = 8;
|
||||
|
||||
public static final int PASV = 9;
|
||||
|
||||
public static final int TYPE = 10;
|
||||
|
||||
public static final int STRU = 11;
|
||||
|
||||
public static final int MODE = 12;
|
||||
|
||||
public static final int RETR = 13;
|
||||
|
||||
public static final int STOR = 14;
|
||||
|
||||
public static final int STOU = 15;
|
||||
|
||||
public static final int APPE = 16;
|
||||
|
||||
public static final int ALLO = 17;
|
||||
|
||||
public static final int REST = 18;
|
||||
|
||||
public static final int RNFR = 19;
|
||||
|
||||
public static final int RNTO = 20;
|
||||
|
||||
public static final int ABOR = 21;
|
||||
|
||||
public static final int DELE = 22;
|
||||
|
||||
public static final int RMD = 23;
|
||||
|
||||
public static final int MKD = 24;
|
||||
|
||||
public static final int PWD = 25;
|
||||
|
||||
public static final int LIST = 26;
|
||||
|
||||
public static final int NLST = 27;
|
||||
|
||||
public static final int SITE = 28;
|
||||
|
||||
public static final int SYST = 29;
|
||||
|
||||
public static final int STAT = 30;
|
||||
|
||||
public static final int HELP = 31;
|
||||
|
||||
public static final int NOOP = 32;
|
||||
|
||||
public static final int MDTM = 33;
|
||||
|
||||
public static final int FEAT = 34;
|
||||
|
||||
public static final int MFMT = 35;
|
||||
|
||||
public static final int EPSV = 36;
|
||||
|
||||
public static final int EPRT = 37;
|
||||
|
||||
public static final int MLSD = 38;
|
||||
|
||||
public static final int MLST = 39;
|
||||
|
||||
private static final int LAST = 39;
|
||||
|
||||
public static final int USERNAME = 0;
|
||||
|
||||
public static final int PASSWORD = 1;
|
||||
|
||||
public static final int ACCOUNT = 2;
|
||||
|
||||
public static final int CHANGE_WORKING_DIRECTORY = 3;
|
||||
|
||||
public static final int CHANGE_TO_PARENT_DIRECTORY = 4;
|
||||
|
||||
public static final int STRUCTURE_MOUNT = 5;
|
||||
|
||||
public static final int REINITIALIZE = 6;
|
||||
|
||||
public static final int LOGOUT = 7;
|
||||
|
||||
public static final int DATA_PORT = 8;
|
||||
|
||||
public static final int PASSIVE = 9;
|
||||
|
||||
public static final int REPRESENTATION_TYPE = 10;
|
||||
|
||||
public static final int FILE_STRUCTURE = 11;
|
||||
|
||||
public static final int TRANSFER_MODE = 12;
|
||||
|
||||
public static final int RETRIEVE = 13;
|
||||
|
||||
public static final int STORE = 14;
|
||||
|
||||
public static final int STORE_UNIQUE = 15;
|
||||
|
||||
public static final int APPEND = 16;
|
||||
|
||||
public static final int ALLOCATE = 17;
|
||||
|
||||
public static final int RESTART = 18;
|
||||
|
||||
public static final int RENAME_FROM = 19;
|
||||
|
||||
public static final int RENAME_TO = 20;
|
||||
|
||||
public static final int ABORT = 21;
|
||||
|
||||
public static final int DELETE = 22;
|
||||
|
||||
public static final int REMOVE_DIRECTORY = 23;
|
||||
|
||||
public static final int MAKE_DIRECTORY = 24;
|
||||
|
||||
public static final int PRINT_WORKING_DIRECTORY = 25;
|
||||
|
||||
public static final int NAME_LIST = 27;
|
||||
|
||||
public static final int SITE_PARAMETERS = 28;
|
||||
|
||||
public static final int SYSTEM = 29;
|
||||
|
||||
public static final int STATUS = 30;
|
||||
|
||||
public static final int MOD_TIME = 33;
|
||||
|
||||
public static final int FEATURES = 34;
|
||||
|
||||
public static final int GET_MOD_TIME = 33;
|
||||
|
||||
public static final int SET_MOD_TIME = 35;
|
||||
|
||||
private static final String[] _commands = new String[] {
|
||||
"USER", "PASS", "ACCT", "CWD", "CDUP", "SMNT", "REIN", "QUIT", "PORT", "PASV",
|
||||
"TYPE", "STRU", "MODE", "RETR", "STOR", "STOU", "APPE", "ALLO", "REST", "RNFR",
|
||||
"RNTO", "ABOR", "DELE", "RMD", "MKD", "PWD", "LIST", "NLST", "SITE", "SYST",
|
||||
"STAT", "HELP", "NOOP", "MDTM", "FEAT", "MFMT", "EPSV", "EPRT", "MLSD", "MLST" };
|
||||
|
||||
static void checkArray() {
|
||||
int expectedLength = 40;
|
||||
if (_commands.length != expectedLength)
|
||||
throw new RuntimeException("Incorrect _commands array. Should have length " + expectedLength + " found " + _commands.length);
|
||||
}
|
||||
|
||||
public static final String getCommand(int command) {
|
||||
return _commands[command];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class FTPConnectionClosedException extends IOException {
|
||||
private static final long serialVersionUID = 3500547241659379952L;
|
||||
|
||||
public FTPConnectionClosedException() {}
|
||||
|
||||
public FTPConnectionClosedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,203 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import java.util.Formatter;
|
||||
|
||||
public class FTPFile implements Serializable {
|
||||
private final boolean[][] _permissions = new boolean[3][3];
|
||||
|
||||
private String _rawListing = null;
|
||||
|
||||
private int _type = 3;
|
||||
|
||||
private int _hardLinkCount = 0;
|
||||
|
||||
private long _size = -1L;
|
||||
|
||||
private String _user = "";
|
||||
|
||||
private String _group = "";
|
||||
|
||||
private Calendar _date = null;
|
||||
|
||||
private String _name = null;
|
||||
|
||||
private static final long serialVersionUID = 9010790363003271996L;
|
||||
|
||||
public static final int FILE_TYPE = 0;
|
||||
|
||||
public static final int DIRECTORY_TYPE = 1;
|
||||
|
||||
public static final int SYMBOLIC_LINK_TYPE = 2;
|
||||
|
||||
public static final int UNKNOWN_TYPE = 3;
|
||||
|
||||
public static final int USER_ACCESS = 0;
|
||||
|
||||
public static final int GROUP_ACCESS = 1;
|
||||
|
||||
public static final int WORLD_ACCESS = 2;
|
||||
|
||||
public static final int READ_PERMISSION = 0;
|
||||
|
||||
public static final int WRITE_PERMISSION = 1;
|
||||
|
||||
public static final int EXECUTE_PERMISSION = 2;
|
||||
|
||||
private String _link;
|
||||
|
||||
public void setRawListing(String rawListing) {
|
||||
this._rawListing = rawListing;
|
||||
}
|
||||
|
||||
public String getRawListing() {
|
||||
return this._rawListing;
|
||||
}
|
||||
|
||||
public boolean isDirectory() {
|
||||
return (this._type == 1);
|
||||
}
|
||||
|
||||
public boolean isFile() {
|
||||
return (this._type == 0);
|
||||
}
|
||||
|
||||
public boolean isSymbolicLink() {
|
||||
return (this._type == 2);
|
||||
}
|
||||
|
||||
public boolean isUnknown() {
|
||||
return (this._type == 3);
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this._type = type;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this._name;
|
||||
}
|
||||
|
||||
public void setSize(long size) {
|
||||
this._size = size;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return this._size;
|
||||
}
|
||||
|
||||
public void setHardLinkCount(int links) {
|
||||
this._hardLinkCount = links;
|
||||
}
|
||||
|
||||
public int getHardLinkCount() {
|
||||
return this._hardLinkCount;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this._group = group;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return this._group;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this._user = user;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
public void setLink(String link) {
|
||||
this._link = link;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return this._link;
|
||||
}
|
||||
|
||||
public void setTimestamp(Calendar date) {
|
||||
this._date = date;
|
||||
}
|
||||
|
||||
public Calendar getTimestamp() {
|
||||
return this._date;
|
||||
}
|
||||
|
||||
public void setPermission(int access, int permission, boolean value) {
|
||||
this._permissions[access][permission] = value;
|
||||
}
|
||||
|
||||
public boolean hasPermission(int access, int permission) {
|
||||
return this._permissions[access][permission];
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getRawListing();
|
||||
}
|
||||
|
||||
public String toFormattedString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Formatter fmt = new Formatter(sb);
|
||||
sb.append(formatType());
|
||||
sb.append(permissionToString(0));
|
||||
sb.append(permissionToString(1));
|
||||
sb.append(permissionToString(2));
|
||||
fmt.format(" %4d", getHardLinkCount());
|
||||
fmt.format(" %-8s %-8s", getGroup(), getUser());
|
||||
fmt.format(" %8d", getSize());
|
||||
Calendar timestamp = getTimestamp();
|
||||
if (timestamp != null) {
|
||||
fmt.format(" %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", timestamp);
|
||||
fmt.format(" %1$tZ", timestamp);
|
||||
sb.append(' ');
|
||||
}
|
||||
sb.append(' ');
|
||||
sb.append(getName());
|
||||
fmt.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private char formatType() {
|
||||
switch (this._type) {
|
||||
case 0:
|
||||
return '-';
|
||||
case 1:
|
||||
return 'd';
|
||||
case 2:
|
||||
return 'l';
|
||||
}
|
||||
return '?';
|
||||
}
|
||||
|
||||
private String permissionToString(int access) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (hasPermission(access, 0)) {
|
||||
sb.append('r');
|
||||
} else {
|
||||
sb.append('-');
|
||||
}
|
||||
if (hasPermission(access, 1)) {
|
||||
sb.append('w');
|
||||
} else {
|
||||
sb.append('-');
|
||||
}
|
||||
if (hasPermission(access, 2)) {
|
||||
sb.append('x');
|
||||
} else {
|
||||
sb.append('-');
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public interface FTPFileEntryParser {
|
||||
FTPFile parseFTPEntry(String paramString);
|
||||
|
||||
String readNextEntry(BufferedReader paramBufferedReader) throws IOException;
|
||||
|
||||
List<String> preParse(List<String> paramList);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class FTPFileEntryParserImpl implements FTPFileEntryParser {
|
||||
public String readNextEntry(BufferedReader reader) throws IOException {
|
||||
return reader.readLine();
|
||||
}
|
||||
|
||||
public List<String> preParse(List<String> original) {
|
||||
return original;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
public interface FTPFileFilter {
|
||||
boolean accept(FTPFile paramFTPFile);
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
public class FTPFileFilters {
|
||||
public static final FTPFileFilter ALL = new FTPFileFilter() {
|
||||
public boolean accept(FTPFile file) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
public static final FTPFileFilter NON_NULL = new FTPFileFilter() {
|
||||
public boolean accept(FTPFile file) {
|
||||
return (file != null);
|
||||
}
|
||||
};
|
||||
|
||||
public static final FTPFileFilter DIRECTORIES = new FTPFileFilter() {
|
||||
public boolean accept(FTPFile file) {
|
||||
return (file != null && file.isDirectory());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
|
||||
public class FTPHTTPClient extends FTPClient {
|
||||
private final String proxyHost;
|
||||
|
||||
private final int proxyPort;
|
||||
|
||||
private final String proxyUsername;
|
||||
|
||||
private final String proxyPassword;
|
||||
|
||||
private static final byte[] CRLF = new byte[] { 13, 10 };
|
||||
|
||||
private final Base64 base64 = new Base64();
|
||||
|
||||
private String tunnelHost;
|
||||
|
||||
public FTPHTTPClient(String proxyHost, int proxyPort, String proxyUser, String proxyPass) {
|
||||
this.proxyHost = proxyHost;
|
||||
this.proxyPort = proxyPort;
|
||||
this.proxyUsername = proxyUser;
|
||||
this.proxyPassword = proxyPass;
|
||||
this.tunnelHost = null;
|
||||
}
|
||||
|
||||
public FTPHTTPClient(String proxyHost, int proxyPort) {
|
||||
this(proxyHost, proxyPort, null, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected Socket _openDataConnection_(int command, String arg) throws IOException {
|
||||
return super._openDataConnection_(command, arg);
|
||||
}
|
||||
|
||||
protected Socket _openDataConnection_(String command, String arg) throws IOException {
|
||||
if (getDataConnectionMode() != 2)
|
||||
throw new IllegalStateException("Only passive connection mode supported");
|
||||
boolean isInet6Address = getRemoteAddress() instanceof java.net.Inet6Address;
|
||||
String passiveHost = null;
|
||||
boolean attemptEPSV = (isUseEPSVwithIPv4() || isInet6Address);
|
||||
if (attemptEPSV && epsv() == 229) {
|
||||
_parseExtendedPassiveModeReply(this._replyLines.get(0));
|
||||
passiveHost = this.tunnelHost;
|
||||
} else {
|
||||
if (isInet6Address)
|
||||
return null;
|
||||
if (pasv() != 227)
|
||||
return null;
|
||||
_parsePassiveModeReply(this._replyLines.get(0));
|
||||
passiveHost = getPassiveHost();
|
||||
}
|
||||
Socket socket = new Socket(this.proxyHost, this.proxyPort);
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
tunnelHandshake(passiveHost, getPassivePort(), is, os);
|
||||
if (getRestartOffset() > 0L && !restart(getRestartOffset())) {
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
public void connect(String host, int port) throws SocketException, IOException {
|
||||
this._socket_ = new Socket(this.proxyHost, this.proxyPort);
|
||||
this._input_ = this._socket_.getInputStream();
|
||||
this._output_ = this._socket_.getOutputStream();
|
||||
try {
|
||||
tunnelHandshake(host, port, this._input_, this._output_);
|
||||
} catch (Exception e) {
|
||||
IOException ioe = new IOException("Could not connect to " + host + " using port " + port);
|
||||
ioe.initCause(e);
|
||||
throw ioe;
|
||||
}
|
||||
_connectAction_();
|
||||
}
|
||||
|
||||
private void tunnelHandshake(String host, int port, InputStream input, OutputStream output) throws IOException, UnsupportedEncodingException {
|
||||
String connectString = "CONNECT " + host + ":" + port + " HTTP/1.1";
|
||||
String hostString = "Host: " + host + ":" + port;
|
||||
this.tunnelHost = host;
|
||||
output.write(connectString.getBytes("UTF-8"));
|
||||
output.write(CRLF);
|
||||
output.write(hostString.getBytes("UTF-8"));
|
||||
output.write(CRLF);
|
||||
if (this.proxyUsername != null && this.proxyPassword != null) {
|
||||
String auth = this.proxyUsername + ":" + this.proxyPassword;
|
||||
String header = "Proxy-Authorization: Basic " + this.base64.encodeToString(auth.getBytes("UTF-8"));
|
||||
output.write(header.getBytes("UTF-8"));
|
||||
}
|
||||
output.write(CRLF);
|
||||
List<String> response = new ArrayList<String>();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(input, getCharsetName()));
|
||||
String line = reader.readLine();
|
||||
for (; line != null && line.length() > 0; line = reader.readLine())
|
||||
response.add(line);
|
||||
int size = response.size();
|
||||
if (size == 0)
|
||||
throw new IOException("No response from proxy");
|
||||
String code = null;
|
||||
String resp = response.get(0);
|
||||
if (resp.startsWith("HTTP/") && resp.length() >= 12) {
|
||||
code = resp.substring(9, 12);
|
||||
} else {
|
||||
throw new IOException("Invalid response from proxy: " + resp);
|
||||
}
|
||||
if (!"200".equals(code)) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("HTTPTunnelConnector: connection failed\r\n");
|
||||
msg.append("Response received from the proxy:\r\n");
|
||||
for (String str : response) {
|
||||
msg.append(str);
|
||||
msg.append("\r\n");
|
||||
}
|
||||
throw new IOException(msg.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import org.apache.commons.net.util.Charsets;
|
||||
|
||||
public class FTPListParseEngine {
|
||||
private List<String> entries = new LinkedList<String>();
|
||||
|
||||
private ListIterator<String> _internalIterator = this.entries.listIterator();
|
||||
|
||||
private final FTPFileEntryParser parser;
|
||||
|
||||
public FTPListParseEngine(FTPFileEntryParser parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public void readServerList(InputStream stream, String encoding) throws IOException {
|
||||
this.entries = new LinkedList<String>();
|
||||
readStream(stream, encoding);
|
||||
this.parser.preParse(this.entries);
|
||||
resetIterator();
|
||||
}
|
||||
|
||||
private void readStream(InputStream stream, String encoding) throws IOException {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charsets.toCharset(encoding)));
|
||||
String line = this.parser.readNextEntry(reader);
|
||||
while (line != null) {
|
||||
this.entries.add(line);
|
||||
line = this.parser.readNextEntry(reader);
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
|
||||
public FTPFile[] getNext(int quantityRequested) {
|
||||
List<FTPFile> tmpResults = new LinkedList<FTPFile>();
|
||||
int count = quantityRequested;
|
||||
while (count > 0 && this._internalIterator.hasNext()) {
|
||||
String entry = this._internalIterator.next();
|
||||
FTPFile temp = this.parser.parseFTPEntry(entry);
|
||||
tmpResults.add(temp);
|
||||
count--;
|
||||
}
|
||||
return tmpResults.<FTPFile>toArray(new FTPFile[tmpResults.size()]);
|
||||
}
|
||||
|
||||
public FTPFile[] getPrevious(int quantityRequested) {
|
||||
List<FTPFile> tmpResults = new LinkedList<FTPFile>();
|
||||
int count = quantityRequested;
|
||||
while (count > 0 && this._internalIterator.hasPrevious()) {
|
||||
String entry = this._internalIterator.previous();
|
||||
FTPFile temp = this.parser.parseFTPEntry(entry);
|
||||
tmpResults.add(0, temp);
|
||||
count--;
|
||||
}
|
||||
return tmpResults.<FTPFile>toArray(new FTPFile[tmpResults.size()]);
|
||||
}
|
||||
|
||||
public FTPFile[] getFiles() throws IOException {
|
||||
return getFiles(FTPFileFilters.NON_NULL);
|
||||
}
|
||||
|
||||
public FTPFile[] getFiles(FTPFileFilter filter) throws IOException {
|
||||
List<FTPFile> tmpResults = new ArrayList<FTPFile>();
|
||||
Iterator<String> iter = this.entries.iterator();
|
||||
while (iter.hasNext()) {
|
||||
String entry = iter.next();
|
||||
FTPFile temp = this.parser.parseFTPEntry(entry);
|
||||
if (filter.accept(temp))
|
||||
tmpResults.add(temp);
|
||||
}
|
||||
return tmpResults.<FTPFile>toArray(new FTPFile[tmpResults.size()]);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return this._internalIterator.hasNext();
|
||||
}
|
||||
|
||||
public boolean hasPrevious() {
|
||||
return this._internalIterator.hasPrevious();
|
||||
}
|
||||
|
||||
public void resetIterator() {
|
||||
this._internalIterator = this.entries.listIterator();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void readServerList(InputStream stream) throws IOException {
|
||||
readServerList(stream, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,129 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
public final class FTPReply {
|
||||
public static final int RESTART_MARKER = 110;
|
||||
|
||||
public static final int SERVICE_NOT_READY = 120;
|
||||
|
||||
public static final int DATA_CONNECTION_ALREADY_OPEN = 125;
|
||||
|
||||
public static final int FILE_STATUS_OK = 150;
|
||||
|
||||
public static final int COMMAND_OK = 200;
|
||||
|
||||
public static final int COMMAND_IS_SUPERFLUOUS = 202;
|
||||
|
||||
public static final int SYSTEM_STATUS = 211;
|
||||
|
||||
public static final int DIRECTORY_STATUS = 212;
|
||||
|
||||
public static final int FILE_STATUS = 213;
|
||||
|
||||
public static final int HELP_MESSAGE = 214;
|
||||
|
||||
public static final int NAME_SYSTEM_TYPE = 215;
|
||||
|
||||
public static final int SERVICE_READY = 220;
|
||||
|
||||
public static final int SERVICE_CLOSING_CONTROL_CONNECTION = 221;
|
||||
|
||||
public static final int DATA_CONNECTION_OPEN = 225;
|
||||
|
||||
public static final int CLOSING_DATA_CONNECTION = 226;
|
||||
|
||||
public static final int ENTERING_PASSIVE_MODE = 227;
|
||||
|
||||
public static final int ENTERING_EPSV_MODE = 229;
|
||||
|
||||
public static final int USER_LOGGED_IN = 230;
|
||||
|
||||
public static final int FILE_ACTION_OK = 250;
|
||||
|
||||
public static final int PATHNAME_CREATED = 257;
|
||||
|
||||
public static final int NEED_PASSWORD = 331;
|
||||
|
||||
public static final int NEED_ACCOUNT = 332;
|
||||
|
||||
public static final int FILE_ACTION_PENDING = 350;
|
||||
|
||||
public static final int SERVICE_NOT_AVAILABLE = 421;
|
||||
|
||||
public static final int CANNOT_OPEN_DATA_CONNECTION = 425;
|
||||
|
||||
public static final int TRANSFER_ABORTED = 426;
|
||||
|
||||
public static final int FILE_ACTION_NOT_TAKEN = 450;
|
||||
|
||||
public static final int ACTION_ABORTED = 451;
|
||||
|
||||
public static final int INSUFFICIENT_STORAGE = 452;
|
||||
|
||||
public static final int UNRECOGNIZED_COMMAND = 500;
|
||||
|
||||
public static final int SYNTAX_ERROR_IN_ARGUMENTS = 501;
|
||||
|
||||
public static final int COMMAND_NOT_IMPLEMENTED = 502;
|
||||
|
||||
public static final int BAD_COMMAND_SEQUENCE = 503;
|
||||
|
||||
public static final int COMMAND_NOT_IMPLEMENTED_FOR_PARAMETER = 504;
|
||||
|
||||
public static final int NOT_LOGGED_IN = 530;
|
||||
|
||||
public static final int NEED_ACCOUNT_FOR_STORING_FILES = 532;
|
||||
|
||||
public static final int FILE_UNAVAILABLE = 550;
|
||||
|
||||
public static final int PAGE_TYPE_UNKNOWN = 551;
|
||||
|
||||
public static final int STORAGE_ALLOCATION_EXCEEDED = 552;
|
||||
|
||||
public static final int FILE_NAME_NOT_ALLOWED = 553;
|
||||
|
||||
public static final int SECURITY_DATA_EXCHANGE_COMPLETE = 234;
|
||||
|
||||
public static final int SECURITY_DATA_EXCHANGE_SUCCESSFULLY = 235;
|
||||
|
||||
public static final int SECURITY_MECHANISM_IS_OK = 334;
|
||||
|
||||
public static final int SECURITY_DATA_IS_ACCEPTABLE = 335;
|
||||
|
||||
public static final int UNAVAILABLE_RESOURCE = 431;
|
||||
|
||||
public static final int BAD_TLS_NEGOTIATION_OR_DATA_ENCRYPTION_REQUIRED = 522;
|
||||
|
||||
public static final int DENIED_FOR_POLICY_REASONS = 533;
|
||||
|
||||
public static final int REQUEST_DENIED = 534;
|
||||
|
||||
public static final int FAILED_SECURITY_CHECK = 535;
|
||||
|
||||
public static final int REQUESTED_PROT_LEVEL_NOT_SUPPORTED = 536;
|
||||
|
||||
public static final int EXTENDED_PORT_FAILURE = 522;
|
||||
|
||||
public static boolean isPositivePreliminary(int reply) {
|
||||
return (reply >= 100 && reply < 200);
|
||||
}
|
||||
|
||||
public static boolean isPositiveCompletion(int reply) {
|
||||
return (reply >= 200 && reply < 300);
|
||||
}
|
||||
|
||||
public static boolean isPositiveIntermediate(int reply) {
|
||||
return (reply >= 300 && reply < 400);
|
||||
}
|
||||
|
||||
public static boolean isNegativeTransient(int reply) {
|
||||
return (reply >= 400 && reply < 500);
|
||||
}
|
||||
|
||||
public static boolean isNegativePermanent(int reply) {
|
||||
return (reply >= 500 && reply < 600);
|
||||
}
|
||||
|
||||
public static boolean isProtectedReplyCode(int reply) {
|
||||
return (reply >= 600 && reply < 700);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,380 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.Socket;
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
import org.apache.commons.net.util.SSLContextUtils;
|
||||
import org.apache.commons.net.util.TrustManagerUtils;
|
||||
|
||||
public class FTPSClient extends FTPClient {
|
||||
public static final int DEFAULT_FTPS_DATA_PORT = 989;
|
||||
|
||||
public static final int DEFAULT_FTPS_PORT = 990;
|
||||
|
||||
private static final String[] PROT_COMMAND_VALUE = new String[] { "C", "E", "S", "P" };
|
||||
|
||||
private static final String DEFAULT_PROT = "C";
|
||||
|
||||
private static final String DEFAULT_PROTOCOL = "TLS";
|
||||
|
||||
private static final String CMD_AUTH = "AUTH";
|
||||
|
||||
private static final String CMD_ADAT = "ADAT";
|
||||
|
||||
private static final String CMD_PROT = "PROT";
|
||||
|
||||
private static final String CMD_PBSZ = "PBSZ";
|
||||
|
||||
private static final String CMD_MIC = "MIC";
|
||||
|
||||
private static final String CMD_CONF = "CONF";
|
||||
|
||||
private static final String CMD_ENC = "ENC";
|
||||
|
||||
private static final String CMD_CCC = "CCC";
|
||||
|
||||
private final boolean isImplicit;
|
||||
|
||||
private final String protocol;
|
||||
|
||||
private String auth = "TLS";
|
||||
|
||||
private SSLContext context;
|
||||
|
||||
private Socket plainSocket;
|
||||
|
||||
private boolean isCreation = true;
|
||||
|
||||
private boolean isClientMode = true;
|
||||
|
||||
private boolean isNeedClientAuth = false;
|
||||
|
||||
private boolean isWantClientAuth = false;
|
||||
|
||||
private String[] suites = null;
|
||||
|
||||
private String[] protocols = null;
|
||||
|
||||
private TrustManager trustManager = TrustManagerUtils.getValidateServerCertificateTrustManager();
|
||||
|
||||
private KeyManager keyManager = null;
|
||||
|
||||
@Deprecated
|
||||
public static String KEYSTORE_ALGORITHM;
|
||||
|
||||
@Deprecated
|
||||
public static String TRUSTSTORE_ALGORITHM;
|
||||
|
||||
@Deprecated
|
||||
public static String PROVIDER;
|
||||
|
||||
@Deprecated
|
||||
public static String STORE_TYPE;
|
||||
|
||||
public FTPSClient() {
|
||||
this("TLS", false);
|
||||
}
|
||||
|
||||
public FTPSClient(boolean isImplicit) {
|
||||
this("TLS", isImplicit);
|
||||
}
|
||||
|
||||
public FTPSClient(String protocol) {
|
||||
this(protocol, false);
|
||||
}
|
||||
|
||||
public FTPSClient(String protocol, boolean isImplicit) {
|
||||
this.protocol = protocol;
|
||||
this.isImplicit = isImplicit;
|
||||
if (isImplicit)
|
||||
setDefaultPort(990);
|
||||
}
|
||||
|
||||
public FTPSClient(boolean isImplicit, SSLContext context) {
|
||||
this("TLS", isImplicit);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public FTPSClient(SSLContext context) {
|
||||
this(false, context);
|
||||
}
|
||||
|
||||
public void setAuthValue(String auth) {
|
||||
this.auth = auth;
|
||||
}
|
||||
|
||||
public String getAuthValue() {
|
||||
return this.auth;
|
||||
}
|
||||
|
||||
protected void _connectAction_() throws IOException {
|
||||
if (this.isImplicit)
|
||||
sslNegotiation();
|
||||
super._connectAction_();
|
||||
if (!this.isImplicit) {
|
||||
execAUTH();
|
||||
sslNegotiation();
|
||||
}
|
||||
}
|
||||
|
||||
protected void execAUTH() throws SSLException, IOException {
|
||||
int replyCode = sendCommand("AUTH", this.auth);
|
||||
if (334 != replyCode)
|
||||
if (234 != replyCode)
|
||||
throw new SSLException(getReplyString());
|
||||
}
|
||||
|
||||
private void initSslContext() throws IOException {
|
||||
if (this.context == null)
|
||||
this.context = SSLContextUtils.createSSLContext(this.protocol, getKeyManager(), getTrustManager());
|
||||
}
|
||||
|
||||
protected void sslNegotiation() throws IOException {
|
||||
this.plainSocket = this._socket_;
|
||||
initSslContext();
|
||||
SSLSocketFactory ssf = this.context.getSocketFactory();
|
||||
String ip = this._socket_.getInetAddress().getHostAddress();
|
||||
int port = this._socket_.getPort();
|
||||
SSLSocket socket = (SSLSocket)ssf.createSocket(this._socket_, ip, port, false);
|
||||
socket.setEnableSessionCreation(this.isCreation);
|
||||
socket.setUseClientMode(this.isClientMode);
|
||||
if (!this.isClientMode) {
|
||||
socket.setNeedClientAuth(this.isNeedClientAuth);
|
||||
socket.setWantClientAuth(this.isWantClientAuth);
|
||||
}
|
||||
if (this.protocols != null)
|
||||
socket.setEnabledProtocols(this.protocols);
|
||||
if (this.suites != null)
|
||||
socket.setEnabledCipherSuites(this.suites);
|
||||
socket.startHandshake();
|
||||
this._socket_ = socket;
|
||||
this._controlInput_ = new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));
|
||||
this._controlOutput_ = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), getControlEncoding()));
|
||||
}
|
||||
|
||||
private KeyManager getKeyManager() {
|
||||
return this.keyManager;
|
||||
}
|
||||
|
||||
public void setKeyManager(KeyManager keyManager) {
|
||||
this.keyManager = keyManager;
|
||||
}
|
||||
|
||||
public void setEnabledSessionCreation(boolean isCreation) {
|
||||
this.isCreation = isCreation;
|
||||
}
|
||||
|
||||
public boolean getEnableSessionCreation() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getEnableSessionCreation();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setNeedClientAuth(boolean isNeedClientAuth) {
|
||||
this.isNeedClientAuth = isNeedClientAuth;
|
||||
}
|
||||
|
||||
public boolean getNeedClientAuth() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getNeedClientAuth();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setWantClientAuth(boolean isWantClientAuth) {
|
||||
this.isWantClientAuth = isWantClientAuth;
|
||||
}
|
||||
|
||||
public boolean getWantClientAuth() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getWantClientAuth();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setUseClientMode(boolean isClientMode) {
|
||||
this.isClientMode = isClientMode;
|
||||
}
|
||||
|
||||
public boolean getUseClientMode() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getUseClientMode();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setEnabledCipherSuites(String[] cipherSuites) {
|
||||
this.suites = new String[cipherSuites.length];
|
||||
System.arraycopy(cipherSuites, 0, this.suites, 0, cipherSuites.length);
|
||||
}
|
||||
|
||||
public String[] getEnabledCipherSuites() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getEnabledCipherSuites();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEnabledProtocols(String[] protocolVersions) {
|
||||
this.protocols = new String[protocolVersions.length];
|
||||
System.arraycopy(protocolVersions, 0, this.protocols, 0, protocolVersions.length);
|
||||
}
|
||||
|
||||
public String[] getEnabledProtocols() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getEnabledProtocols();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void execPBSZ(long pbsz) throws SSLException, IOException {
|
||||
if (pbsz < 0L || 4294967295L < pbsz)
|
||||
throw new IllegalArgumentException();
|
||||
int status = sendCommand("PBSZ", String.valueOf(pbsz));
|
||||
if (200 != status)
|
||||
throw new SSLException(getReplyString());
|
||||
}
|
||||
|
||||
public long parsePBSZ(long pbsz) throws SSLException, IOException {
|
||||
execPBSZ(pbsz);
|
||||
long minvalue = pbsz;
|
||||
String remainder = extractPrefixedData("PBSZ=", getReplyString());
|
||||
if (remainder != null) {
|
||||
long replysz = Long.parseLong(remainder);
|
||||
if (replysz < minvalue)
|
||||
minvalue = replysz;
|
||||
}
|
||||
return minvalue;
|
||||
}
|
||||
|
||||
public void execPROT(String prot) throws SSLException, IOException {
|
||||
if (prot == null)
|
||||
prot = "C";
|
||||
if (!checkPROTValue(prot))
|
||||
throw new IllegalArgumentException();
|
||||
if (200 != sendCommand("PROT", prot))
|
||||
throw new SSLException(getReplyString());
|
||||
if ("C".equals(prot)) {
|
||||
setSocketFactory(null);
|
||||
setServerSocketFactory(null);
|
||||
} else {
|
||||
setSocketFactory(new FTPSSocketFactory(this.context));
|
||||
setServerSocketFactory(new FTPSServerSocketFactory(this.context));
|
||||
initSslContext();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkPROTValue(String prot) {
|
||||
for (String element : PROT_COMMAND_VALUE) {
|
||||
if (element.equals(prot))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int sendCommand(String command, String args) throws IOException {
|
||||
int repCode = super.sendCommand(command, args);
|
||||
if ("CCC".equals(command))
|
||||
if (200 == repCode) {
|
||||
this._socket_.close();
|
||||
this._socket_ = this.plainSocket;
|
||||
this._controlInput_ = new BufferedReader(new InputStreamReader(this._socket_.getInputStream(), getControlEncoding()));
|
||||
this._controlOutput_ = new BufferedWriter(new OutputStreamWriter(this._socket_.getOutputStream(), getControlEncoding()));
|
||||
} else {
|
||||
throw new SSLException(getReplyString());
|
||||
}
|
||||
return repCode;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected Socket _openDataConnection_(int command, String arg) throws IOException {
|
||||
return _openDataConnection_(FTPCommand.getCommand(command), arg);
|
||||
}
|
||||
|
||||
protected Socket _openDataConnection_(String command, String arg) throws IOException {
|
||||
Socket socket = super._openDataConnection_(command, arg);
|
||||
_prepareDataSocket_(socket);
|
||||
if (socket instanceof SSLSocket) {
|
||||
SSLSocket sslSocket = (SSLSocket)socket;
|
||||
sslSocket.setUseClientMode(this.isClientMode);
|
||||
sslSocket.setEnableSessionCreation(this.isCreation);
|
||||
if (!this.isClientMode) {
|
||||
sslSocket.setNeedClientAuth(this.isNeedClientAuth);
|
||||
sslSocket.setWantClientAuth(this.isWantClientAuth);
|
||||
}
|
||||
if (this.suites != null)
|
||||
sslSocket.setEnabledCipherSuites(this.suites);
|
||||
if (this.protocols != null)
|
||||
sslSocket.setEnabledProtocols(this.protocols);
|
||||
sslSocket.startHandshake();
|
||||
}
|
||||
return socket;
|
||||
}
|
||||
|
||||
protected void _prepareDataSocket_(Socket socket) throws IOException {}
|
||||
|
||||
public TrustManager getTrustManager() {
|
||||
return this.trustManager;
|
||||
}
|
||||
|
||||
public void setTrustManager(TrustManager trustManager) {
|
||||
this.trustManager = trustManager;
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
super.disconnect();
|
||||
setSocketFactory(null);
|
||||
setServerSocketFactory(null);
|
||||
}
|
||||
|
||||
public int execAUTH(String mechanism) throws IOException {
|
||||
return sendCommand("AUTH", mechanism);
|
||||
}
|
||||
|
||||
public int execADAT(byte[] data) throws IOException {
|
||||
if (data != null)
|
||||
return sendCommand("ADAT", Base64.encodeBase64StringUnChunked(data));
|
||||
return sendCommand("ADAT");
|
||||
}
|
||||
|
||||
public int execCCC() throws IOException {
|
||||
int repCode = sendCommand("CCC");
|
||||
return repCode;
|
||||
}
|
||||
|
||||
public int execMIC(byte[] data) throws IOException {
|
||||
if (data != null)
|
||||
return sendCommand("MIC", Base64.encodeBase64StringUnChunked(data));
|
||||
return sendCommand("MIC", "");
|
||||
}
|
||||
|
||||
public int execCONF(byte[] data) throws IOException {
|
||||
if (data != null)
|
||||
return sendCommand("CONF", Base64.encodeBase64StringUnChunked(data));
|
||||
return sendCommand("CONF", "");
|
||||
}
|
||||
|
||||
public int execENC(byte[] data) throws IOException {
|
||||
if (data != null)
|
||||
return sendCommand("ENC", Base64.encodeBase64StringUnChunked(data));
|
||||
return sendCommand("ENC", "");
|
||||
}
|
||||
|
||||
public byte[] parseADATReply(String reply) {
|
||||
if (reply == null)
|
||||
return null;
|
||||
return Base64.decodeBase64(extractPrefixedData("ADAT=", reply));
|
||||
}
|
||||
|
||||
private String extractPrefixedData(String prefix, String reply) {
|
||||
int idx = reply.indexOf(prefix);
|
||||
if (idx == -1)
|
||||
return null;
|
||||
return reply.substring(idx + prefix.length()).trim();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
@Deprecated
|
||||
public final class FTPSCommand {
|
||||
public static final int AUTH = 0;
|
||||
|
||||
public static final int ADAT = 1;
|
||||
|
||||
public static final int PBSZ = 2;
|
||||
|
||||
public static final int PROT = 3;
|
||||
|
||||
public static final int CCC = 4;
|
||||
|
||||
public static final int AUTHENTICATION_SECURITY_MECHANISM = 0;
|
||||
|
||||
public static final int AUTHENTICATION_SECURITY_DATA = 1;
|
||||
|
||||
public static final int PROTECTION_BUFFER_SIZE = 2;
|
||||
|
||||
public static final int DATA_CHANNEL_PROTECTION_LEVEL = 3;
|
||||
|
||||
public static final int CLEAR_COMMAND_CHANNEL = 4;
|
||||
|
||||
private static final String[] _commands = new String[] { "AUTH", "ADAT", "PBSZ", "PROT", "CCC" };
|
||||
|
||||
public static final String getCommand(int command) {
|
||||
return _commands[command];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
|
||||
public class FTPSServerSocketFactory extends ServerSocketFactory {
|
||||
private final SSLContext context;
|
||||
|
||||
public FTPSServerSocketFactory(SSLContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket() throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket());
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket(int port) throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket(port));
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket(int port, int backlog) throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket(port, backlog));
|
||||
}
|
||||
|
||||
public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket(port, backlog, ifAddress));
|
||||
}
|
||||
|
||||
public ServerSocket init(ServerSocket socket) {
|
||||
((SSLServerSocket)socket).setUseClientMode(true);
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
|
||||
public class FTPSSocketFactory extends SocketFactory {
|
||||
private final SSLContext context;
|
||||
|
||||
public FTPSSocketFactory(SSLContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public Socket createSocket() throws IOException {
|
||||
return this.context.getSocketFactory().createSocket();
|
||||
}
|
||||
|
||||
public Socket createSocket(String address, int port) throws UnknownHostException, IOException {
|
||||
return this.context.getSocketFactory().createSocket(address, port);
|
||||
}
|
||||
|
||||
public Socket createSocket(InetAddress address, int port) throws IOException {
|
||||
return this.context.getSocketFactory().createSocket(address, port);
|
||||
}
|
||||
|
||||
public Socket createSocket(String address, int port, InetAddress localAddress, int localPort) throws UnknownHostException, IOException {
|
||||
return this.context.getSocketFactory().createSocket(address, port, localAddress, localPort);
|
||||
}
|
||||
|
||||
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
||||
return this.context.getSocketFactory().createSocket(address, port, localAddress, localPort);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerSocket createServerSocket(int port) throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket(port));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerSocket createServerSocket(int port, int backlog) throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket(port, backlog));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException {
|
||||
return init(this.context.getServerSocketFactory().createServerSocket(port, backlog, ifAddress));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ServerSocket init(ServerSocket socket) throws IOException {
|
||||
((SSLServerSocket)socket).setUseClientMode(true);
|
||||
return socket;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package org.apache.commons.net.ftp;
|
||||
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
@Deprecated
|
||||
public class FTPSTrustManager implements X509TrustManager {
|
||||
private static final X509Certificate[] EMPTY_X509CERTIFICATE_ARRAY = new X509Certificate[0];
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] certificates, String authType) {}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
|
||||
for (X509Certificate certificate : certificates)
|
||||
certificate.checkValidity();
|
||||
}
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return EMPTY_X509CERTIFICATE_ARRAY;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
||||
import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
|
||||
|
||||
public class CompositeFileEntryParser extends FTPFileEntryParserImpl {
|
||||
private final FTPFileEntryParser[] ftpFileEntryParsers;
|
||||
|
||||
private FTPFileEntryParser cachedFtpFileEntryParser;
|
||||
|
||||
public CompositeFileEntryParser(FTPFileEntryParser[] ftpFileEntryParsers) {
|
||||
this.cachedFtpFileEntryParser = null;
|
||||
this.ftpFileEntryParsers = ftpFileEntryParsers;
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String listEntry) {
|
||||
if (this.cachedFtpFileEntryParser != null) {
|
||||
FTPFile matched = this.cachedFtpFileEntryParser.parseFTPEntry(listEntry);
|
||||
if (matched != null)
|
||||
return matched;
|
||||
} else {
|
||||
for (FTPFileEntryParser ftpFileEntryParser : this.ftpFileEntryParsers) {
|
||||
FTPFile matched = ftpFileEntryParser.parseFTPEntry(listEntry);
|
||||
if (matched != null) {
|
||||
this.cachedFtpFileEntryParser = ftpFileEntryParser;
|
||||
return matched;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
import org.apache.commons.net.ftp.Configurable;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
|
||||
public abstract class ConfigurableFTPFileEntryParserImpl extends RegexFTPFileEntryParserImpl implements Configurable {
|
||||
private final FTPTimestampParser timestampParser;
|
||||
|
||||
public ConfigurableFTPFileEntryParserImpl(String regex) {
|
||||
super(regex);
|
||||
this.timestampParser = new FTPTimestampParserImpl();
|
||||
}
|
||||
|
||||
public Calendar parseTimestamp(String timestampStr) throws ParseException {
|
||||
return this.timestampParser.parseTimestamp(timestampStr);
|
||||
}
|
||||
|
||||
public void configure(FTPClientConfig config) {
|
||||
if (this.timestampParser instanceof Configurable) {
|
||||
FTPClientConfig defaultCfg = getDefaultConfiguration();
|
||||
if (config != null) {
|
||||
if (null == config.getDefaultDateFormatStr())
|
||||
config.setDefaultDateFormatStr(defaultCfg.getDefaultDateFormatStr());
|
||||
if (null == config.getRecentDateFormatStr())
|
||||
config.setRecentDateFormatStr(defaultCfg.getRecentDateFormatStr());
|
||||
((Configurable)this.timestampParser).configure(config);
|
||||
} else {
|
||||
((Configurable)this.timestampParser).configure(defaultCfg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract FTPClientConfig getDefaultConfiguration();
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.net.ftp.Configurable;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
||||
|
||||
public class DefaultFTPFileEntryParserFactory implements FTPFileEntryParserFactory {
|
||||
private static final String JAVA_IDENTIFIER = "\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart})*";
|
||||
|
||||
private static final String JAVA_QUALIFIED_NAME = "(\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart})*\\.)+\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart})*";
|
||||
|
||||
private static final Pattern JAVA_QUALIFIED_NAME_PATTERN = Pattern.compile("(\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart})*\\.)+\\p{javaJavaIdentifierStart}(\\p{javaJavaIdentifierPart})*");
|
||||
|
||||
public FTPFileEntryParser createFileEntryParser(String key) {
|
||||
if (key == null)
|
||||
throw new ParserInitializationException("Parser key cannot be null");
|
||||
return createFileEntryParser(key, null);
|
||||
}
|
||||
|
||||
private FTPFileEntryParser createFileEntryParser(String key, FTPClientConfig config) {
|
||||
FTPFileEntryParser parser = null;
|
||||
if (JAVA_QUALIFIED_NAME_PATTERN.matcher(key).matches())
|
||||
try {
|
||||
Class<?> parserClass = Class.forName(key);
|
||||
try {
|
||||
parser = (FTPFileEntryParser)parserClass.newInstance();
|
||||
} catch (ClassCastException e) {
|
||||
throw new ParserInitializationException(parserClass.getName() + " does not implement the interface " + "org.apache.commons.net.ftp.FTPFileEntryParser.", e);
|
||||
} catch (Exception e) {
|
||||
throw new ParserInitializationException("Error initializing parser", e);
|
||||
} catch (ExceptionInInitializerError e) {
|
||||
throw new ParserInitializationException("Error initializing parser", e);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {}
|
||||
if (parser == null) {
|
||||
String ukey = key.toUpperCase(Locale.ENGLISH);
|
||||
if (ukey.indexOf("UNIX") >= 0) {
|
||||
parser = new UnixFTPEntryParser(config);
|
||||
} else if (ukey.indexOf("VMS") >= 0) {
|
||||
parser = new VMSVersioningFTPEntryParser(config);
|
||||
} else if (ukey.indexOf("WINDOWS") >= 0) {
|
||||
parser = createNTFTPEntryParser(config);
|
||||
} else if (ukey.indexOf("OS/2") >= 0) {
|
||||
parser = new OS2FTPEntryParser(config);
|
||||
} else if (ukey.indexOf("OS/400") >= 0 || ukey.indexOf("AS/400") >= 0) {
|
||||
parser = createOS400FTPEntryParser(config);
|
||||
} else if (ukey.indexOf("MVS") >= 0) {
|
||||
parser = new MVSFTPEntryParser();
|
||||
} else if (ukey.indexOf("NETWARE") >= 0) {
|
||||
parser = new NetwareFTPEntryParser(config);
|
||||
} else if (ukey.indexOf("MACOS PETER") >= 0) {
|
||||
parser = new MacOsPeterFTPEntryParser(config);
|
||||
} else if (ukey.indexOf("TYPE: L8") >= 0) {
|
||||
parser = new UnixFTPEntryParser(config);
|
||||
} else {
|
||||
throw new ParserInitializationException("Unknown parser type: " + key);
|
||||
}
|
||||
}
|
||||
if (parser instanceof Configurable)
|
||||
((Configurable)parser).configure(config);
|
||||
return parser;
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createFileEntryParser(FTPClientConfig config) throws ParserInitializationException {
|
||||
String key = config.getServerSystemKey();
|
||||
return createFileEntryParser(key, config);
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createUnixFTPEntryParser() {
|
||||
return new UnixFTPEntryParser();
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createVMSVersioningFTPEntryParser() {
|
||||
return new VMSVersioningFTPEntryParser();
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createNetwareFTPEntryParser() {
|
||||
return new NetwareFTPEntryParser();
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createNTFTPEntryParser() {
|
||||
return createNTFTPEntryParser(null);
|
||||
}
|
||||
|
||||
private FTPFileEntryParser createNTFTPEntryParser(FTPClientConfig config) {
|
||||
if (config != null && "WINDOWS".equals(config.getServerSystemKey()))
|
||||
return new NTFTPEntryParser(config);
|
||||
return new CompositeFileEntryParser(new FTPFileEntryParser[] { new NTFTPEntryParser(config), new UnixFTPEntryParser(config) });
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createOS2FTPEntryParser() {
|
||||
return new OS2FTPEntryParser();
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createOS400FTPEntryParser() {
|
||||
return createOS400FTPEntryParser(null);
|
||||
}
|
||||
|
||||
private FTPFileEntryParser createOS400FTPEntryParser(FTPClientConfig config) {
|
||||
if (config != null && "OS/400".equals(config.getServerSystemKey()))
|
||||
return new OS400FTPEntryParser(config);
|
||||
return new CompositeFileEntryParser(new FTPFileEntryParser[] { new OS400FTPEntryParser(config), new UnixFTPEntryParser(config) });
|
||||
}
|
||||
|
||||
public FTPFileEntryParser createMVSEntryParser() {
|
||||
return new MVSFTPEntryParser();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.util.Calendar;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class EnterpriseUnixFTPEntryParser extends RegexFTPFileEntryParserImpl {
|
||||
private static final String MONTHS = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
|
||||
|
||||
private static final String REGEX = "(([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z]))(\\S*)\\s*(\\S+)\\s*(\\S*)\\s*(\\d*)\\s*(\\d*)\\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s*((?:[012]\\d*)|(?:3[01]))\\s*((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s(\\S*)(\\s*.*)";
|
||||
|
||||
public EnterpriseUnixFTPEntryParser() {
|
||||
super("(([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z])([\\-]|[A-Z]))(\\S*)\\s*(\\S+)\\s*(\\S*)\\s*(\\d*)\\s*(\\d*)\\s*(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s*((?:[012]\\d*)|(?:3[01]))\\s*((\\d\\d\\d\\d)|((?:[01]\\d)|(?:2[0123])):([012345]\\d))\\s(\\S*)(\\s*.*)");
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile file = new FTPFile();
|
||||
file.setRawListing(entry);
|
||||
if (matches(entry)) {
|
||||
String usr = group(14);
|
||||
String grp = group(15);
|
||||
String filesize = group(16);
|
||||
String mo = group(17);
|
||||
String da = group(18);
|
||||
String yr = group(20);
|
||||
String hr = group(21);
|
||||
String min = group(22);
|
||||
String name = group(23);
|
||||
file.setType(0);
|
||||
file.setUser(usr);
|
||||
file.setGroup(grp);
|
||||
try {
|
||||
file.setSize(Long.parseLong(filesize));
|
||||
} catch (NumberFormatException e) {}
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(14, 0);
|
||||
cal.set(13, 0);
|
||||
cal.set(12, 0);
|
||||
cal.set(11, 0);
|
||||
try {
|
||||
int pos = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)".indexOf(mo);
|
||||
int month = pos / 4;
|
||||
if (yr != null) {
|
||||
cal.set(1, Integer.parseInt(yr));
|
||||
} else {
|
||||
int year = cal.get(1);
|
||||
if (cal.get(2) < month)
|
||||
year--;
|
||||
cal.set(1, year);
|
||||
cal.set(11, Integer.parseInt(hr));
|
||||
cal.set(12, Integer.parseInt(min));
|
||||
}
|
||||
cal.set(2, month);
|
||||
cal.set(5, Integer.parseInt(da));
|
||||
file.setTimestamp(cal);
|
||||
} catch (NumberFormatException e) {}
|
||||
file.setName(name);
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFileEntryParser;
|
||||
|
||||
public interface FTPFileEntryParserFactory {
|
||||
FTPFileEntryParser createFileEntryParser(String paramString) throws ParserInitializationException;
|
||||
|
||||
FTPFileEntryParser createFileEntryParser(FTPClientConfig paramFTPClientConfig) throws ParserInitializationException;
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
|
||||
public interface FTPTimestampParser {
|
||||
public static final String DEFAULT_SDF = "MMM d yyyy";
|
||||
|
||||
public static final String DEFAULT_RECENT_SDF = "MMM d HH:mm";
|
||||
|
||||
Calendar parseTimestamp(String paramString) throws ParseException;
|
||||
}
|
||||
|
|
@ -0,0 +1,144 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import org.apache.commons.net.ftp.Configurable;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
|
||||
public class FTPTimestampParserImpl implements FTPTimestampParser, Configurable {
|
||||
private SimpleDateFormat defaultDateFormat;
|
||||
|
||||
private SimpleDateFormat recentDateFormat;
|
||||
|
||||
private boolean lenientFutureDates = false;
|
||||
|
||||
public FTPTimestampParserImpl() {
|
||||
setDefaultDateFormat("MMM d yyyy");
|
||||
setRecentDateFormat("MMM d HH:mm");
|
||||
}
|
||||
|
||||
public Calendar parseTimestamp(String timestampStr) throws ParseException {
|
||||
Calendar now = Calendar.getInstance();
|
||||
return parseTimestamp(timestampStr, now);
|
||||
}
|
||||
|
||||
public Calendar parseTimestamp(String timestampStr, Calendar serverTime) throws ParseException {
|
||||
Calendar working = (Calendar)serverTime.clone();
|
||||
working.setTimeZone(getServerTimeZone());
|
||||
Date parsed = null;
|
||||
if (this.recentDateFormat != null) {
|
||||
Calendar now = (Calendar)serverTime.clone();
|
||||
now.setTimeZone(getServerTimeZone());
|
||||
if (this.lenientFutureDates)
|
||||
now.add(5, 1);
|
||||
String year = Integer.toString(now.get(1));
|
||||
String timeStampStrPlusYear = timestampStr + " " + year;
|
||||
SimpleDateFormat hackFormatter = new SimpleDateFormat(this.recentDateFormat.toPattern() + " yyyy", this.recentDateFormat.getDateFormatSymbols());
|
||||
hackFormatter.setLenient(false);
|
||||
hackFormatter.setTimeZone(this.recentDateFormat.getTimeZone());
|
||||
ParsePosition parsePosition = new ParsePosition(0);
|
||||
parsed = hackFormatter.parse(timeStampStrPlusYear, parsePosition);
|
||||
if (parsed != null && parsePosition.getIndex() == timeStampStrPlusYear.length()) {
|
||||
working.setTime(parsed);
|
||||
if (working.after(now))
|
||||
working.add(1, -1);
|
||||
return working;
|
||||
}
|
||||
}
|
||||
ParsePosition pp = new ParsePosition(0);
|
||||
parsed = this.defaultDateFormat.parse(timestampStr, pp);
|
||||
if (parsed != null && pp.getIndex() == timestampStr.length()) {
|
||||
working.setTime(parsed);
|
||||
} else {
|
||||
throw new ParseException("Timestamp '" + timestampStr + "' could not be parsed using a server time of " + serverTime.getTime().toString(), pp.getErrorIndex());
|
||||
}
|
||||
return working;
|
||||
}
|
||||
|
||||
public SimpleDateFormat getDefaultDateFormat() {
|
||||
return this.defaultDateFormat;
|
||||
}
|
||||
|
||||
public String getDefaultDateFormatString() {
|
||||
return this.defaultDateFormat.toPattern();
|
||||
}
|
||||
|
||||
private void setDefaultDateFormat(String format) {
|
||||
if (format != null) {
|
||||
this.defaultDateFormat = new SimpleDateFormat(format);
|
||||
this.defaultDateFormat.setLenient(false);
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleDateFormat getRecentDateFormat() {
|
||||
return this.recentDateFormat;
|
||||
}
|
||||
|
||||
public String getRecentDateFormatString() {
|
||||
return this.recentDateFormat.toPattern();
|
||||
}
|
||||
|
||||
private void setRecentDateFormat(String format) {
|
||||
if (format != null) {
|
||||
this.recentDateFormat = new SimpleDateFormat(format);
|
||||
this.recentDateFormat.setLenient(false);
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getShortMonths() {
|
||||
return this.defaultDateFormat.getDateFormatSymbols().getShortMonths();
|
||||
}
|
||||
|
||||
public TimeZone getServerTimeZone() {
|
||||
return this.defaultDateFormat.getTimeZone();
|
||||
}
|
||||
|
||||
private void setServerTimeZone(String serverTimeZoneId) {
|
||||
TimeZone serverTimeZone = TimeZone.getDefault();
|
||||
if (serverTimeZoneId != null)
|
||||
serverTimeZone = TimeZone.getTimeZone(serverTimeZoneId);
|
||||
this.defaultDateFormat.setTimeZone(serverTimeZone);
|
||||
if (this.recentDateFormat != null)
|
||||
this.recentDateFormat.setTimeZone(serverTimeZone);
|
||||
}
|
||||
|
||||
public void configure(FTPClientConfig config) {
|
||||
DateFormatSymbols dfs = null;
|
||||
String languageCode = config.getServerLanguageCode();
|
||||
String shortmonths = config.getShortMonthNames();
|
||||
if (shortmonths != null) {
|
||||
dfs = FTPClientConfig.getDateFormatSymbols(shortmonths);
|
||||
} else if (languageCode != null) {
|
||||
dfs = FTPClientConfig.lookupDateFormatSymbols(languageCode);
|
||||
} else {
|
||||
dfs = FTPClientConfig.lookupDateFormatSymbols("en");
|
||||
}
|
||||
String recentFormatString = config.getRecentDateFormatStr();
|
||||
if (recentFormatString == null) {
|
||||
this.recentDateFormat = null;
|
||||
} else {
|
||||
this.recentDateFormat = new SimpleDateFormat(recentFormatString, dfs);
|
||||
this.recentDateFormat.setLenient(false);
|
||||
}
|
||||
String defaultFormatString = config.getDefaultDateFormatStr();
|
||||
if (defaultFormatString == null)
|
||||
throw new IllegalArgumentException("defaultFormatString cannot be null");
|
||||
this.defaultDateFormat = new SimpleDateFormat(defaultFormatString, dfs);
|
||||
this.defaultDateFormat.setLenient(false);
|
||||
setServerTimeZone(config.getServerTimeZoneId());
|
||||
this.lenientFutureDates = config.isLenientFutureDates();
|
||||
}
|
||||
|
||||
boolean isLenientFutureDates() {
|
||||
return this.lenientFutureDates;
|
||||
}
|
||||
|
||||
void setLenientFutureDates(boolean lenientFutureDates) {
|
||||
this.lenientFutureDates = lenientFutureDates;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
|
||||
|
||||
public class MLSxEntryParser extends FTPFileEntryParserImpl {
|
||||
private static final MLSxEntryParser PARSER = new MLSxEntryParser();
|
||||
|
||||
private static final HashMap<String, Integer> TYPE_TO_INT = new HashMap<String, Integer>();
|
||||
|
||||
static {
|
||||
TYPE_TO_INT.put("file", Integer.valueOf(0));
|
||||
TYPE_TO_INT.put("cdir", Integer.valueOf(1));
|
||||
TYPE_TO_INT.put("pdir", Integer.valueOf(1));
|
||||
TYPE_TO_INT.put("dir", Integer.valueOf(1));
|
||||
}
|
||||
|
||||
private static int[] UNIX_GROUPS = new int[] { 0, 1, 2 };
|
||||
|
||||
private static int[][] UNIX_PERMS = new int[][] { {}, new int[] { 2 }, new int[] { 1 }, new int[] { 2, 1 }, new int[] { 0 }, new int[] { 0, 2 }, new int[] { 0, 1 }, new int[] { 0, 1, 2 } };
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
String[] parts = entry.split(" ", 2);
|
||||
if (parts.length != 2)
|
||||
return null;
|
||||
FTPFile file = new FTPFile();
|
||||
file.setRawListing(entry);
|
||||
file.setName(parts[1]);
|
||||
String[] facts = parts[0].split(";");
|
||||
boolean hasUnixMode = parts[0].toLowerCase(Locale.ENGLISH).contains("unix.mode=");
|
||||
for (String fact : facts) {
|
||||
String[] factparts = fact.split("=");
|
||||
if (factparts.length == 2) {
|
||||
String factname = factparts[0].toLowerCase(Locale.ENGLISH);
|
||||
String factvalue = factparts[1];
|
||||
String valueLowerCase = factvalue.toLowerCase(Locale.ENGLISH);
|
||||
if ("size".equals(factname)) {
|
||||
file.setSize(Long.parseLong(factvalue));
|
||||
} else if ("sizd".equals(factname)) {
|
||||
file.setSize(Long.parseLong(factvalue));
|
||||
} else if ("modify".equals(factname)) {
|
||||
SimpleDateFormat sdf;
|
||||
if (factvalue.contains(".")) {
|
||||
sdf = new SimpleDateFormat("yyyyMMddHHmmss.SSS");
|
||||
} else {
|
||||
sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
}
|
||||
TimeZone GMT = TimeZone.getTimeZone("GMT");
|
||||
sdf.setTimeZone(GMT);
|
||||
GregorianCalendar gc = new GregorianCalendar(GMT);
|
||||
try {
|
||||
gc.setTime(sdf.parse(factvalue));
|
||||
} catch (ParseException e) {}
|
||||
file.setTimestamp(gc);
|
||||
} else if ("type".equals(factname)) {
|
||||
Integer intType = TYPE_TO_INT.get(valueLowerCase);
|
||||
if (intType == null) {
|
||||
file.setType(3);
|
||||
} else {
|
||||
file.setType(intType.intValue());
|
||||
}
|
||||
} else if (factname.startsWith("unix.")) {
|
||||
String unixfact = factname.substring("unix.".length()).toLowerCase(Locale.ENGLISH);
|
||||
if ("group".equals(unixfact)) {
|
||||
file.setGroup(factvalue);
|
||||
} else if ("owner".equals(unixfact)) {
|
||||
file.setUser(factvalue);
|
||||
} else if ("mode".equals(unixfact)) {
|
||||
int off = factvalue.length() - 3;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
int ch = factvalue.charAt(off + i) - 48;
|
||||
if (ch >= 0 && ch <= 7)
|
||||
for (int p : UNIX_PERMS[ch])
|
||||
file.setPermission(UNIX_GROUPS[i], p, true);
|
||||
}
|
||||
}
|
||||
} else if (!hasUnixMode && "perm".equals(factname)) {
|
||||
doUnixPerms(file, valueLowerCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
private void doUnixPerms(FTPFile file, String valueLowerCase) {
|
||||
for (char c : valueLowerCase.toCharArray()) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
file.setPermission(0, 1, true);
|
||||
break;
|
||||
case 'c':
|
||||
file.setPermission(0, 1, true);
|
||||
break;
|
||||
case 'd':
|
||||
file.setPermission(0, 1, true);
|
||||
break;
|
||||
case 'e':
|
||||
file.setPermission(0, 0, true);
|
||||
break;
|
||||
case 'l':
|
||||
file.setPermission(0, 2, true);
|
||||
break;
|
||||
case 'm':
|
||||
file.setPermission(0, 1, true);
|
||||
break;
|
||||
case 'p':
|
||||
file.setPermission(0, 1, true);
|
||||
break;
|
||||
case 'r':
|
||||
file.setPermission(0, 0, true);
|
||||
break;
|
||||
case 'w':
|
||||
file.setPermission(0, 1, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FTPFile parseEntry(String entry) {
|
||||
return PARSER.parseFTPEntry(entry);
|
||||
}
|
||||
|
||||
public static MLSxEntryParser getInstance() {
|
||||
return PARSER;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class MVSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
static final int UNKNOWN_LIST_TYPE = -1;
|
||||
|
||||
static final int FILE_LIST_TYPE = 0;
|
||||
|
||||
static final int MEMBER_LIST_TYPE = 1;
|
||||
|
||||
static final int UNIX_LIST_TYPE = 2;
|
||||
|
||||
static final int JES_LEVEL_1_LIST_TYPE = 3;
|
||||
|
||||
static final int JES_LEVEL_2_LIST_TYPE = 4;
|
||||
|
||||
private int isType = -1;
|
||||
|
||||
private UnixFTPEntryParser unixFTPEntryParser;
|
||||
|
||||
static final String DEFAULT_DATE_FORMAT = "yyyy/MM/dd HH:mm";
|
||||
|
||||
static final String FILE_LIST_REGEX = "\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+[FV]\\S*\\s+\\S+\\s+\\S+\\s+(PS|PO|PO-E)\\s+(\\S+)\\s*";
|
||||
|
||||
static final String MEMBER_LIST_REGEX = "(\\S+)\\s+\\S+\\s+\\S+\\s+(\\S+)\\s+(\\S+)\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s*";
|
||||
|
||||
static final String JES_LEVEL_1_LIST_REGEX = "(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*";
|
||||
|
||||
static final String JES_LEVEL_2_LIST_REGEX = "(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+).*";
|
||||
|
||||
public MVSFTPEntryParser() {
|
||||
super("");
|
||||
configure(null);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
boolean isParsed = false;
|
||||
FTPFile f = new FTPFile();
|
||||
if (this.isType == 0) {
|
||||
isParsed = parseFileList(f, entry);
|
||||
} else if (this.isType == 1) {
|
||||
isParsed = parseMemberList(f, entry);
|
||||
if (!isParsed)
|
||||
isParsed = parseSimpleEntry(f, entry);
|
||||
} else if (this.isType == 2) {
|
||||
isParsed = parseUnixList(f, entry);
|
||||
} else if (this.isType == 3) {
|
||||
isParsed = parseJeslevel1List(f, entry);
|
||||
} else if (this.isType == 4) {
|
||||
isParsed = parseJeslevel2List(f, entry);
|
||||
}
|
||||
if (!isParsed)
|
||||
f = null;
|
||||
return f;
|
||||
}
|
||||
|
||||
private boolean parseFileList(FTPFile file, String entry) {
|
||||
if (matches(entry)) {
|
||||
file.setRawListing(entry);
|
||||
String name = group(2);
|
||||
String dsorg = group(1);
|
||||
file.setName(name);
|
||||
if ("PS".equals(dsorg)) {
|
||||
file.setType(0);
|
||||
} else if ("PO".equals(dsorg) || "PO-E".equals(dsorg)) {
|
||||
file.setType(1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean parseMemberList(FTPFile file, String entry) {
|
||||
if (matches(entry)) {
|
||||
file.setRawListing(entry);
|
||||
String name = group(1);
|
||||
String datestr = group(2) + " " + group(3);
|
||||
file.setName(name);
|
||||
file.setType(0);
|
||||
try {
|
||||
file.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean parseSimpleEntry(FTPFile file, String entry) {
|
||||
if (entry != null && entry.trim().length() > 0) {
|
||||
file.setRawListing(entry);
|
||||
String name = entry.split(" ")[0];
|
||||
file.setName(name);
|
||||
file.setType(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean parseUnixList(FTPFile file, String entry) {
|
||||
file = this.unixFTPEntryParser.parseFTPEntry(entry);
|
||||
if (file == null)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean parseJeslevel1List(FTPFile file, String entry) {
|
||||
if (matches(entry) &&
|
||||
group(3).equalsIgnoreCase("OUTPUT")) {
|
||||
file.setRawListing(entry);
|
||||
String name = group(2);
|
||||
file.setName(name);
|
||||
file.setType(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean parseJeslevel2List(FTPFile file, String entry) {
|
||||
if (matches(entry) &&
|
||||
group(4).equalsIgnoreCase("OUTPUT")) {
|
||||
file.setRawListing(entry);
|
||||
String name = group(2);
|
||||
file.setName(name);
|
||||
file.setType(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<String> preParse(List<String> orig) {
|
||||
if (orig != null && orig.size() > 0) {
|
||||
String header = orig.get(0);
|
||||
if (header.indexOf("Volume") >= 0 && header.indexOf("Dsname") >= 0) {
|
||||
setType(0);
|
||||
setRegex("\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s+[FV]\\S*\\s+\\S+\\s+\\S+\\s+(PS|PO|PO-E)\\s+(\\S+)\\s*");
|
||||
} else if (header.indexOf("Name") >= 0 && header.indexOf("Id") >= 0) {
|
||||
setType(1);
|
||||
setRegex("(\\S+)\\s+\\S+\\s+\\S+\\s+(\\S+)\\s+(\\S+)\\s+\\S+\\s+\\S+\\s+\\S+\\s+\\S+\\s*");
|
||||
} else if (header.indexOf("total") == 0) {
|
||||
setType(2);
|
||||
this.unixFTPEntryParser = new UnixFTPEntryParser();
|
||||
} else if (header.indexOf("Spool Files") >= 30) {
|
||||
setType(3);
|
||||
setRegex("(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s*");
|
||||
} else if (header.indexOf("JOBNAME") == 0 && header.indexOf("JOBID") > 8) {
|
||||
setType(4);
|
||||
setRegex("(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(\\S+).*");
|
||||
} else {
|
||||
setType(-1);
|
||||
}
|
||||
if (this.isType != 3)
|
||||
orig.remove(0);
|
||||
}
|
||||
return orig;
|
||||
}
|
||||
|
||||
void setType(int type) {
|
||||
this.isType = type;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("MVS", "yyyy/MM/dd HH:mm", null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class MacOsPeterFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
static final String DEFAULT_DATE_FORMAT = "MMM d yyyy";
|
||||
|
||||
static final String DEFAULT_RECENT_DATE_FORMAT = "MMM d HH:mm";
|
||||
|
||||
private static final String REGEX = "([bcdelfmpSs-])(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s+((folder\\s+)|((\\d+)\\s+(\\d+)\\s+))(\\d+)\\s+((?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+\\S{3}))\\s+(\\d+(?::\\d+)?)\\s+(\\S*)(\\s*.*)";
|
||||
|
||||
public MacOsPeterFTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public MacOsPeterFTPEntryParser(FTPClientConfig config) {
|
||||
super("([bcdelfmpSs-])(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s+((folder\\s+)|((\\d+)\\s+(\\d+)\\s+))(\\d+)\\s+((?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+\\S{3}))\\s+(\\d+(?::\\d+)?)\\s+(\\S*)(\\s*.*)");
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile file = new FTPFile();
|
||||
file.setRawListing(entry);
|
||||
boolean isDevice = false;
|
||||
if (matches(entry)) {
|
||||
int type;
|
||||
String typeStr = group(1);
|
||||
String hardLinkCount = "0";
|
||||
String usr = null;
|
||||
String grp = null;
|
||||
String filesize = group(20);
|
||||
String datestr = group(21) + " " + group(22);
|
||||
String name = group(23);
|
||||
String endtoken = group(24);
|
||||
try {
|
||||
file.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {}
|
||||
switch (typeStr.charAt(0)) {
|
||||
case 'd':
|
||||
type = 1;
|
||||
break;
|
||||
case 'e':
|
||||
type = 2;
|
||||
break;
|
||||
case 'l':
|
||||
type = 2;
|
||||
break;
|
||||
case 'b':
|
||||
case 'c':
|
||||
isDevice = true;
|
||||
type = 0;
|
||||
break;
|
||||
case '-':
|
||||
case 'f':
|
||||
type = 0;
|
||||
break;
|
||||
default:
|
||||
type = 3;
|
||||
break;
|
||||
}
|
||||
file.setType(type);
|
||||
int g = 4;
|
||||
for (int access = 0; access < 3; access++, g += 4) {
|
||||
file.setPermission(access, 0, !group(g).equals("-"));
|
||||
file.setPermission(access, 1, !group(g + 1).equals("-"));
|
||||
String execPerm = group(g + 2);
|
||||
if (!execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0))) {
|
||||
file.setPermission(access, 2, true);
|
||||
} else {
|
||||
file.setPermission(access, 2, false);
|
||||
}
|
||||
}
|
||||
if (!isDevice)
|
||||
try {
|
||||
file.setHardLinkCount(Integer.parseInt(hardLinkCount));
|
||||
} catch (NumberFormatException e) {}
|
||||
file.setUser(usr);
|
||||
file.setGroup(grp);
|
||||
try {
|
||||
file.setSize(Long.parseLong(filesize));
|
||||
} catch (NumberFormatException e) {}
|
||||
if (null == endtoken) {
|
||||
file.setName(name);
|
||||
} else {
|
||||
name = name + endtoken;
|
||||
if (type == 2) {
|
||||
int end = name.indexOf(" -> ");
|
||||
if (end == -1) {
|
||||
file.setName(name);
|
||||
} else {
|
||||
file.setName(name.substring(0, end));
|
||||
file.setLink(name.substring(end + 4));
|
||||
}
|
||||
} else {
|
||||
file.setName(name);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("UNIX", "MMM d yyyy", "MMM d HH:mm", null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.apache.commons.net.ftp.Configurable;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class NTFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
private static final String DEFAULT_DATE_FORMAT = "MM-dd-yy hh:mma";
|
||||
|
||||
private static final String DEFAULT_DATE_FORMAT2 = "MM-dd-yy kk:mm";
|
||||
|
||||
private final FTPTimestampParser timestampParser;
|
||||
|
||||
private static final String REGEX = "(\\S+)\\s+(\\S+)\\s+(?:(<DIR>)|([0-9]+))\\s+(\\S.*)";
|
||||
|
||||
public NTFTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public NTFTPEntryParser(FTPClientConfig config) {
|
||||
super("(\\S+)\\s+(\\S+)\\s+(?:(<DIR>)|([0-9]+))\\s+(\\S.*)");
|
||||
configure(config);
|
||||
FTPClientConfig config2 = new FTPClientConfig("WINDOWS", "MM-dd-yy kk:mm", null, null, null, null);
|
||||
config2.setDefaultDateFormatStr("MM-dd-yy kk:mm");
|
||||
this.timestampParser = new FTPTimestampParserImpl();
|
||||
((Configurable)this.timestampParser).configure(config2);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile f = new FTPFile();
|
||||
f.setRawListing(entry);
|
||||
if (matches(entry)) {
|
||||
String datestr = group(1) + " " + group(2);
|
||||
String dirString = group(3);
|
||||
String size = group(4);
|
||||
String name = group(5);
|
||||
try {
|
||||
f.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {
|
||||
try {
|
||||
f.setTimestamp(this.timestampParser.parseTimestamp(datestr));
|
||||
} catch (ParseException e2) {}
|
||||
}
|
||||
if (null == name || name.equals(".") || name.equals(".."))
|
||||
return null;
|
||||
f.setName(name);
|
||||
if ("<DIR>".equals(dirString)) {
|
||||
f.setType(1);
|
||||
f.setSize(0L);
|
||||
} else {
|
||||
f.setType(0);
|
||||
if (null != size)
|
||||
f.setSize(Long.parseLong(size));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("WINDOWS", "MM-dd-yy hh:mma", null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class NetwareFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
private static final String DEFAULT_DATE_FORMAT = "MMM dd yyyy";
|
||||
|
||||
private static final String DEFAULT_RECENT_DATE_FORMAT = "MMM dd HH:mm";
|
||||
|
||||
private static final String REGEX = "(d|-){1}\\s+\\[(.*)\\]\\s+(\\S+)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+((\\d+:\\d+)|(\\d{4})))\\s+(.*)";
|
||||
|
||||
public NetwareFTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public NetwareFTPEntryParser(FTPClientConfig config) {
|
||||
super("(d|-){1}\\s+\\[(.*)\\]\\s+(\\S+)\\s+(\\d+)\\s+(\\S+\\s+\\S+\\s+((\\d+:\\d+)|(\\d{4})))\\s+(.*)");
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile f = new FTPFile();
|
||||
if (matches(entry)) {
|
||||
String dirString = group(1);
|
||||
String attrib = group(2);
|
||||
String user = group(3);
|
||||
String size = group(4);
|
||||
String datestr = group(5);
|
||||
String name = group(9);
|
||||
try {
|
||||
f.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {}
|
||||
if (dirString.trim().equals("d")) {
|
||||
f.setType(1);
|
||||
} else {
|
||||
f.setType(0);
|
||||
}
|
||||
f.setUser(user);
|
||||
f.setName(name.trim());
|
||||
f.setSize(Long.parseLong(size.trim()));
|
||||
if (attrib.indexOf("R") != -1)
|
||||
f.setPermission(0, 0, true);
|
||||
if (attrib.indexOf("W") != -1)
|
||||
f.setPermission(0, 1, true);
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("NETWARE", "MMM dd yyyy", "MMM dd HH:mm", null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class OS2FTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
private static final String DEFAULT_DATE_FORMAT = "MM-dd-yy HH:mm";
|
||||
|
||||
private static final String REGEX = "\\s*([0-9]+)\\s*(\\s+|[A-Z]+)\\s*(DIR|\\s+)\\s*(\\S+)\\s+(\\S+)\\s+(\\S.*)";
|
||||
|
||||
public OS2FTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public OS2FTPEntryParser(FTPClientConfig config) {
|
||||
super("\\s*([0-9]+)\\s*(\\s+|[A-Z]+)\\s*(DIR|\\s+)\\s*(\\S+)\\s+(\\S+)\\s+(\\S.*)");
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile f = new FTPFile();
|
||||
if (matches(entry)) {
|
||||
String size = group(1);
|
||||
String attrib = group(2);
|
||||
String dirString = group(3);
|
||||
String datestr = group(4) + " " + group(5);
|
||||
String name = group(6);
|
||||
try {
|
||||
f.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {}
|
||||
if (dirString.trim().equals("DIR") || attrib.trim().equals("DIR")) {
|
||||
f.setType(1);
|
||||
} else {
|
||||
f.setType(0);
|
||||
}
|
||||
f.setName(name.trim());
|
||||
f.setSize(Long.parseLong(size.trim()));
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("OS/2", "MM-dd-yy HH:mm", null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class OS400FTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
private static final String DEFAULT_DATE_FORMAT = "yy/MM/dd HH:mm:ss";
|
||||
|
||||
private static final String REGEX = "(\\S+)\\s+(\\d+)\\s+(\\S+)\\s+(\\S+)\\s+(\\*\\S+)\\s+(\\S+/?)\\s*";
|
||||
|
||||
public OS400FTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public OS400FTPEntryParser(FTPClientConfig config) {
|
||||
super("(\\S+)\\s+(\\d+)\\s+(\\S+)\\s+(\\S+)\\s+(\\*\\S+)\\s+(\\S+/?)\\s*");
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile file = new FTPFile();
|
||||
file.setRawListing(entry);
|
||||
if (matches(entry)) {
|
||||
int type;
|
||||
String usr = group(1);
|
||||
String filesize = group(2);
|
||||
String datestr = group(3) + " " + group(4);
|
||||
String typeStr = group(5);
|
||||
String name = group(6);
|
||||
try {
|
||||
file.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {}
|
||||
if (typeStr.equalsIgnoreCase("*STMF")) {
|
||||
type = 0;
|
||||
} else if (typeStr.equalsIgnoreCase("*DIR")) {
|
||||
type = 1;
|
||||
} else {
|
||||
type = 3;
|
||||
}
|
||||
file.setType(type);
|
||||
file.setUser(usr);
|
||||
try {
|
||||
file.setSize(Long.parseLong(filesize));
|
||||
} catch (NumberFormatException e) {}
|
||||
if (name.endsWith("/"))
|
||||
name = name.substring(0, name.length() - 1);
|
||||
int pos = name.lastIndexOf('/');
|
||||
if (pos > -1)
|
||||
name = name.substring(pos + 1);
|
||||
file.setName(name);
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("OS/400", "yy/MM/dd HH:mm:ss", null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
public class ParserInitializationException extends RuntimeException {
|
||||
private static final long serialVersionUID = 5563335279583210658L;
|
||||
|
||||
public ParserInitializationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParserInitializationException(String message, Throwable rootCause) {
|
||||
super(message, rootCause);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Throwable getRootCause() {
|
||||
return getCause();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import org.apache.commons.net.ftp.FTPFileEntryParserImpl;
|
||||
|
||||
public abstract class RegexFTPFileEntryParserImpl extends FTPFileEntryParserImpl {
|
||||
private Pattern pattern = null;
|
||||
|
||||
private MatchResult result = null;
|
||||
|
||||
protected Matcher _matcher_ = null;
|
||||
|
||||
public RegexFTPFileEntryParserImpl(String regex) {
|
||||
setRegex(regex);
|
||||
}
|
||||
|
||||
public boolean matches(String s) {
|
||||
this.result = null;
|
||||
this._matcher_ = this.pattern.matcher(s);
|
||||
if (this._matcher_.matches())
|
||||
this.result = this._matcher_.toMatchResult();
|
||||
return (null != this.result);
|
||||
}
|
||||
|
||||
public int getGroupCnt() {
|
||||
if (this.result == null)
|
||||
return 0;
|
||||
return this.result.groupCount();
|
||||
}
|
||||
|
||||
public String group(int matchnum) {
|
||||
if (this.result == null)
|
||||
return null;
|
||||
return this.result.group(matchnum);
|
||||
}
|
||||
|
||||
public String getGroupsAsString() {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for (int i = 1; i <= this.result.groupCount(); i++)
|
||||
b.append(i).append(") ").append(this.result.group(i)).append(System.getProperty("line.separator"));
|
||||
return b.toString();
|
||||
}
|
||||
|
||||
public boolean setRegex(String regex) {
|
||||
try {
|
||||
this.pattern = Pattern.compile(regex);
|
||||
return true;
|
||||
} catch (PatternSyntaxException pse) {
|
||||
throw new IllegalArgumentException("Unparseable regex supplied: " + regex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
|
||||
public class UnixFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
static final String DEFAULT_DATE_FORMAT = "MMM d yyyy";
|
||||
|
||||
static final String DEFAULT_RECENT_DATE_FORMAT = "MMM d HH:mm";
|
||||
|
||||
static final String NUMERIC_DATE_FORMAT = "yyyy-MM-dd HH:mm";
|
||||
|
||||
public static final FTPClientConfig NUMERIC_DATE_CONFIG = new FTPClientConfig("UNIX", "yyyy-MM-dd HH:mm", null, null, null, null);
|
||||
|
||||
private static final String REGEX = "([bcdelfmpSs-])(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s*(\\d+)\\s+(?:(\\S+(?:\\s\\S+)*?)\\s+)?(?:(\\S+(?:\\s\\S+)*)\\s+)?(\\d+(?:,\\s*\\d+)?)\\s+((?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+\\S{3}))\\s+(\\d+(?::\\d+)?)\\s+(\\S*)(\\s*.*)";
|
||||
|
||||
public UnixFTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public UnixFTPEntryParser(FTPClientConfig config) {
|
||||
super("([bcdelfmpSs-])(((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-]))((r|-)(w|-)([xsStTL-])))\\+?\\s*(\\d+)\\s+(?:(\\S+(?:\\s\\S+)*?)\\s+)?(?:(\\S+(?:\\s\\S+)*)\\s+)?(\\d+(?:,\\s*\\d+)?)\\s+((?:\\d+[-/]\\d+[-/]\\d+)|(?:\\S{3}\\s+\\d{1,2})|(?:\\d{1,2}\\s+\\S{3}))\\s+(\\d+(?::\\d+)?)\\s+(\\S*)(\\s*.*)");
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public List<String> preParse(List<String> original) {
|
||||
ListIterator<String> iter = original.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
String entry = iter.next();
|
||||
if (entry.matches("^total \\d+$"))
|
||||
iter.remove();
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
FTPFile file = new FTPFile();
|
||||
file.setRawListing(entry);
|
||||
boolean isDevice = false;
|
||||
if (matches(entry)) {
|
||||
int type;
|
||||
String typeStr = group(1);
|
||||
String hardLinkCount = group(15);
|
||||
String usr = group(16);
|
||||
String grp = group(17);
|
||||
String filesize = group(18);
|
||||
String datestr = group(19) + " " + group(20);
|
||||
String name = group(21);
|
||||
String endtoken = group(22);
|
||||
try {
|
||||
file.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {}
|
||||
switch (typeStr.charAt(0)) {
|
||||
case 'd':
|
||||
type = 1;
|
||||
break;
|
||||
case 'e':
|
||||
type = 2;
|
||||
break;
|
||||
case 'l':
|
||||
type = 2;
|
||||
break;
|
||||
case 'b':
|
||||
case 'c':
|
||||
isDevice = true;
|
||||
type = 0;
|
||||
break;
|
||||
case '-':
|
||||
case 'f':
|
||||
type = 0;
|
||||
break;
|
||||
default:
|
||||
type = 3;
|
||||
break;
|
||||
}
|
||||
file.setType(type);
|
||||
int g = 4;
|
||||
for (int access = 0; access < 3; access++, g += 4) {
|
||||
file.setPermission(access, 0, !group(g).equals("-"));
|
||||
file.setPermission(access, 1, !group(g + 1).equals("-"));
|
||||
String execPerm = group(g + 2);
|
||||
if (!execPerm.equals("-") && !Character.isUpperCase(execPerm.charAt(0))) {
|
||||
file.setPermission(access, 2, true);
|
||||
} else {
|
||||
file.setPermission(access, 2, false);
|
||||
}
|
||||
}
|
||||
if (!isDevice)
|
||||
try {
|
||||
file.setHardLinkCount(Integer.parseInt(hardLinkCount));
|
||||
} catch (NumberFormatException e) {}
|
||||
file.setUser(usr);
|
||||
file.setGroup(grp);
|
||||
try {
|
||||
file.setSize(Long.parseLong(filesize));
|
||||
} catch (NumberFormatException e) {}
|
||||
if (null == endtoken) {
|
||||
file.setName(name);
|
||||
} else {
|
||||
name = name + endtoken;
|
||||
if (type == 2) {
|
||||
int end = name.indexOf(" -> ");
|
||||
if (end == -1) {
|
||||
file.setName(name);
|
||||
} else {
|
||||
file.setName(name.substring(0, end));
|
||||
file.setLink(name.substring(end + 4));
|
||||
}
|
||||
} else {
|
||||
file.setName(name);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("UNIX", "MMM d yyyy", "MMM d HH:mm", null, null, null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.StringTokenizer;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
import org.apache.commons.net.ftp.FTPFile;
|
||||
import org.apache.commons.net.ftp.FTPListParseEngine;
|
||||
|
||||
public class VMSFTPEntryParser extends ConfigurableFTPFileEntryParserImpl {
|
||||
private static final String DEFAULT_DATE_FORMAT = "d-MMM-yyyy HH:mm:ss";
|
||||
|
||||
private static final String REGEX = "(.*;[0-9]+)\\s*(\\d+)/\\d+\\s*(\\S+)\\s+(\\S+)\\s+\\[(([0-9$A-Za-z_]+)|([0-9$A-Za-z_]+),([0-9$a-zA-Z_]+))\\]?\\s*\\([a-zA-Z]*,([a-zA-Z]*),([a-zA-Z]*),([a-zA-Z]*)\\)";
|
||||
|
||||
public VMSFTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public VMSFTPEntryParser(FTPClientConfig config) {
|
||||
super("(.*;[0-9]+)\\s*(\\d+)/\\d+\\s*(\\S+)\\s+(\\S+)\\s+\\[(([0-9$A-Za-z_]+)|([0-9$A-Za-z_]+),([0-9$a-zA-Z_]+))\\]?\\s*\\([a-zA-Z]*,([a-zA-Z]*),([a-zA-Z]*),([a-zA-Z]*)\\)");
|
||||
configure(config);
|
||||
}
|
||||
|
||||
public FTPFile parseFTPEntry(String entry) {
|
||||
long longBlock = 512L;
|
||||
if (matches(entry)) {
|
||||
String grp, user;
|
||||
FTPFile f = new FTPFile();
|
||||
f.setRawListing(entry);
|
||||
String name = group(1);
|
||||
String size = group(2);
|
||||
String datestr = group(3) + " " + group(4);
|
||||
String owner = group(5);
|
||||
String[] permissions = new String[3];
|
||||
permissions[0] = group(9);
|
||||
permissions[1] = group(10);
|
||||
permissions[2] = group(11);
|
||||
try {
|
||||
f.setTimestamp(parseTimestamp(datestr));
|
||||
} catch (ParseException e) {}
|
||||
StringTokenizer t = new StringTokenizer(owner, ",");
|
||||
switch (t.countTokens()) {
|
||||
case 1:
|
||||
grp = null;
|
||||
user = t.nextToken();
|
||||
break;
|
||||
case 2:
|
||||
grp = t.nextToken();
|
||||
user = t.nextToken();
|
||||
break;
|
||||
default:
|
||||
grp = null;
|
||||
user = null;
|
||||
break;
|
||||
}
|
||||
if (name.lastIndexOf(".DIR") != -1) {
|
||||
f.setType(1);
|
||||
} else {
|
||||
f.setType(0);
|
||||
}
|
||||
if (isVersioning()) {
|
||||
f.setName(name);
|
||||
} else {
|
||||
name = name.substring(0, name.lastIndexOf(";"));
|
||||
f.setName(name);
|
||||
}
|
||||
long sizeInBytes = Long.parseLong(size) * longBlock;
|
||||
f.setSize(sizeInBytes);
|
||||
f.setGroup(grp);
|
||||
f.setUser(user);
|
||||
for (int access = 0; access < 3; access++) {
|
||||
String permission = permissions[access];
|
||||
f.setPermission(access, 0, (permission.indexOf('R') >= 0));
|
||||
f.setPermission(access, 1, (permission.indexOf('W') >= 0));
|
||||
f.setPermission(access, 2, (permission.indexOf('E') >= 0));
|
||||
}
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String readNextEntry(BufferedReader reader) throws IOException {
|
||||
String line = reader.readLine();
|
||||
StringBuilder entry = new StringBuilder();
|
||||
while (line != null) {
|
||||
if (line.startsWith("Directory") || line.startsWith("Total")) {
|
||||
line = reader.readLine();
|
||||
continue;
|
||||
}
|
||||
entry.append(line);
|
||||
if (line.trim().endsWith(")"))
|
||||
break;
|
||||
line = reader.readLine();
|
||||
}
|
||||
return (entry.length() == 0) ? null : entry.toString();
|
||||
}
|
||||
|
||||
protected boolean isVersioning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected FTPClientConfig getDefaultConfiguration() {
|
||||
return new FTPClientConfig("VMS", "d-MMM-yyyy HH:mm:ss", null, null, null, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public FTPFile[] parseFileList(InputStream listStream) throws IOException {
|
||||
FTPListParseEngine engine = new FTPListParseEngine(this);
|
||||
engine.readServerList(listStream, null);
|
||||
return engine.getFiles();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package org.apache.commons.net.ftp.parser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.regex.MatchResult;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
import org.apache.commons.net.ftp.FTPClientConfig;
|
||||
|
||||
public class VMSVersioningFTPEntryParser extends VMSFTPEntryParser {
|
||||
private final Pattern _preparse_pattern_;
|
||||
|
||||
private static final String PRE_PARSE_REGEX = "(.*);([0-9]+)\\s*.*";
|
||||
|
||||
public VMSVersioningFTPEntryParser() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public VMSVersioningFTPEntryParser(FTPClientConfig config) {
|
||||
configure(config);
|
||||
try {
|
||||
this._preparse_pattern_ = Pattern.compile("(.*);([0-9]+)\\s*.*");
|
||||
} catch (PatternSyntaxException pse) {
|
||||
throw new IllegalArgumentException("Unparseable regex supplied: (.*);([0-9]+)\\s*.*");
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> preParse(List<String> original) {
|
||||
HashMap<String, Integer> existingEntries = new HashMap<String, Integer>();
|
||||
ListIterator<String> iter = original.listIterator();
|
||||
while (iter.hasNext()) {
|
||||
String entry = iter.next().trim();
|
||||
MatchResult result = null;
|
||||
Matcher _preparse_matcher_ = this._preparse_pattern_.matcher(entry);
|
||||
if (_preparse_matcher_.matches()) {
|
||||
result = _preparse_matcher_.toMatchResult();
|
||||
String name = result.group(1);
|
||||
String version = result.group(2);
|
||||
Integer nv = Integer.valueOf(version);
|
||||
Integer existing = existingEntries.get(name);
|
||||
if (null != existing &&
|
||||
nv < existing) {
|
||||
iter.remove();
|
||||
continue;
|
||||
}
|
||||
existingEntries.put(name, nv);
|
||||
}
|
||||
}
|
||||
while (iter.hasPrevious()) {
|
||||
String entry = iter.previous().trim();
|
||||
MatchResult result = null;
|
||||
Matcher _preparse_matcher_ = this._preparse_pattern_.matcher(entry);
|
||||
if (_preparse_matcher_.matches()) {
|
||||
result = _preparse_matcher_.toMatchResult();
|
||||
String name = result.group(1);
|
||||
String version = result.group(2);
|
||||
Integer nv = Integer.valueOf(version);
|
||||
Integer existing = existingEntries.get(name);
|
||||
if (null != existing &&
|
||||
nv < existing)
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
protected boolean isVersioning() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
package org.apache.commons.net.imap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
|
||||
public class AuthenticatingIMAPClient extends IMAPSClient {
|
||||
public AuthenticatingIMAPClient() {
|
||||
this("TLS", false);
|
||||
}
|
||||
|
||||
public AuthenticatingIMAPClient(boolean implicit) {
|
||||
this("TLS", implicit);
|
||||
}
|
||||
|
||||
public AuthenticatingIMAPClient(String proto) {
|
||||
this(proto, false);
|
||||
}
|
||||
|
||||
public AuthenticatingIMAPClient(String proto, boolean implicit) {
|
||||
this(proto, implicit, null);
|
||||
}
|
||||
|
||||
public AuthenticatingIMAPClient(String proto, boolean implicit, SSLContext ctx) {
|
||||
super(proto, implicit, ctx);
|
||||
}
|
||||
|
||||
public AuthenticatingIMAPClient(boolean implicit, SSLContext ctx) {
|
||||
this("TLS", implicit, ctx);
|
||||
}
|
||||
|
||||
public AuthenticatingIMAPClient(SSLContext context) {
|
||||
this(false, context);
|
||||
}
|
||||
|
||||
public boolean authenticate(AUTH_METHOD method, String username, String password) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException {
|
||||
return auth(method, username, password);
|
||||
}
|
||||
|
||||
public boolean auth(AUTH_METHOD method, String username, String password) throws IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidKeySpecException {
|
||||
int i;
|
||||
byte[] serverChallenge;
|
||||
int result;
|
||||
Mac hmac_md5;
|
||||
byte[] hmacResult, usernameBytes, toEncode;
|
||||
int j;
|
||||
if (!IMAPReply.isContinuation(sendCommand(IMAPCommand.AUTHENTICATE, method.getAuthName())))
|
||||
return false;
|
||||
switch (method) {
|
||||
case PLAIN:
|
||||
i = sendData(Base64.encodeBase64StringUnChunked(("\000" + username + "\000" + password).getBytes(getCharsetName())));
|
||||
if (i == 0)
|
||||
setState(IMAP.IMAPState.AUTH_STATE);
|
||||
return (i == 0);
|
||||
case CRAM_MD5:
|
||||
serverChallenge = Base64.decodeBase64(getReplyString().substring(2).trim());
|
||||
hmac_md5 = Mac.getInstance("HmacMD5");
|
||||
hmac_md5.init(new SecretKeySpec(password.getBytes(getCharsetName()), "HmacMD5"));
|
||||
hmacResult = _convertToHexString(hmac_md5.doFinal(serverChallenge)).getBytes(getCharsetName());
|
||||
usernameBytes = username.getBytes(getCharsetName());
|
||||
toEncode = new byte[usernameBytes.length + 1 + hmacResult.length];
|
||||
System.arraycopy(usernameBytes, 0, toEncode, 0, usernameBytes.length);
|
||||
toEncode[usernameBytes.length] = 32;
|
||||
System.arraycopy(hmacResult, 0, toEncode, usernameBytes.length + 1, hmacResult.length);
|
||||
j = sendData(Base64.encodeBase64StringUnChunked(toEncode));
|
||||
if (j == 0)
|
||||
setState(IMAP.IMAPState.AUTH_STATE);
|
||||
return (j == 0);
|
||||
case LOGIN:
|
||||
if (sendData(Base64.encodeBase64StringUnChunked(username.getBytes(getCharsetName()))) != 3)
|
||||
return false;
|
||||
result = sendData(Base64.encodeBase64StringUnChunked(password.getBytes(getCharsetName())));
|
||||
if (result == 0)
|
||||
setState(IMAP.IMAPState.AUTH_STATE);
|
||||
return (result == 0);
|
||||
case XOAUTH:
|
||||
result = sendData(username);
|
||||
if (result == 0)
|
||||
setState(IMAP.IMAPState.AUTH_STATE);
|
||||
return (result == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String _convertToHexString(byte[] a) {
|
||||
StringBuilder result = new StringBuilder(a.length * 2);
|
||||
for (byte element : a) {
|
||||
if ((element & 0xFF) <= 15)
|
||||
result.append("0");
|
||||
result.append(Integer.toHexString(element & 0xFF));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public enum AUTH_METHOD {
|
||||
PLAIN("PLAIN"),
|
||||
CRAM_MD5("CRAM-MD5"),
|
||||
LOGIN("LOGIN"),
|
||||
XOAUTH("XOAUTH");
|
||||
|
||||
private final String authName;
|
||||
|
||||
AUTH_METHOD(String name) {
|
||||
this.authName = name;
|
||||
}
|
||||
|
||||
public final String getAuthName() {
|
||||
return this.authName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,179 @@
|
|||
package org.apache.commons.net.imap;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
import org.apache.commons.net.io.CRLFLineReader;
|
||||
|
||||
public class IMAP extends SocketClient {
|
||||
public static final int DEFAULT_PORT = 143;
|
||||
|
||||
protected static final String __DEFAULT_ENCODING = "ISO-8859-1";
|
||||
|
||||
private IMAPState __state;
|
||||
|
||||
protected BufferedWriter __writer;
|
||||
|
||||
protected BufferedReader _reader;
|
||||
|
||||
private int _replyCode;
|
||||
|
||||
private final List<String> _replyLines;
|
||||
|
||||
public enum IMAPState {
|
||||
DISCONNECTED_STATE, NOT_AUTH_STATE, AUTH_STATE, LOGOUT_STATE;
|
||||
}
|
||||
|
||||
private final char[] _initialID = new char[] { 'A', 'A', 'A', 'A' };
|
||||
|
||||
public IMAP() {
|
||||
setDefaultPort(143);
|
||||
this.__state = IMAPState.DISCONNECTED_STATE;
|
||||
this._reader = null;
|
||||
this.__writer = null;
|
||||
this._replyLines = new ArrayList<String>();
|
||||
createCommandSupport();
|
||||
}
|
||||
|
||||
private void __getReply() throws IOException {
|
||||
__getReply(true);
|
||||
}
|
||||
|
||||
private void __getReply(boolean wantTag) throws IOException {
|
||||
this._replyLines.clear();
|
||||
String line = this._reader.readLine();
|
||||
if (line == null)
|
||||
throw new EOFException("Connection closed without indication.");
|
||||
this._replyLines.add(line);
|
||||
if (wantTag) {
|
||||
while (IMAPReply.isUntagged(line)) {
|
||||
int literalCount = IMAPReply.literalCount(line);
|
||||
while (literalCount >= 0) {
|
||||
line = this._reader.readLine();
|
||||
if (line == null)
|
||||
throw new EOFException("Connection closed without indication.");
|
||||
this._replyLines.add(line);
|
||||
literalCount -= line.length() + 2;
|
||||
}
|
||||
line = this._reader.readLine();
|
||||
if (line == null)
|
||||
throw new EOFException("Connection closed without indication.");
|
||||
this._replyLines.add(line);
|
||||
}
|
||||
this._replyCode = IMAPReply.getReplyCode(line);
|
||||
} else {
|
||||
this._replyCode = IMAPReply.getUntaggedReplyCode(line);
|
||||
}
|
||||
fireReplyReceived(this._replyCode, getReplyString());
|
||||
}
|
||||
|
||||
protected void _connectAction_() throws IOException {
|
||||
super._connectAction_();
|
||||
this._reader = new CRLFLineReader(new InputStreamReader(this._input_, "ISO-8859-1"));
|
||||
this.__writer = new BufferedWriter(new OutputStreamWriter(this._output_, "ISO-8859-1"));
|
||||
int tmo = getSoTimeout();
|
||||
if (tmo <= 0)
|
||||
setSoTimeout(this.connectTimeout);
|
||||
__getReply(false);
|
||||
if (tmo <= 0)
|
||||
setSoTimeout(tmo);
|
||||
setState(IMAPState.NOT_AUTH_STATE);
|
||||
}
|
||||
|
||||
protected void setState(IMAPState state) {
|
||||
this.__state = state;
|
||||
}
|
||||
|
||||
public IMAPState getState() {
|
||||
return this.__state;
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
super.disconnect();
|
||||
this._reader = null;
|
||||
this.__writer = null;
|
||||
this._replyLines.clear();
|
||||
setState(IMAPState.DISCONNECTED_STATE);
|
||||
}
|
||||
|
||||
private int sendCommandWithID(String commandID, String command, String args) throws IOException {
|
||||
StringBuilder __commandBuffer = new StringBuilder();
|
||||
if (commandID != null) {
|
||||
__commandBuffer.append(commandID);
|
||||
__commandBuffer.append(' ');
|
||||
}
|
||||
__commandBuffer.append(command);
|
||||
if (args != null) {
|
||||
__commandBuffer.append(' ');
|
||||
__commandBuffer.append(args);
|
||||
}
|
||||
__commandBuffer.append("\r\n");
|
||||
String message = __commandBuffer.toString();
|
||||
this.__writer.write(message);
|
||||
this.__writer.flush();
|
||||
fireCommandSent(command, message);
|
||||
__getReply();
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
public int sendCommand(String command, String args) throws IOException {
|
||||
return sendCommandWithID(generateCommandID(), command, args);
|
||||
}
|
||||
|
||||
public int sendCommand(String command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public int sendCommand(IMAPCommand command, String args) throws IOException {
|
||||
return sendCommand(command.getIMAPCommand(), args);
|
||||
}
|
||||
|
||||
public boolean doCommand(IMAPCommand command, String args) throws IOException {
|
||||
return IMAPReply.isSuccess(sendCommand(command, args));
|
||||
}
|
||||
|
||||
public int sendCommand(IMAPCommand command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public boolean doCommand(IMAPCommand command) throws IOException {
|
||||
return IMAPReply.isSuccess(sendCommand(command));
|
||||
}
|
||||
|
||||
public int sendData(String command) throws IOException {
|
||||
return sendCommandWithID(null, command, null);
|
||||
}
|
||||
|
||||
public String[] getReplyStrings() {
|
||||
return this._replyLines.<String>toArray(new String[this._replyLines.size()]);
|
||||
}
|
||||
|
||||
public String getReplyString() {
|
||||
StringBuilder buffer = new StringBuilder(256);
|
||||
for (String s : this._replyLines) {
|
||||
buffer.append(s);
|
||||
buffer.append("\r\n");
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
protected String generateCommandID() {
|
||||
String res = new String(this._initialID);
|
||||
boolean carry = true;
|
||||
for (int i = this._initialID.length - 1; carry && i >= 0; i--) {
|
||||
if (this._initialID[i] == 'Z') {
|
||||
this._initialID[i] = 'A';
|
||||
} else {
|
||||
this._initialID[i] = (char)(this._initialID[i] + 1);
|
||||
carry = false;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
package org.apache.commons.net.imap;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IMAPClient extends IMAP {
|
||||
public boolean capability() throws IOException {
|
||||
return doCommand(IMAPCommand.CAPABILITY);
|
||||
}
|
||||
|
||||
public boolean noop() throws IOException {
|
||||
return doCommand(IMAPCommand.NOOP);
|
||||
}
|
||||
|
||||
public boolean logout() throws IOException {
|
||||
return doCommand(IMAPCommand.LOGOUT);
|
||||
}
|
||||
|
||||
public boolean login(String username, String password) throws IOException {
|
||||
if (getState() != IMAP.IMAPState.NOT_AUTH_STATE)
|
||||
return false;
|
||||
if (!doCommand(IMAPCommand.LOGIN, username + " " + password))
|
||||
return false;
|
||||
setState(IMAP.IMAPState.AUTH_STATE);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean select(String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.SELECT, mailboxName);
|
||||
}
|
||||
|
||||
public boolean examine(String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.EXAMINE, mailboxName);
|
||||
}
|
||||
|
||||
public boolean create(String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.CREATE, mailboxName);
|
||||
}
|
||||
|
||||
public boolean delete(String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.DELETE, mailboxName);
|
||||
}
|
||||
|
||||
public boolean rename(String oldMailboxName, String newMailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.RENAME, oldMailboxName + " " + newMailboxName);
|
||||
}
|
||||
|
||||
public boolean subscribe(String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.SUBSCRIBE, mailboxName);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.UNSUBSCRIBE, mailboxName);
|
||||
}
|
||||
|
||||
public boolean list(String refName, String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.LIST, refName + " " + mailboxName);
|
||||
}
|
||||
|
||||
public boolean lsub(String refName, String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.LSUB, refName + " " + mailboxName);
|
||||
}
|
||||
|
||||
public boolean status(String mailboxName, String[] itemNames) throws IOException {
|
||||
if (itemNames == null || itemNames.length < 1)
|
||||
throw new IllegalArgumentException("STATUS command requires at least one data item name");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(mailboxName);
|
||||
sb.append(" (");
|
||||
for (int i = 0; i < itemNames.length; i++) {
|
||||
if (i > 0)
|
||||
sb.append(" ");
|
||||
sb.append(itemNames[i]);
|
||||
}
|
||||
sb.append(")");
|
||||
return doCommand(IMAPCommand.STATUS, sb.toString());
|
||||
}
|
||||
|
||||
public boolean append(String mailboxName, String flags, String datetime) throws IOException {
|
||||
String args = mailboxName;
|
||||
if (flags != null)
|
||||
args = args + " " + flags;
|
||||
if (datetime != null)
|
||||
if (datetime.charAt(0) == '{') {
|
||||
args = args + " " + datetime;
|
||||
} else {
|
||||
args = args + " {" + datetime + "}";
|
||||
}
|
||||
return doCommand(IMAPCommand.APPEND, args);
|
||||
}
|
||||
|
||||
public boolean append(String mailboxName) throws IOException {
|
||||
return append(mailboxName, null, null);
|
||||
}
|
||||
|
||||
public boolean check() throws IOException {
|
||||
return doCommand(IMAPCommand.CHECK);
|
||||
}
|
||||
|
||||
public boolean close() throws IOException {
|
||||
return doCommand(IMAPCommand.CLOSE);
|
||||
}
|
||||
|
||||
public boolean expunge() throws IOException {
|
||||
return doCommand(IMAPCommand.EXPUNGE);
|
||||
}
|
||||
|
||||
public boolean search(String charset, String criteria) throws IOException {
|
||||
String args = "";
|
||||
if (charset != null)
|
||||
args = args + "CHARSET " + charset;
|
||||
args = args + criteria;
|
||||
return doCommand(IMAPCommand.SEARCH, args);
|
||||
}
|
||||
|
||||
public boolean search(String criteria) throws IOException {
|
||||
return search(null, criteria);
|
||||
}
|
||||
|
||||
public boolean fetch(String sequenceSet, String itemNames) throws IOException {
|
||||
return doCommand(IMAPCommand.FETCH, sequenceSet + " " + itemNames);
|
||||
}
|
||||
|
||||
public boolean store(String sequenceSet, String itemNames, String itemValues) throws IOException {
|
||||
return doCommand(IMAPCommand.STORE, sequenceSet + " " + itemNames + " " + itemValues);
|
||||
}
|
||||
|
||||
public boolean copy(String sequenceSet, String mailboxName) throws IOException {
|
||||
return doCommand(IMAPCommand.COPY, sequenceSet + " " + mailboxName);
|
||||
}
|
||||
|
||||
public boolean uid(String command, String commandArgs) throws IOException {
|
||||
return doCommand(IMAPCommand.UID, command + " " + commandArgs);
|
||||
}
|
||||
|
||||
public enum STATUS_DATA_ITEMS {
|
||||
MESSAGES, RECENT, UIDNEXT, UIDVALIDITY, UNSEEN;
|
||||
}
|
||||
|
||||
public enum SEARCH_CRITERIA {
|
||||
ALL, ANSWERED, BCC, BEFORE, BODY, CC, DELETED, DRAFT, FLAGGED, FROM, HEADER, KEYWORD, LARGER, NEW, NOT, OLD, ON, OR, RECENT, SEEN, SENTBEFORE, SENTON, SENTSINCE, SINCE, SMALLER, SUBJECT, TEXT, TO, UID, UNANSWERED, UNDELETED, UNDRAFT, UNFLAGGED, UNKEYWORD, UNSEEN;
|
||||
}
|
||||
|
||||
public enum FETCH_ITEM_NAMES {
|
||||
ALL, FAST, FULL, BODY, BODYSTRUCTURE, ENVELOPE, FLAGS, INTERNALDATE, RFC822, UID;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package org.apache.commons.net.imap;
|
||||
|
||||
public enum IMAPCommand {
|
||||
CAPABILITY(0),
|
||||
NOOP(0),
|
||||
LOGOUT(0),
|
||||
STARTTLS(0),
|
||||
AUTHENTICATE(1),
|
||||
LOGIN(2),
|
||||
XOAUTH(1),
|
||||
SELECT(1),
|
||||
EXAMINE(1),
|
||||
CREATE(1),
|
||||
DELETE(1),
|
||||
RENAME(2),
|
||||
SUBSCRIBE(1),
|
||||
UNSUBSCRIBE(1),
|
||||
LIST(2),
|
||||
LSUB(2),
|
||||
STATUS(2),
|
||||
APPEND(2, 4),
|
||||
CHECK(0),
|
||||
CLOSE(0),
|
||||
EXPUNGE(0),
|
||||
SEARCH(1, Integer.MAX_VALUE),
|
||||
FETCH(2),
|
||||
STORE(3),
|
||||
COPY(2),
|
||||
UID(2, Integer.MAX_VALUE);
|
||||
|
||||
private final String imapCommand;
|
||||
|
||||
private final int minParamCount;
|
||||
|
||||
private final int maxParamCount;
|
||||
|
||||
IMAPCommand(String name, int minCount, int maxCount) {
|
||||
this.imapCommand = name;
|
||||
this.minParamCount = minCount;
|
||||
this.maxParamCount = maxCount;
|
||||
}
|
||||
|
||||
public static final String getCommand(IMAPCommand command) {
|
||||
return command.getIMAPCommand();
|
||||
}
|
||||
|
||||
public String getIMAPCommand() {
|
||||
return (this.imapCommand != null) ? this.imapCommand : name();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package org.apache.commons.net.imap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.apache.commons.net.MalformedServerReplyException;
|
||||
|
||||
public final class IMAPReply {
|
||||
public static final int OK = 0;
|
||||
|
||||
public static final int NO = 1;
|
||||
|
||||
public static final int BAD = 2;
|
||||
|
||||
public static final int CONT = 3;
|
||||
|
||||
private static final String IMAP_OK = "OK";
|
||||
|
||||
private static final String IMAP_NO = "NO";
|
||||
|
||||
private static final String IMAP_BAD = "BAD";
|
||||
|
||||
private static final String IMAP_UNTAGGED_PREFIX = "* ";
|
||||
|
||||
private static final String IMAP_CONTINUATION_PREFIX = "+";
|
||||
|
||||
private static final String TAGGED_RESPONSE = "^\\w+ (\\S+).*";
|
||||
|
||||
public static boolean isUntagged(String line) {
|
||||
return line.startsWith("* ");
|
||||
}
|
||||
|
||||
public static boolean isContinuation(String line) {
|
||||
return line.startsWith("+");
|
||||
}
|
||||
|
||||
private static final Pattern TAGGED_PATTERN = Pattern.compile("^\\w+ (\\S+).*");
|
||||
|
||||
private static final String UNTAGGED_RESPONSE = "^\\* (\\S+).*";
|
||||
|
||||
public static int getReplyCode(String line) throws IOException {
|
||||
return getReplyCode(line, TAGGED_PATTERN);
|
||||
}
|
||||
|
||||
private static final Pattern UNTAGGED_PATTERN = Pattern.compile("^\\* (\\S+).*");
|
||||
|
||||
private static final Pattern LITERAL_PATTERN = Pattern.compile("\\{(\\d+)\\}$");
|
||||
|
||||
public static int literalCount(String line) {
|
||||
Matcher m = LITERAL_PATTERN.matcher(line);
|
||||
if (m.find())
|
||||
return Integer.parseInt(m.group(1));
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static int getUntaggedReplyCode(String line) throws IOException {
|
||||
return getReplyCode(line, UNTAGGED_PATTERN);
|
||||
}
|
||||
|
||||
private static int getReplyCode(String line, Pattern pattern) throws IOException {
|
||||
if (isContinuation(line))
|
||||
return 3;
|
||||
Matcher m = pattern.matcher(line);
|
||||
if (m.matches()) {
|
||||
String code = m.group(1);
|
||||
if (code.equals("OK"))
|
||||
return 0;
|
||||
if (code.equals("BAD"))
|
||||
return 2;
|
||||
if (code.equals("NO"))
|
||||
return 1;
|
||||
}
|
||||
throw new MalformedServerReplyException("Received unexpected IMAP protocol response from server: '" + line + "'.");
|
||||
}
|
||||
|
||||
public static boolean isSuccess(int replyCode) {
|
||||
return (replyCode == 0);
|
||||
}
|
||||
|
||||
public static boolean isContinuation(int replyCode) {
|
||||
return (replyCode == 3);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
package org.apache.commons.net.imap;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import org.apache.commons.net.io.CRLFLineReader;
|
||||
import org.apache.commons.net.util.SSLContextUtils;
|
||||
|
||||
public class IMAPSClient extends IMAPClient {
|
||||
public static final int DEFAULT_IMAPS_PORT = 993;
|
||||
|
||||
public static final String DEFAULT_PROTOCOL = "TLS";
|
||||
|
||||
private final boolean isImplicit;
|
||||
|
||||
private final String protocol;
|
||||
|
||||
private SSLContext context = null;
|
||||
|
||||
private String[] suites = null;
|
||||
|
||||
private String[] protocols = null;
|
||||
|
||||
private TrustManager trustManager = null;
|
||||
|
||||
private KeyManager keyManager = null;
|
||||
|
||||
public IMAPSClient() {
|
||||
this("TLS", false);
|
||||
}
|
||||
|
||||
public IMAPSClient(boolean implicit) {
|
||||
this("TLS", implicit);
|
||||
}
|
||||
|
||||
public IMAPSClient(String proto) {
|
||||
this(proto, false);
|
||||
}
|
||||
|
||||
public IMAPSClient(String proto, boolean implicit) {
|
||||
this(proto, implicit, null);
|
||||
}
|
||||
|
||||
public IMAPSClient(String proto, boolean implicit, SSLContext ctx) {
|
||||
setDefaultPort(993);
|
||||
this.protocol = proto;
|
||||
this.isImplicit = implicit;
|
||||
this.context = ctx;
|
||||
}
|
||||
|
||||
public IMAPSClient(boolean implicit, SSLContext ctx) {
|
||||
this("TLS", implicit, ctx);
|
||||
}
|
||||
|
||||
public IMAPSClient(SSLContext context) {
|
||||
this(false, context);
|
||||
}
|
||||
|
||||
protected void _connectAction_() throws IOException {
|
||||
if (this.isImplicit)
|
||||
performSSLNegotiation();
|
||||
super._connectAction_();
|
||||
}
|
||||
|
||||
private void initSSLContext() throws IOException {
|
||||
if (this.context == null)
|
||||
this.context = SSLContextUtils.createSSLContext(this.protocol, getKeyManager(), getTrustManager());
|
||||
}
|
||||
|
||||
private void performSSLNegotiation() throws IOException {
|
||||
initSSLContext();
|
||||
SSLSocketFactory ssf = this.context.getSocketFactory();
|
||||
String ip = getRemoteAddress().getHostAddress();
|
||||
int port = getRemotePort();
|
||||
SSLSocket socket = (SSLSocket)ssf.createSocket(this._socket_, ip, port, true);
|
||||
socket.setEnableSessionCreation(true);
|
||||
socket.setUseClientMode(true);
|
||||
if (this.protocols != null)
|
||||
socket.setEnabledProtocols(this.protocols);
|
||||
if (this.suites != null)
|
||||
socket.setEnabledCipherSuites(this.suites);
|
||||
socket.startHandshake();
|
||||
this._socket_ = socket;
|
||||
this._input_ = socket.getInputStream();
|
||||
this._output_ = socket.getOutputStream();
|
||||
this._reader = new CRLFLineReader(new InputStreamReader(this._input_, "ISO-8859-1"));
|
||||
this.__writer = new BufferedWriter(new OutputStreamWriter(this._output_, "ISO-8859-1"));
|
||||
}
|
||||
|
||||
private KeyManager getKeyManager() {
|
||||
return this.keyManager;
|
||||
}
|
||||
|
||||
public void setKeyManager(KeyManager newKeyManager) {
|
||||
this.keyManager = newKeyManager;
|
||||
}
|
||||
|
||||
public void setEnabledCipherSuites(String[] cipherSuites) {
|
||||
this.suites = new String[cipherSuites.length];
|
||||
System.arraycopy(cipherSuites, 0, this.suites, 0, cipherSuites.length);
|
||||
}
|
||||
|
||||
public String[] getEnabledCipherSuites() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getEnabledCipherSuites();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEnabledProtocols(String[] protocolVersions) {
|
||||
this.protocols = new String[protocolVersions.length];
|
||||
System.arraycopy(protocolVersions, 0, this.protocols, 0, protocolVersions.length);
|
||||
}
|
||||
|
||||
public String[] getEnabledProtocols() {
|
||||
if (this._socket_ instanceof SSLSocket)
|
||||
return ((SSLSocket)this._socket_).getEnabledProtocols();
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean execTLS() throws SSLException, IOException {
|
||||
if (sendCommand(IMAPCommand.getCommand(IMAPCommand.STARTTLS)) != 0)
|
||||
return false;
|
||||
performSSLNegotiation();
|
||||
return true;
|
||||
}
|
||||
|
||||
public TrustManager getTrustManager() {
|
||||
return this.trustManager;
|
||||
}
|
||||
|
||||
public void setTrustManager(TrustManager newTrustManager) {
|
||||
this.trustManager = newTrustManager;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
public final class CRLFLineReader extends BufferedReader {
|
||||
private static final char LF = '\n';
|
||||
|
||||
private static final char CR = '\r';
|
||||
|
||||
public CRLFLineReader(Reader reader) {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
public String readLine() throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean prevWasCR = false;
|
||||
synchronized (this.lock) {
|
||||
int intch;
|
||||
while ((intch = read()) != -1) {
|
||||
if (prevWasCR && intch == 10)
|
||||
return sb.substring(0, sb.length() - 1);
|
||||
if (intch == 13) {
|
||||
prevWasCR = true;
|
||||
} else {
|
||||
prevWasCR = false;
|
||||
}
|
||||
sb.append((char)intch);
|
||||
}
|
||||
}
|
||||
String string = sb.toString();
|
||||
if (string.length() == 0)
|
||||
return null;
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.util.EventListener;
|
||||
import org.apache.commons.net.util.ListenerList;
|
||||
|
||||
public class CopyStreamAdapter implements CopyStreamListener {
|
||||
private final ListenerList internalListeners = new ListenerList();
|
||||
|
||||
public void bytesTransferred(CopyStreamEvent event) {
|
||||
for (EventListener listener : (Iterable<EventListener>)this.internalListeners)
|
||||
((CopyStreamListener)listener).bytesTransferred(event);
|
||||
}
|
||||
|
||||
public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {
|
||||
for (EventListener listener : (Iterable<EventListener>)this.internalListeners)
|
||||
((CopyStreamListener)listener).bytesTransferred(totalBytesTransferred, bytesTransferred, streamSize);
|
||||
}
|
||||
|
||||
public void addCopyStreamListener(CopyStreamListener listener) {
|
||||
this.internalListeners.addListener(listener);
|
||||
}
|
||||
|
||||
public void removeCopyStreamListener(CopyStreamListener listener) {
|
||||
this.internalListeners.removeListener(listener);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.util.EventObject;
|
||||
|
||||
public class CopyStreamEvent extends EventObject {
|
||||
private static final long serialVersionUID = -964927635655051867L;
|
||||
|
||||
public static final long UNKNOWN_STREAM_SIZE = -1L;
|
||||
|
||||
private final int bytesTransferred;
|
||||
|
||||
private final long totalBytesTransferred;
|
||||
|
||||
private final long streamSize;
|
||||
|
||||
public CopyStreamEvent(Object source, long totalBytesTransferred, int bytesTransferred, long streamSize) {
|
||||
super(source);
|
||||
this.bytesTransferred = bytesTransferred;
|
||||
this.totalBytesTransferred = totalBytesTransferred;
|
||||
this.streamSize = streamSize;
|
||||
}
|
||||
|
||||
public int getBytesTransferred() {
|
||||
return this.bytesTransferred;
|
||||
}
|
||||
|
||||
public long getTotalBytesTransferred() {
|
||||
return this.totalBytesTransferred;
|
||||
}
|
||||
|
||||
public long getStreamSize() {
|
||||
return this.streamSize;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getClass().getName() + "[source=" + this.source + ", total=" + this.totalBytesTransferred + ", bytes=" + this.bytesTransferred + ", size=" + this.streamSize + "]";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class CopyStreamException extends IOException {
|
||||
private static final long serialVersionUID = -2602899129433221532L;
|
||||
|
||||
private final long totalBytesTransferred;
|
||||
|
||||
public CopyStreamException(String message, long bytesTransferred, IOException exception) {
|
||||
super(message);
|
||||
initCause(exception);
|
||||
this.totalBytesTransferred = bytesTransferred;
|
||||
}
|
||||
|
||||
public long getTotalBytesTransferred() {
|
||||
return this.totalBytesTransferred;
|
||||
}
|
||||
|
||||
public IOException getIOException() {
|
||||
return (IOException)getCause();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
public interface CopyStreamListener extends EventListener {
|
||||
void bytesTransferred(CopyStreamEvent paramCopyStreamEvent);
|
||||
|
||||
void bytesTransferred(long paramLong1, int paramInt, long paramLong2);
|
||||
}
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
public final class DotTerminatedMessageReader extends BufferedReader {
|
||||
private static final char LF = '\n';
|
||||
|
||||
private static final char CR = '\r';
|
||||
|
||||
private static final int DOT = 46;
|
||||
|
||||
public DotTerminatedMessageReader(Reader reader) {
|
||||
super(reader);
|
||||
}
|
||||
|
||||
private boolean atBeginning = true;
|
||||
|
||||
private boolean eof = false;
|
||||
|
||||
private boolean seenCR;
|
||||
|
||||
public int read() throws IOException {
|
||||
synchronized (this.lock) {
|
||||
if (this.eof)
|
||||
return -1;
|
||||
int chint = super.read();
|
||||
if (chint == -1) {
|
||||
this.eof = true;
|
||||
return -1;
|
||||
}
|
||||
if (this.atBeginning) {
|
||||
this.atBeginning = false;
|
||||
if (chint == 46) {
|
||||
mark(2);
|
||||
chint = super.read();
|
||||
if (chint == -1) {
|
||||
this.eof = true;
|
||||
return 46;
|
||||
}
|
||||
if (chint == 46)
|
||||
return chint;
|
||||
if (chint == 13) {
|
||||
chint = super.read();
|
||||
if (chint == -1) {
|
||||
reset();
|
||||
return 46;
|
||||
}
|
||||
if (chint == 10) {
|
||||
this.atBeginning = true;
|
||||
this.eof = true;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
reset();
|
||||
return 46;
|
||||
}
|
||||
}
|
||||
if (this.seenCR) {
|
||||
this.seenCR = false;
|
||||
if (chint == 10)
|
||||
this.atBeginning = true;
|
||||
}
|
||||
if (chint == 13)
|
||||
this.seenCR = true;
|
||||
return chint;
|
||||
}
|
||||
}
|
||||
|
||||
public int read(char[] buffer) throws IOException {
|
||||
return read(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
public int read(char[] buffer, int offset, int length) throws IOException {
|
||||
if (length < 1)
|
||||
return 0;
|
||||
synchronized (this.lock) {
|
||||
int ch;
|
||||
if ((ch = read()) == -1)
|
||||
return -1;
|
||||
int off = offset;
|
||||
do {
|
||||
buffer[offset++] = (char)ch;
|
||||
} while (--length > 0 && (ch = read()) != -1);
|
||||
return offset - off;
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
synchronized (this.lock) {
|
||||
if (!this.eof)
|
||||
while (read() != -1);
|
||||
this.eof = true;
|
||||
this.atBeginning = false;
|
||||
}
|
||||
}
|
||||
|
||||
public String readLine() throws IOException {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
synchronized (this.lock) {
|
||||
int intch;
|
||||
while ((intch = read()) != -1) {
|
||||
if (intch == 10 && this.atBeginning)
|
||||
return sb.substring(0, sb.length() - 1);
|
||||
sb.append((char)intch);
|
||||
}
|
||||
}
|
||||
String string = sb.toString();
|
||||
if (string.length() == 0)
|
||||
return null;
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
public final class DotTerminatedMessageWriter extends Writer {
|
||||
private static final int __NOTHING_SPECIAL_STATE = 0;
|
||||
|
||||
private static final int __LAST_WAS_CR_STATE = 1;
|
||||
|
||||
private static final int __LAST_WAS_NL_STATE = 2;
|
||||
|
||||
private int __state;
|
||||
|
||||
private Writer __output;
|
||||
|
||||
public DotTerminatedMessageWriter(Writer output) {
|
||||
super((Object)output);
|
||||
this.__output = output;
|
||||
this.__state = 0;
|
||||
}
|
||||
|
||||
public void write(int ch) throws IOException {
|
||||
synchronized (this.lock) {
|
||||
switch (ch) {
|
||||
case 13:
|
||||
this.__state = 1;
|
||||
this.__output.write(13);
|
||||
return;
|
||||
case 10:
|
||||
if (this.__state != 1)
|
||||
this.__output.write(13);
|
||||
this.__output.write(10);
|
||||
this.__state = 2;
|
||||
return;
|
||||
case 46:
|
||||
if (this.__state == 2)
|
||||
this.__output.write(46);
|
||||
break;
|
||||
}
|
||||
this.__state = 0;
|
||||
this.__output.write(ch);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void write(char[] buffer, int offset, int length) throws IOException {
|
||||
synchronized (this.lock) {
|
||||
while (length-- > 0)
|
||||
write(buffer[offset++]);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(char[] buffer) throws IOException {
|
||||
write(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
public void write(String string) throws IOException {
|
||||
write(string.toCharArray());
|
||||
}
|
||||
|
||||
public void write(String string, int offset, int length) throws IOException {
|
||||
write(string.toCharArray(), offset, length);
|
||||
}
|
||||
|
||||
public void flush() throws IOException {
|
||||
synchronized (this.lock) {
|
||||
this.__output.flush();
|
||||
}
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
synchronized (this.lock) {
|
||||
if (this.__output == null)
|
||||
return;
|
||||
if (this.__state == 1) {
|
||||
this.__output.write(10);
|
||||
} else if (this.__state != 2) {
|
||||
this.__output.write("\r\n");
|
||||
}
|
||||
this.__output.write(".\r\n");
|
||||
this.__output.flush();
|
||||
this.__output = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public final class FromNetASCIIInputStream extends PushbackInputStream {
|
||||
static final String _lineSeparator = System.getProperty("line.separator");
|
||||
|
||||
static final boolean _noConversionRequired = _lineSeparator.equals("\r\n");
|
||||
|
||||
static {
|
||||
try {
|
||||
_lineSeparatorBytes = _lineSeparator.getBytes("US-ASCII");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException("Broken JVM - cannot find US-ASCII charset!", e);
|
||||
}
|
||||
}
|
||||
|
||||
private int __length = 0;
|
||||
|
||||
static final byte[] _lineSeparatorBytes;
|
||||
|
||||
public static final boolean isConversionRequired() {
|
||||
return !_noConversionRequired;
|
||||
}
|
||||
|
||||
public FromNetASCIIInputStream(InputStream input) {
|
||||
super(input, _lineSeparatorBytes.length + 1);
|
||||
}
|
||||
|
||||
private int __read() throws IOException {
|
||||
int ch = super.read();
|
||||
if (ch == 13) {
|
||||
ch = super.read();
|
||||
if (ch == 10) {
|
||||
unread(_lineSeparatorBytes);
|
||||
ch = super.read();
|
||||
this.__length--;
|
||||
} else {
|
||||
if (ch != -1)
|
||||
unread(ch);
|
||||
return 13;
|
||||
}
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
if (_noConversionRequired)
|
||||
return super.read();
|
||||
return __read();
|
||||
}
|
||||
|
||||
public int read(byte[] buffer) throws IOException {
|
||||
return read(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
public int read(byte[] buffer, int offset, int length) throws IOException {
|
||||
if (_noConversionRequired)
|
||||
return super.read(buffer, offset, length);
|
||||
if (length < 1)
|
||||
return 0;
|
||||
int ch = available();
|
||||
this.__length = (length > ch) ? ch : length;
|
||||
if (this.__length < 1)
|
||||
this.__length = 1;
|
||||
if ((ch = __read()) == -1)
|
||||
return -1;
|
||||
int off = offset;
|
||||
do {
|
||||
buffer[offset++] = (byte)ch;
|
||||
} while (--this.__length > 0 && (ch = __read()) != -1);
|
||||
return offset - off;
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
if (this.in == null)
|
||||
throw new IOException("Stream closed");
|
||||
return this.buf.length - this.pos + this.in.available();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class FromNetASCIIOutputStream extends FilterOutputStream {
|
||||
private boolean __lastWasCR;
|
||||
|
||||
public FromNetASCIIOutputStream(OutputStream output) {
|
||||
super(output);
|
||||
this.__lastWasCR = false;
|
||||
}
|
||||
|
||||
private void __write(int ch) throws IOException {
|
||||
switch (ch) {
|
||||
case 13:
|
||||
this.__lastWasCR = true;
|
||||
break;
|
||||
case 10:
|
||||
if (this.__lastWasCR) {
|
||||
this.out.write(FromNetASCIIInputStream._lineSeparatorBytes);
|
||||
this.__lastWasCR = false;
|
||||
} else {
|
||||
this.__lastWasCR = false;
|
||||
this.out.write(10);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (this.__lastWasCR) {
|
||||
this.out.write(13);
|
||||
this.__lastWasCR = false;
|
||||
}
|
||||
this.out.write(ch);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void write(int ch) throws IOException {
|
||||
if (FromNetASCIIInputStream._noConversionRequired) {
|
||||
this.out.write(ch);
|
||||
return;
|
||||
}
|
||||
__write(ch);
|
||||
}
|
||||
|
||||
public synchronized void write(byte[] buffer) throws IOException {
|
||||
write(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
public synchronized void write(byte[] buffer, int offset, int length) throws IOException {
|
||||
if (FromNetASCIIInputStream._noConversionRequired) {
|
||||
this.out.write(buffer, offset, length);
|
||||
return;
|
||||
}
|
||||
while (length-- > 0)
|
||||
__write(buffer[offset++]);
|
||||
}
|
||||
|
||||
public synchronized void close() throws IOException {
|
||||
if (FromNetASCIIInputStream._noConversionRequired) {
|
||||
super.close();
|
||||
return;
|
||||
}
|
||||
if (this.__lastWasCR)
|
||||
this.out.write(13);
|
||||
super.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
public class SocketInputStream extends FilterInputStream {
|
||||
private final Socket __socket;
|
||||
|
||||
public SocketInputStream(Socket socket, InputStream stream) {
|
||||
super(stream);
|
||||
this.__socket = socket;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
this.__socket.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
public class SocketOutputStream extends FilterOutputStream {
|
||||
private final Socket __socket;
|
||||
|
||||
public SocketOutputStream(Socket socket, OutputStream stream) {
|
||||
super(stream);
|
||||
this.__socket = socket;
|
||||
}
|
||||
|
||||
public void write(byte[] buffer, int offset, int length) throws IOException {
|
||||
this.out.write(buffer, offset, length);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
this.__socket.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.FilterInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public final class ToNetASCIIInputStream extends FilterInputStream {
|
||||
private static final int __NOTHING_SPECIAL = 0;
|
||||
|
||||
private static final int __LAST_WAS_CR = 1;
|
||||
|
||||
private static final int __LAST_WAS_NL = 2;
|
||||
|
||||
private int __status;
|
||||
|
||||
public ToNetASCIIInputStream(InputStream input) {
|
||||
super(input);
|
||||
this.__status = 0;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
if (this.__status == 2) {
|
||||
this.__status = 0;
|
||||
return 10;
|
||||
}
|
||||
int ch = this.in.read();
|
||||
switch (ch) {
|
||||
case 13:
|
||||
this.__status = 1;
|
||||
return 13;
|
||||
case 10:
|
||||
if (this.__status != 1) {
|
||||
this.__status = 2;
|
||||
return 13;
|
||||
}
|
||||
break;
|
||||
}
|
||||
this.__status = 0;
|
||||
return ch;
|
||||
}
|
||||
|
||||
public int read(byte[] buffer) throws IOException {
|
||||
return read(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
public int read(byte[] buffer, int offset, int length) throws IOException {
|
||||
if (length < 1)
|
||||
return 0;
|
||||
int ch = available();
|
||||
if (length > ch)
|
||||
length = ch;
|
||||
if (length < 1)
|
||||
length = 1;
|
||||
if ((ch = read()) == -1)
|
||||
return -1;
|
||||
int off = offset;
|
||||
do {
|
||||
buffer[offset++] = (byte)ch;
|
||||
} while (--length > 0 && (ch = read()) != -1);
|
||||
return offset - off;
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
int result = this.in.available();
|
||||
if (this.__status == 2)
|
||||
return result + 1;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.FilterOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public final class ToNetASCIIOutputStream extends FilterOutputStream {
|
||||
private boolean __lastWasCR;
|
||||
|
||||
public ToNetASCIIOutputStream(OutputStream output) {
|
||||
super(output);
|
||||
this.__lastWasCR = false;
|
||||
}
|
||||
|
||||
public synchronized void write(int ch) throws IOException {
|
||||
switch (ch) {
|
||||
case 13:
|
||||
this.__lastWasCR = true;
|
||||
this.out.write(13);
|
||||
return;
|
||||
case 10:
|
||||
if (!this.__lastWasCR)
|
||||
this.out.write(13);
|
||||
break;
|
||||
}
|
||||
this.__lastWasCR = false;
|
||||
this.out.write(ch);
|
||||
}
|
||||
|
||||
public synchronized void write(byte[] buffer) throws IOException {
|
||||
write(buffer, 0, buffer.length);
|
||||
}
|
||||
|
||||
public synchronized void write(byte[] buffer, int offset, int length) throws IOException {
|
||||
while (length-- > 0)
|
||||
write(buffer[offset++]);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package org.apache.commons.net.io;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.net.Socket;
|
||||
|
||||
public final class Util {
|
||||
public static final int DEFAULT_COPY_BUFFER_SIZE = 1024;
|
||||
|
||||
public static final long copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener, boolean flush) throws CopyStreamException {
|
||||
long total = 0L;
|
||||
byte[] buffer = new byte[(bufferSize >= 0) ? bufferSize : 1024];
|
||||
try {
|
||||
int bytes;
|
||||
while ((bytes = source.read(buffer)) != -1) {
|
||||
if (bytes == 0) {
|
||||
bytes = source.read();
|
||||
if (bytes < 0)
|
||||
break;
|
||||
dest.write(bytes);
|
||||
if (flush)
|
||||
dest.flush();
|
||||
total++;
|
||||
if (listener != null)
|
||||
listener.bytesTransferred(total, 1, streamSize);
|
||||
continue;
|
||||
}
|
||||
dest.write(buffer, 0, bytes);
|
||||
if (flush)
|
||||
dest.flush();
|
||||
total += (long)bytes;
|
||||
if (listener != null)
|
||||
listener.bytesTransferred(total, bytes, streamSize);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CopyStreamException("IOException caught while copying.", total, e);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public static final long copyStream(InputStream source, OutputStream dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException {
|
||||
return copyStream(source, dest, bufferSize, streamSize, listener, true);
|
||||
}
|
||||
|
||||
public static final long copyStream(InputStream source, OutputStream dest, int bufferSize) throws CopyStreamException {
|
||||
return copyStream(source, dest, bufferSize, -1L, null);
|
||||
}
|
||||
|
||||
public static final long copyStream(InputStream source, OutputStream dest) throws CopyStreamException {
|
||||
return copyStream(source, dest, 1024);
|
||||
}
|
||||
|
||||
public static final long copyReader(Reader source, Writer dest, int bufferSize, long streamSize, CopyStreamListener listener) throws CopyStreamException {
|
||||
long total = 0L;
|
||||
char[] buffer = new char[(bufferSize >= 0) ? bufferSize : 1024];
|
||||
try {
|
||||
int chars;
|
||||
while ((chars = source.read(buffer)) != -1) {
|
||||
if (chars == 0) {
|
||||
chars = source.read();
|
||||
if (chars < 0)
|
||||
break;
|
||||
dest.write(chars);
|
||||
dest.flush();
|
||||
total++;
|
||||
if (listener != null)
|
||||
listener.bytesTransferred(total, chars, streamSize);
|
||||
continue;
|
||||
}
|
||||
dest.write(buffer, 0, chars);
|
||||
dest.flush();
|
||||
total += (long)chars;
|
||||
if (listener != null)
|
||||
listener.bytesTransferred(total, chars, streamSize);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new CopyStreamException("IOException caught while copying.", total, e);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public static final long copyReader(Reader source, Writer dest, int bufferSize) throws CopyStreamException {
|
||||
return copyReader(source, dest, bufferSize, -1L, null);
|
||||
}
|
||||
|
||||
public static final long copyReader(Reader source, Writer dest) throws CopyStreamException {
|
||||
return copyReader(source, dest, 1024);
|
||||
}
|
||||
|
||||
public static void closeQuietly(Closeable closeable) {
|
||||
if (closeable != null)
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
public static void closeQuietly(Socket socket) {
|
||||
if (socket != null)
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Article implements Threadable {
|
||||
private long articleNumber;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String date;
|
||||
|
||||
private String articleId;
|
||||
|
||||
private String simplifiedSubject;
|
||||
|
||||
private String from;
|
||||
|
||||
private ArrayList<String> references;
|
||||
|
||||
private boolean isReply = false;
|
||||
|
||||
public Article kid;
|
||||
|
||||
public Article next;
|
||||
|
||||
public Article() {
|
||||
this.articleNumber = -1L;
|
||||
}
|
||||
|
||||
public void addReference(String msgId) {
|
||||
if (msgId == null || msgId.length() == 0)
|
||||
return;
|
||||
if (this.references == null)
|
||||
this.references = new ArrayList<String>();
|
||||
this.isReply = true;
|
||||
for (String s : msgId.split(" "))
|
||||
this.references.add(s);
|
||||
}
|
||||
|
||||
public String[] getReferences() {
|
||||
if (this.references == null)
|
||||
return new String[0];
|
||||
return this.references.<String>toArray(new String[this.references.size()]);
|
||||
}
|
||||
|
||||
private void simplifySubject() {
|
||||
int start = 0;
|
||||
String subject = getSubject();
|
||||
int len = subject.length();
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
done = true;
|
||||
while (start < len && subject.charAt(start) == ' ')
|
||||
start++;
|
||||
if (start < len - 2 && (subject.charAt(start) == 'r' || subject.charAt(start) == 'R') && (subject.charAt(start + 1) == 'e' || subject.charAt(start + 1) == 'E'))
|
||||
if (subject.charAt(start + 2) == ':') {
|
||||
start += 3;
|
||||
done = false;
|
||||
} else if (start < len - 2 && (subject.charAt(start + 2) == '[' || subject.charAt(start + 2) == '(')) {
|
||||
int i = start + 3;
|
||||
while (i < len && subject.charAt(i) >= '0' && subject.charAt(i) <= '9')
|
||||
i++;
|
||||
if (i < len - 1 && (subject.charAt(i) == ']' || subject.charAt(i) == ')') && subject.charAt(i + 1) == ':') {
|
||||
start = i + 2;
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
if ("(no subject)".equals(this.simplifiedSubject))
|
||||
this.simplifiedSubject = "";
|
||||
int end = len;
|
||||
while (end > start && subject.charAt(end - 1) < ' ')
|
||||
end--;
|
||||
if (start == 0 && end == len) {
|
||||
this.simplifiedSubject = subject;
|
||||
continue;
|
||||
}
|
||||
this.simplifiedSubject = subject.substring(start, end);
|
||||
}
|
||||
}
|
||||
|
||||
public static void printThread(Article article, int depth) {
|
||||
for (int i = 0; i < depth; i++)
|
||||
System.out.print("==>");
|
||||
System.out.println(article.getSubject() + "\t" + article.getFrom() + "\t" + article.getArticleId());
|
||||
if (article.kid != null)
|
||||
printThread(article.kid, depth + 1);
|
||||
if (article.next != null)
|
||||
printThread(article.next, depth);
|
||||
}
|
||||
|
||||
public String getArticleId() {
|
||||
return this.articleId;
|
||||
}
|
||||
|
||||
public long getArticleNumberLong() {
|
||||
return this.articleNumber;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public String getFrom() {
|
||||
return this.from;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return this.subject;
|
||||
}
|
||||
|
||||
public void setArticleId(String string) {
|
||||
this.articleId = string;
|
||||
}
|
||||
|
||||
public void setArticleNumber(long l) {
|
||||
this.articleNumber = l;
|
||||
}
|
||||
|
||||
public void setDate(String string) {
|
||||
this.date = string;
|
||||
}
|
||||
|
||||
public void setFrom(String string) {
|
||||
this.from = string;
|
||||
}
|
||||
|
||||
public void setSubject(String string) {
|
||||
this.subject = string;
|
||||
}
|
||||
|
||||
public boolean isDummy() {
|
||||
return (this.articleNumber == -1L);
|
||||
}
|
||||
|
||||
public String messageThreadId() {
|
||||
return this.articleId;
|
||||
}
|
||||
|
||||
public String[] messageThreadReferences() {
|
||||
return getReferences();
|
||||
}
|
||||
|
||||
public String simplifiedSubject() {
|
||||
if (this.simplifiedSubject == null)
|
||||
simplifySubject();
|
||||
return this.simplifiedSubject;
|
||||
}
|
||||
|
||||
public boolean subjectIsReply() {
|
||||
return this.isReply;
|
||||
}
|
||||
|
||||
public void setChild(Threadable child) {
|
||||
this.kid = (Article)child;
|
||||
flushSubjectCache();
|
||||
}
|
||||
|
||||
private void flushSubjectCache() {
|
||||
this.simplifiedSubject = null;
|
||||
}
|
||||
|
||||
public void setNext(Threadable next) {
|
||||
this.next = (Article)next;
|
||||
flushSubjectCache();
|
||||
}
|
||||
|
||||
public Threadable makeDummy() {
|
||||
return new Article();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.articleNumber + " " + this.articleId + " " + this.subject;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getArticleNumber() {
|
||||
return (int)this.articleNumber;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setArticleNumber(int a) {
|
||||
this.articleNumber = (long)a;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void addHeaderField(String name, String val) {}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
public class ArticleInfo {
|
||||
public String articleId;
|
||||
|
||||
public long articleNumber;
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
class ArticleIterator implements Iterator<Article>, Iterable<Article> {
|
||||
private final Iterator<String> stringIterator;
|
||||
|
||||
public ArticleIterator(Iterable<String> iterableString) {
|
||||
this.stringIterator = iterableString.iterator();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return this.stringIterator.hasNext();
|
||||
}
|
||||
|
||||
public Article next() {
|
||||
String line = this.stringIterator.next();
|
||||
return NNTPClient.__parseArticleEntry(line);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
this.stringIterator.remove();
|
||||
}
|
||||
|
||||
public Iterator<Article> iterator() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
@Deprecated
|
||||
public final class ArticlePointer {
|
||||
public int articleNumber;
|
||||
|
||||
public String articleId;
|
||||
}
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import org.apache.commons.net.MalformedServerReplyException;
|
||||
import org.apache.commons.net.ProtocolCommandSupport;
|
||||
import org.apache.commons.net.SocketClient;
|
||||
import org.apache.commons.net.io.CRLFLineReader;
|
||||
|
||||
public class NNTP extends SocketClient {
|
||||
public static final int DEFAULT_PORT = 119;
|
||||
|
||||
private static final String __DEFAULT_ENCODING = "ISO-8859-1";
|
||||
|
||||
boolean _isAllowedToPost;
|
||||
|
||||
int _replyCode;
|
||||
|
||||
String _replyString;
|
||||
|
||||
protected BufferedReader _reader_;
|
||||
|
||||
protected BufferedWriter _writer_;
|
||||
|
||||
protected ProtocolCommandSupport _commandSupport_;
|
||||
|
||||
public NNTP() {
|
||||
setDefaultPort(119);
|
||||
this._replyString = null;
|
||||
this._reader_ = null;
|
||||
this._writer_ = null;
|
||||
this._isAllowedToPost = false;
|
||||
this._commandSupport_ = new ProtocolCommandSupport(this);
|
||||
}
|
||||
|
||||
private void __getReply() throws IOException {
|
||||
this._replyString = this._reader_.readLine();
|
||||
if (this._replyString == null)
|
||||
throw new NNTPConnectionClosedException("Connection closed without indication.");
|
||||
if (this._replyString.length() < 3)
|
||||
throw new MalformedServerReplyException("Truncated server reply: " + this._replyString);
|
||||
try {
|
||||
this._replyCode = Integer.parseInt(this._replyString.substring(0, 3));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new MalformedServerReplyException("Could not parse response code.\nServer Reply: " + this._replyString);
|
||||
}
|
||||
fireReplyReceived(this._replyCode, this._replyString + "\r\n");
|
||||
if (this._replyCode == 400)
|
||||
throw new NNTPConnectionClosedException("NNTP response 400 received. Server closed connection.");
|
||||
}
|
||||
|
||||
protected void _connectAction_() throws IOException {
|
||||
super._connectAction_();
|
||||
this._reader_ = new CRLFLineReader(new InputStreamReader(this._input_, "ISO-8859-1"));
|
||||
this._writer_ = new BufferedWriter(new OutputStreamWriter(this._output_, "ISO-8859-1"));
|
||||
__getReply();
|
||||
this._isAllowedToPost = (this._replyCode == 200);
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
super.disconnect();
|
||||
this._reader_ = null;
|
||||
this._writer_ = null;
|
||||
this._replyString = null;
|
||||
this._isAllowedToPost = false;
|
||||
}
|
||||
|
||||
public boolean isAllowedToPost() {
|
||||
return this._isAllowedToPost;
|
||||
}
|
||||
|
||||
public int sendCommand(String command, String args) throws IOException {
|
||||
StringBuilder __commandBuffer = new StringBuilder();
|
||||
__commandBuffer.append(command);
|
||||
if (args != null) {
|
||||
__commandBuffer.append(' ');
|
||||
__commandBuffer.append(args);
|
||||
}
|
||||
__commandBuffer.append("\r\n");
|
||||
String message;
|
||||
this._writer_.write(message = __commandBuffer.toString());
|
||||
this._writer_.flush();
|
||||
fireCommandSent(command, message);
|
||||
__getReply();
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
public int sendCommand(int command, String args) throws IOException {
|
||||
return sendCommand(NNTPCommand.getCommand(command), args);
|
||||
}
|
||||
|
||||
public int sendCommand(String command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public int sendCommand(int command) throws IOException {
|
||||
return sendCommand(command, null);
|
||||
}
|
||||
|
||||
public int getReplyCode() {
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
public int getReply() throws IOException {
|
||||
__getReply();
|
||||
return this._replyCode;
|
||||
}
|
||||
|
||||
public String getReplyString() {
|
||||
return this._replyString;
|
||||
}
|
||||
|
||||
public int article(String messageId) throws IOException {
|
||||
return sendCommand(0, messageId);
|
||||
}
|
||||
|
||||
public int article(long articleNumber) throws IOException {
|
||||
return sendCommand(0, Long.toString(articleNumber));
|
||||
}
|
||||
|
||||
public int article() throws IOException {
|
||||
return sendCommand(0);
|
||||
}
|
||||
|
||||
public int body(String messageId) throws IOException {
|
||||
return sendCommand(1, messageId);
|
||||
}
|
||||
|
||||
public int body(long articleNumber) throws IOException {
|
||||
return sendCommand(1, Long.toString(articleNumber));
|
||||
}
|
||||
|
||||
public int body() throws IOException {
|
||||
return sendCommand(1);
|
||||
}
|
||||
|
||||
public int head(String messageId) throws IOException {
|
||||
return sendCommand(3, messageId);
|
||||
}
|
||||
|
||||
public int head(long articleNumber) throws IOException {
|
||||
return sendCommand(3, Long.toString(articleNumber));
|
||||
}
|
||||
|
||||
public int head() throws IOException {
|
||||
return sendCommand(3);
|
||||
}
|
||||
|
||||
public int stat(String messageId) throws IOException {
|
||||
return sendCommand(14, messageId);
|
||||
}
|
||||
|
||||
public int stat(long articleNumber) throws IOException {
|
||||
return sendCommand(14, Long.toString(articleNumber));
|
||||
}
|
||||
|
||||
public int stat() throws IOException {
|
||||
return sendCommand(14);
|
||||
}
|
||||
|
||||
public int group(String newsgroup) throws IOException {
|
||||
return sendCommand(2, newsgroup);
|
||||
}
|
||||
|
||||
public int help() throws IOException {
|
||||
return sendCommand(4);
|
||||
}
|
||||
|
||||
public int ihave(String messageId) throws IOException {
|
||||
return sendCommand(5, messageId);
|
||||
}
|
||||
|
||||
public int last() throws IOException {
|
||||
return sendCommand(6);
|
||||
}
|
||||
|
||||
public int list() throws IOException {
|
||||
return sendCommand(7);
|
||||
}
|
||||
|
||||
public int next() throws IOException {
|
||||
return sendCommand(10);
|
||||
}
|
||||
|
||||
public int newgroups(String date, String time, boolean GMT, String distributions) throws IOException {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(date);
|
||||
buffer.append(' ');
|
||||
buffer.append(time);
|
||||
if (GMT) {
|
||||
buffer.append(' ');
|
||||
buffer.append("GMT");
|
||||
}
|
||||
if (distributions != null) {
|
||||
buffer.append(" <");
|
||||
buffer.append(distributions);
|
||||
buffer.append('>');
|
||||
}
|
||||
return sendCommand(8, buffer.toString());
|
||||
}
|
||||
|
||||
public int newnews(String newsgroups, String date, String time, boolean GMT, String distributions) throws IOException {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append(newsgroups);
|
||||
buffer.append(' ');
|
||||
buffer.append(date);
|
||||
buffer.append(' ');
|
||||
buffer.append(time);
|
||||
if (GMT) {
|
||||
buffer.append(' ');
|
||||
buffer.append("GMT");
|
||||
}
|
||||
if (distributions != null) {
|
||||
buffer.append(" <");
|
||||
buffer.append(distributions);
|
||||
buffer.append('>');
|
||||
}
|
||||
return sendCommand(9, buffer.toString());
|
||||
}
|
||||
|
||||
public int post() throws IOException {
|
||||
return sendCommand(11);
|
||||
}
|
||||
|
||||
public int quit() throws IOException {
|
||||
return sendCommand(12);
|
||||
}
|
||||
|
||||
public int authinfoUser(String username) throws IOException {
|
||||
String userParameter = "USER " + username;
|
||||
return sendCommand(15, userParameter);
|
||||
}
|
||||
|
||||
public int authinfoPass(String password) throws IOException {
|
||||
String passParameter = "PASS " + password;
|
||||
return sendCommand(15, passParameter);
|
||||
}
|
||||
|
||||
public int xover(String selectedArticles) throws IOException {
|
||||
return sendCommand(16, selectedArticles);
|
||||
}
|
||||
|
||||
public int xhdr(String header, String selectedArticles) throws IOException {
|
||||
StringBuilder command = new StringBuilder(header);
|
||||
command.append(" ");
|
||||
command.append(selectedArticles);
|
||||
return sendCommand(17, command.toString());
|
||||
}
|
||||
|
||||
public int listActive(String wildmat) throws IOException {
|
||||
StringBuilder command = new StringBuilder("ACTIVE ");
|
||||
command.append(wildmat);
|
||||
return sendCommand(7, command.toString());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int article(int a) throws IOException {
|
||||
return article((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int body(int a) throws IOException {
|
||||
return body((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int head(int a) throws IOException {
|
||||
return head((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int stat(int a) throws IOException {
|
||||
return stat((long)a);
|
||||
}
|
||||
|
||||
protected ProtocolCommandSupport getCommandSupport() {
|
||||
return this._commandSupport_;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,580 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
import org.apache.commons.net.MalformedServerReplyException;
|
||||
import org.apache.commons.net.io.DotTerminatedMessageReader;
|
||||
import org.apache.commons.net.io.DotTerminatedMessageWriter;
|
||||
import org.apache.commons.net.io.Util;
|
||||
|
||||
public class NNTPClient extends NNTP {
|
||||
private void __parseArticlePointer(String reply, ArticleInfo pointer) throws MalformedServerReplyException {
|
||||
String[] tokens = reply.split(" ");
|
||||
if (tokens.length >= 3) {
|
||||
int i = 1;
|
||||
try {
|
||||
pointer.articleNumber = Long.parseLong(tokens[i++]);
|
||||
pointer.articleId = tokens[i++];
|
||||
return;
|
||||
} catch (NumberFormatException e) {}
|
||||
}
|
||||
throw new MalformedServerReplyException("Could not parse article pointer.\nServer reply: " + reply);
|
||||
}
|
||||
|
||||
private static void __parseGroupReply(String reply, NewsgroupInfo info) throws MalformedServerReplyException {
|
||||
String[] tokens = reply.split(" ");
|
||||
if (tokens.length >= 5) {
|
||||
int i = 1;
|
||||
try {
|
||||
info._setArticleCount(Long.parseLong(tokens[i++]));
|
||||
info._setFirstArticle(Long.parseLong(tokens[i++]));
|
||||
info._setLastArticle(Long.parseLong(tokens[i++]));
|
||||
info._setNewsgroup(tokens[i++]);
|
||||
info._setPostingPermission(0);
|
||||
return;
|
||||
} catch (NumberFormatException e) {}
|
||||
}
|
||||
throw new MalformedServerReplyException("Could not parse newsgroup info.\nServer reply: " + reply);
|
||||
}
|
||||
|
||||
static NewsgroupInfo __parseNewsgroupListEntry(String entry) {
|
||||
String[] tokens = entry.split(" ");
|
||||
if (tokens.length < 4)
|
||||
return null;
|
||||
NewsgroupInfo result = new NewsgroupInfo();
|
||||
int i = 0;
|
||||
result._setNewsgroup(tokens[i++]);
|
||||
try {
|
||||
long lastNum = Long.parseLong(tokens[i++]);
|
||||
long firstNum = Long.parseLong(tokens[i++]);
|
||||
result._setFirstArticle(firstNum);
|
||||
result._setLastArticle(lastNum);
|
||||
if (firstNum == 0L && lastNum == 0L) {
|
||||
result._setArticleCount(0L);
|
||||
} else {
|
||||
result._setArticleCount(lastNum - firstNum + 1L);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
switch (tokens[i++].charAt(0)) {
|
||||
case 'Y':
|
||||
case 'y':
|
||||
result._setPostingPermission(2);
|
||||
break;
|
||||
case 'N':
|
||||
case 'n':
|
||||
result._setPostingPermission(3);
|
||||
break;
|
||||
case 'M':
|
||||
case 'm':
|
||||
result._setPostingPermission(1);
|
||||
break;
|
||||
default:
|
||||
result._setPostingPermission(0);
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static Article __parseArticleEntry(String line) {
|
||||
Article article = new Article();
|
||||
article.setSubject(line);
|
||||
String[] parts = line.split("\t");
|
||||
if (parts.length > 6) {
|
||||
int i = 0;
|
||||
try {
|
||||
article.setArticleNumber(Long.parseLong(parts[i++]));
|
||||
article.setSubject(parts[i++]);
|
||||
article.setFrom(parts[i++]);
|
||||
article.setDate(parts[i++]);
|
||||
article.setArticleId(parts[i++]);
|
||||
article.addReference(parts[i++]);
|
||||
} catch (NumberFormatException e) {}
|
||||
}
|
||||
return article;
|
||||
}
|
||||
|
||||
private NewsgroupInfo[] __readNewsgroupListing() throws IOException {
|
||||
BufferedReader reader = new DotTerminatedMessageReader(this._reader_);
|
||||
Vector<NewsgroupInfo> list = new Vector<NewsgroupInfo>(2048);
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
NewsgroupInfo tmp = __parseNewsgroupListEntry(line);
|
||||
if (tmp != null) {
|
||||
list.addElement(tmp);
|
||||
continue;
|
||||
}
|
||||
throw new MalformedServerReplyException(line);
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
int size;
|
||||
if ((size = list.size()) < 1)
|
||||
return new NewsgroupInfo[0];
|
||||
NewsgroupInfo[] info = new NewsgroupInfo[size];
|
||||
list.copyInto(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
private BufferedReader __retrieve(int command, String articleId, ArticleInfo pointer) throws IOException {
|
||||
if (articleId != null) {
|
||||
if (!NNTPReply.isPositiveCompletion(sendCommand(command, articleId)))
|
||||
return null;
|
||||
} else if (!NNTPReply.isPositiveCompletion(sendCommand(command))) {
|
||||
return null;
|
||||
}
|
||||
if (pointer != null)
|
||||
__parseArticlePointer(getReplyString(), pointer);
|
||||
return new DotTerminatedMessageReader(this._reader_);
|
||||
}
|
||||
|
||||
private BufferedReader __retrieve(int command, long articleNumber, ArticleInfo pointer) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(sendCommand(command, Long.toString(articleNumber))))
|
||||
return null;
|
||||
if (pointer != null)
|
||||
__parseArticlePointer(getReplyString(), pointer);
|
||||
return new DotTerminatedMessageReader(this._reader_);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticle(String articleId, ArticleInfo pointer) throws IOException {
|
||||
return __retrieve(0, articleId, pointer);
|
||||
}
|
||||
|
||||
public Reader retrieveArticle(String articleId) throws IOException {
|
||||
return retrieveArticle(articleId, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public Reader retrieveArticle() throws IOException {
|
||||
return retrieveArticle((String)null);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticle(long articleNumber, ArticleInfo pointer) throws IOException {
|
||||
return __retrieve(0, articleNumber, pointer);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticle(long articleNumber) throws IOException {
|
||||
return retrieveArticle(articleNumber, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleHeader(String articleId, ArticleInfo pointer) throws IOException {
|
||||
return __retrieve(3, articleId, pointer);
|
||||
}
|
||||
|
||||
public Reader retrieveArticleHeader(String articleId) throws IOException {
|
||||
return retrieveArticleHeader(articleId, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public Reader retrieveArticleHeader() throws IOException {
|
||||
return retrieveArticleHeader((String)null);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleHeader(long articleNumber, ArticleInfo pointer) throws IOException {
|
||||
return __retrieve(3, articleNumber, pointer);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleHeader(long articleNumber) throws IOException {
|
||||
return retrieveArticleHeader(articleNumber, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleBody(String articleId, ArticleInfo pointer) throws IOException {
|
||||
return __retrieve(1, articleId, pointer);
|
||||
}
|
||||
|
||||
public Reader retrieveArticleBody(String articleId) throws IOException {
|
||||
return retrieveArticleBody(articleId, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public Reader retrieveArticleBody() throws IOException {
|
||||
return retrieveArticleBody(null);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleBody(long articleNumber, ArticleInfo pointer) throws IOException {
|
||||
return __retrieve(1, articleNumber, pointer);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleBody(long articleNumber) throws IOException {
|
||||
return retrieveArticleBody(articleNumber, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public boolean selectNewsgroup(String newsgroup, NewsgroupInfo info) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(group(newsgroup)))
|
||||
return false;
|
||||
if (info != null)
|
||||
__parseGroupReply(getReplyString(), info);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectNewsgroup(String newsgroup) throws IOException {
|
||||
return selectNewsgroup(newsgroup, null);
|
||||
}
|
||||
|
||||
public String listHelp() throws IOException {
|
||||
if (!NNTPReply.isInformational(help()))
|
||||
return null;
|
||||
StringWriter help = new StringWriter();
|
||||
BufferedReader reader = new DotTerminatedMessageReader(this._reader_);
|
||||
Util.copyReader(reader, help);
|
||||
reader.close();
|
||||
help.close();
|
||||
return help.toString();
|
||||
}
|
||||
|
||||
public String[] listOverviewFmt() throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(sendCommand("LIST", "OVERVIEW.FMT")))
|
||||
return null;
|
||||
BufferedReader reader = new DotTerminatedMessageReader(this._reader_);
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
list.add(line);
|
||||
reader.close();
|
||||
return list.<String>toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
public boolean selectArticle(String articleId, ArticleInfo pointer) throws IOException {
|
||||
if (articleId != null) {
|
||||
if (!NNTPReply.isPositiveCompletion(stat(articleId)))
|
||||
return false;
|
||||
} else if (!NNTPReply.isPositiveCompletion(stat())) {
|
||||
return false;
|
||||
}
|
||||
if (pointer != null)
|
||||
__parseArticlePointer(getReplyString(), pointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectArticle(String articleId) throws IOException {
|
||||
return selectArticle(articleId, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public boolean selectArticle(ArticleInfo pointer) throws IOException {
|
||||
return selectArticle(null, pointer);
|
||||
}
|
||||
|
||||
public boolean selectArticle(long articleNumber, ArticleInfo pointer) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(stat(articleNumber)))
|
||||
return false;
|
||||
if (pointer != null)
|
||||
__parseArticlePointer(getReplyString(), pointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectArticle(long articleNumber) throws IOException {
|
||||
return selectArticle(articleNumber, (ArticleInfo)null);
|
||||
}
|
||||
|
||||
public boolean selectPreviousArticle(ArticleInfo pointer) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(last()))
|
||||
return false;
|
||||
if (pointer != null)
|
||||
__parseArticlePointer(getReplyString(), pointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectPreviousArticle() throws IOException {
|
||||
return selectPreviousArticle((ArticleInfo)null);
|
||||
}
|
||||
|
||||
public boolean selectNextArticle(ArticleInfo pointer) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(next()))
|
||||
return false;
|
||||
if (pointer != null)
|
||||
__parseArticlePointer(getReplyString(), pointer);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean selectNextArticle() throws IOException {
|
||||
return selectNextArticle((ArticleInfo)null);
|
||||
}
|
||||
|
||||
public NewsgroupInfo[] listNewsgroups() throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(list()))
|
||||
return null;
|
||||
return __readNewsgroupListing();
|
||||
}
|
||||
|
||||
public Iterable<String> iterateNewsgroupListing() throws IOException {
|
||||
if (NNTPReply.isPositiveCompletion(list()))
|
||||
return new ReplyIterator(this._reader_);
|
||||
throw new IOException("LIST command failed: " + getReplyString());
|
||||
}
|
||||
|
||||
public Iterable<NewsgroupInfo> iterateNewsgroups() throws IOException {
|
||||
return new NewsgroupIterator(iterateNewsgroupListing());
|
||||
}
|
||||
|
||||
public NewsgroupInfo[] listNewsgroups(String wildmat) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(listActive(wildmat)))
|
||||
return null;
|
||||
return __readNewsgroupListing();
|
||||
}
|
||||
|
||||
public Iterable<String> iterateNewsgroupListing(String wildmat) throws IOException {
|
||||
if (NNTPReply.isPositiveCompletion(listActive(wildmat)))
|
||||
return new ReplyIterator(this._reader_);
|
||||
throw new IOException("LIST ACTIVE " + wildmat + " command failed: " + getReplyString());
|
||||
}
|
||||
|
||||
public Iterable<NewsgroupInfo> iterateNewsgroups(String wildmat) throws IOException {
|
||||
return new NewsgroupIterator(iterateNewsgroupListing(wildmat));
|
||||
}
|
||||
|
||||
public NewsgroupInfo[] listNewNewsgroups(NewGroupsOrNewsQuery query) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(newgroups(query.getDate(), query.getTime(), query.isGMT(), query.getDistributions())))
|
||||
return null;
|
||||
return __readNewsgroupListing();
|
||||
}
|
||||
|
||||
public Iterable<String> iterateNewNewsgroupListing(NewGroupsOrNewsQuery query) throws IOException {
|
||||
if (NNTPReply.isPositiveCompletion(newgroups(query.getDate(), query.getTime(), query.isGMT(), query.getDistributions())))
|
||||
return new ReplyIterator(this._reader_);
|
||||
throw new IOException("NEWGROUPS command failed: " + getReplyString());
|
||||
}
|
||||
|
||||
public Iterable<NewsgroupInfo> iterateNewNewsgroups(NewGroupsOrNewsQuery query) throws IOException {
|
||||
return new NewsgroupIterator(iterateNewNewsgroupListing(query));
|
||||
}
|
||||
|
||||
public String[] listNewNews(NewGroupsOrNewsQuery query) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(), query.isGMT(), query.getDistributions())))
|
||||
return null;
|
||||
Vector<String> list = new Vector<String>();
|
||||
BufferedReader reader = new DotTerminatedMessageReader(this._reader_);
|
||||
try {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
list.addElement(line);
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
int size = list.size();
|
||||
if (size < 1)
|
||||
return new String[0];
|
||||
String[] result = new String[size];
|
||||
list.copyInto(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Iterable<String> iterateNewNews(NewGroupsOrNewsQuery query) throws IOException {
|
||||
if (NNTPReply.isPositiveCompletion(newnews(query.getNewsgroups(), query.getDate(), query.getTime(), query.isGMT(), query.getDistributions())))
|
||||
return new ReplyIterator(this._reader_);
|
||||
throw new IOException("NEWNEWS command failed: " + getReplyString());
|
||||
}
|
||||
|
||||
public boolean completePendingCommand() throws IOException {
|
||||
return NNTPReply.isPositiveCompletion(getReply());
|
||||
}
|
||||
|
||||
public Writer postArticle() throws IOException {
|
||||
if (!NNTPReply.isPositiveIntermediate(post()))
|
||||
return null;
|
||||
return new DotTerminatedMessageWriter(this._writer_);
|
||||
}
|
||||
|
||||
public Writer forwardArticle(String articleId) throws IOException {
|
||||
if (!NNTPReply.isPositiveIntermediate(ihave(articleId)))
|
||||
return null;
|
||||
return new DotTerminatedMessageWriter(this._writer_);
|
||||
}
|
||||
|
||||
public boolean logout() throws IOException {
|
||||
return NNTPReply.isPositiveCompletion(quit());
|
||||
}
|
||||
|
||||
public boolean authenticate(String username, String password) throws IOException {
|
||||
int replyCode = authinfoUser(username);
|
||||
if (replyCode == 381) {
|
||||
replyCode = authinfoPass(password);
|
||||
if (replyCode == 281) {
|
||||
this._isAllowedToPost = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private BufferedReader __retrieveArticleInfo(String articleRange) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(xover(articleRange)))
|
||||
return null;
|
||||
return new DotTerminatedMessageReader(this._reader_);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleInfo(long articleNumber) throws IOException {
|
||||
return __retrieveArticleInfo(Long.toString(articleNumber));
|
||||
}
|
||||
|
||||
public BufferedReader retrieveArticleInfo(long lowArticleNumber, long highArticleNumber) throws IOException {
|
||||
return __retrieveArticleInfo(lowArticleNumber + "-" + highArticleNumber);
|
||||
}
|
||||
|
||||
public Iterable<Article> iterateArticleInfo(long lowArticleNumber, long highArticleNumber) throws IOException {
|
||||
BufferedReader info = retrieveArticleInfo(lowArticleNumber, highArticleNumber);
|
||||
if (info == null)
|
||||
throw new IOException("XOVER command failed: " + getReplyString());
|
||||
return new ArticleIterator(new ReplyIterator<Article>(info, false));
|
||||
}
|
||||
|
||||
private BufferedReader __retrieveHeader(String header, String articleRange) throws IOException {
|
||||
if (!NNTPReply.isPositiveCompletion(xhdr(header, articleRange)))
|
||||
return null;
|
||||
return new DotTerminatedMessageReader(this._reader_);
|
||||
}
|
||||
|
||||
public BufferedReader retrieveHeader(String header, long articleNumber) throws IOException {
|
||||
return __retrieveHeader(header, Long.toString(articleNumber));
|
||||
}
|
||||
|
||||
public BufferedReader retrieveHeader(String header, long lowArticleNumber, long highArticleNumber) throws IOException {
|
||||
return __retrieveHeader(header, lowArticleNumber + "-" + highArticleNumber);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveHeader(String s, int l, int h) throws IOException {
|
||||
return retrieveHeader(s, (long)l, (long)h);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleInfo(int a, int b) throws IOException {
|
||||
return retrieveArticleInfo((long)a, (long)b);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveHeader(String a, int b) throws IOException {
|
||||
return retrieveHeader(a, (long)b);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean selectArticle(int a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
boolean b = selectArticle((long)a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleInfo(int a) throws IOException {
|
||||
return retrieveArticleInfo((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean selectArticle(int a) throws IOException {
|
||||
return selectArticle((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleHeader(int a) throws IOException {
|
||||
return retrieveArticleHeader((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleHeader(int a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
Reader rdr = retrieveArticleHeader((long)a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return rdr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleBody(int a) throws IOException {
|
||||
return retrieveArticleBody((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticle(int a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
Reader rdr = retrieveArticle((long)a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return rdr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticle(int a) throws IOException {
|
||||
return retrieveArticle((long)a);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleBody(int a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
Reader rdr = retrieveArticleBody((long)a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return rdr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticle(String a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
Reader rdr = retrieveArticle(a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return rdr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleBody(String a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
Reader rdr = retrieveArticleBody(a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return rdr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public Reader retrieveArticleHeader(String a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
Reader rdr = retrieveArticleHeader(a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return rdr;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean selectArticle(String a, ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
boolean b = selectArticle(a, ai);
|
||||
__ai2ap(ai, ap);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean selectArticle(ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
boolean b = selectArticle(ai);
|
||||
__ai2ap(ai, ap);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean selectNextArticle(ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
boolean b = selectNextArticle(ai);
|
||||
__ai2ap(ai, ap);
|
||||
return b;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public boolean selectPreviousArticle(ArticlePointer ap) throws IOException {
|
||||
ArticleInfo ai = __ap2ai(ap);
|
||||
boolean b = selectPreviousArticle(ai);
|
||||
__ai2ap(ai, ap);
|
||||
return b;
|
||||
}
|
||||
|
||||
private ArticleInfo __ap2ai(ArticlePointer ap) {
|
||||
if (ap == null)
|
||||
return null;
|
||||
ArticleInfo ai = new ArticleInfo();
|
||||
return ai;
|
||||
}
|
||||
|
||||
private void __ai2ap(ArticleInfo ai, ArticlePointer ap) {
|
||||
if (ap != null) {
|
||||
ap.articleId = ai.articleId;
|
||||
ap.articleNumber = (int)ai.articleNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
public final class NNTPCommand {
|
||||
public static final int ARTICLE = 0;
|
||||
|
||||
public static final int BODY = 1;
|
||||
|
||||
public static final int GROUP = 2;
|
||||
|
||||
public static final int HEAD = 3;
|
||||
|
||||
public static final int HELP = 4;
|
||||
|
||||
public static final int IHAVE = 5;
|
||||
|
||||
public static final int LAST = 6;
|
||||
|
||||
public static final int LIST = 7;
|
||||
|
||||
public static final int NEWGROUPS = 8;
|
||||
|
||||
public static final int NEWNEWS = 9;
|
||||
|
||||
public static final int NEXT = 10;
|
||||
|
||||
public static final int POST = 11;
|
||||
|
||||
public static final int QUIT = 12;
|
||||
|
||||
public static final int SLAVE = 13;
|
||||
|
||||
public static final int STAT = 14;
|
||||
|
||||
public static final int AUTHINFO = 15;
|
||||
|
||||
public static final int XOVER = 16;
|
||||
|
||||
public static final int XHDR = 17;
|
||||
|
||||
private static final String[] _commands = new String[] {
|
||||
"ARTICLE", "BODY", "GROUP", "HEAD", "HELP", "IHAVE", "LAST", "LIST", "NEWGROUPS", "NEWNEWS",
|
||||
"NEXT", "POST", "QUIT", "SLAVE", "STAT", "AUTHINFO", "XOVER", "XHDR" };
|
||||
|
||||
public static final String getCommand(int command) {
|
||||
return _commands[command];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public final class NNTPConnectionClosedException extends IOException {
|
||||
private static final long serialVersionUID = 1029785635891040770L;
|
||||
|
||||
public NNTPConnectionClosedException() {}
|
||||
|
||||
public NNTPConnectionClosedException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
public final class NNTPReply {
|
||||
public static final int HELP_TEXT_FOLLOWS = 100;
|
||||
|
||||
public static final int DEBUG_OUTPUT = 199;
|
||||
|
||||
public static final int SERVER_READY_POSTING_ALLOWED = 200;
|
||||
|
||||
public static final int SERVER_READY_POSTING_NOT_ALLOWED = 201;
|
||||
|
||||
public static final int SLAVE_STATUS_NOTED = 202;
|
||||
|
||||
public static final int CLOSING_CONNECTION = 205;
|
||||
|
||||
public static final int GROUP_SELECTED = 211;
|
||||
|
||||
public static final int ARTICLE_RETRIEVED_HEAD_AND_BODY_FOLLOW = 220;
|
||||
|
||||
public static final int ARTICLE_RETRIEVED_HEAD_FOLLOWS = 221;
|
||||
|
||||
public static final int ARTICLE_RETRIEVED_BODY_FOLLOWS = 222;
|
||||
|
||||
public static final int ARTICLE_RETRIEVED_REQUEST_TEXT_SEPARATELY = 223;
|
||||
|
||||
public static final int ARTICLE_LIST_BY_MESSAGE_ID_FOLLOWS = 230;
|
||||
|
||||
public static final int NEW_NEWSGROUP_LIST_FOLLOWS = 231;
|
||||
|
||||
public static final int ARTICLE_TRANSFERRED_OK = 235;
|
||||
|
||||
public static final int ARTICLE_POSTED_OK = 240;
|
||||
|
||||
public static final int AUTHENTICATION_ACCEPTED = 281;
|
||||
|
||||
public static final int SEND_ARTICLE_TO_TRANSFER = 335;
|
||||
|
||||
public static final int SEND_ARTICLE_TO_POST = 340;
|
||||
|
||||
public static final int MORE_AUTH_INFO_REQUIRED = 381;
|
||||
|
||||
public static final int SERVICE_DISCONTINUED = 400;
|
||||
|
||||
public static final int NO_SUCH_NEWSGROUP = 411;
|
||||
|
||||
public static final int NO_NEWSGROUP_SELECTED = 412;
|
||||
|
||||
public static final int NO_CURRENT_ARTICLE_SELECTED = 420;
|
||||
|
||||
public static final int NO_NEXT_ARTICLE = 421;
|
||||
|
||||
public static final int NO_PREVIOUS_ARTICLE = 422;
|
||||
|
||||
public static final int NO_SUCH_ARTICLE_NUMBER = 423;
|
||||
|
||||
public static final int NO_SUCH_ARTICLE_FOUND = 430;
|
||||
|
||||
public static final int ARTICLE_NOT_WANTED = 435;
|
||||
|
||||
public static final int TRANSFER_FAILED = 436;
|
||||
|
||||
public static final int ARTICLE_REJECTED = 437;
|
||||
|
||||
public static final int POSTING_NOT_ALLOWED = 440;
|
||||
|
||||
public static final int POSTING_FAILED = 441;
|
||||
|
||||
public static final int AUTHENTICATION_REQUIRED = 480;
|
||||
|
||||
public static final int AUTHENTICATION_REJECTED = 482;
|
||||
|
||||
public static final int COMMAND_NOT_RECOGNIZED = 500;
|
||||
|
||||
public static final int COMMAND_SYNTAX_ERROR = 501;
|
||||
|
||||
public static final int PERMISSION_DENIED = 502;
|
||||
|
||||
public static final int PROGRAM_FAULT = 503;
|
||||
|
||||
public static boolean isInformational(int reply) {
|
||||
return (reply >= 100 && reply < 200);
|
||||
}
|
||||
|
||||
public static boolean isPositiveCompletion(int reply) {
|
||||
return (reply >= 200 && reply < 300);
|
||||
}
|
||||
|
||||
public static boolean isPositiveIntermediate(int reply) {
|
||||
return (reply >= 300 && reply < 400);
|
||||
}
|
||||
|
||||
public static boolean isNegativeTransient(int reply) {
|
||||
return (reply >= 400 && reply < 500);
|
||||
}
|
||||
|
||||
public static boolean isNegativePermanent(int reply) {
|
||||
return (reply >= 500 && reply < 600);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public final class NewGroupsOrNewsQuery {
|
||||
private final String __date;
|
||||
|
||||
private final String __time;
|
||||
|
||||
private StringBuffer __distributions;
|
||||
|
||||
private StringBuffer __newsgroups;
|
||||
|
||||
private final boolean __isGMT;
|
||||
|
||||
public NewGroupsOrNewsQuery(Calendar date, boolean gmt) {
|
||||
this.__distributions = null;
|
||||
this.__newsgroups = null;
|
||||
this.__isGMT = gmt;
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
int num = date.get(1);
|
||||
String str = Integer.toString(num);
|
||||
num = str.length();
|
||||
if (num >= 2) {
|
||||
buffer.append(str.substring(num - 2));
|
||||
} else {
|
||||
buffer.append("00");
|
||||
}
|
||||
num = date.get(2) + 1;
|
||||
str = Integer.toString(num);
|
||||
num = str.length();
|
||||
if (num == 1) {
|
||||
buffer.append('0');
|
||||
buffer.append(str);
|
||||
} else if (num == 2) {
|
||||
buffer.append(str);
|
||||
} else {
|
||||
buffer.append("01");
|
||||
}
|
||||
num = date.get(5);
|
||||
str = Integer.toString(num);
|
||||
num = str.length();
|
||||
if (num == 1) {
|
||||
buffer.append('0');
|
||||
buffer.append(str);
|
||||
} else if (num == 2) {
|
||||
buffer.append(str);
|
||||
} else {
|
||||
buffer.append("01");
|
||||
}
|
||||
this.__date = buffer.toString();
|
||||
buffer.setLength(0);
|
||||
num = date.get(11);
|
||||
str = Integer.toString(num);
|
||||
num = str.length();
|
||||
if (num == 1) {
|
||||
buffer.append('0');
|
||||
buffer.append(str);
|
||||
} else if (num == 2) {
|
||||
buffer.append(str);
|
||||
} else {
|
||||
buffer.append("00");
|
||||
}
|
||||
num = date.get(12);
|
||||
str = Integer.toString(num);
|
||||
num = str.length();
|
||||
if (num == 1) {
|
||||
buffer.append('0');
|
||||
buffer.append(str);
|
||||
} else if (num == 2) {
|
||||
buffer.append(str);
|
||||
} else {
|
||||
buffer.append("00");
|
||||
}
|
||||
num = date.get(13);
|
||||
str = Integer.toString(num);
|
||||
num = str.length();
|
||||
if (num == 1) {
|
||||
buffer.append('0');
|
||||
buffer.append(str);
|
||||
} else if (num == 2) {
|
||||
buffer.append(str);
|
||||
} else {
|
||||
buffer.append("00");
|
||||
}
|
||||
this.__time = buffer.toString();
|
||||
}
|
||||
|
||||
public void addNewsgroup(String newsgroup) {
|
||||
if (this.__newsgroups != null) {
|
||||
this.__newsgroups.append(',');
|
||||
} else {
|
||||
this.__newsgroups = new StringBuffer();
|
||||
}
|
||||
this.__newsgroups.append(newsgroup);
|
||||
}
|
||||
|
||||
public void omitNewsgroup(String newsgroup) {
|
||||
addNewsgroup("!" + newsgroup);
|
||||
}
|
||||
|
||||
public void addDistribution(String distribution) {
|
||||
if (this.__distributions != null) {
|
||||
this.__distributions.append(',');
|
||||
} else {
|
||||
this.__distributions = new StringBuffer();
|
||||
}
|
||||
this.__distributions.append(distribution);
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return this.__date;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return this.__time;
|
||||
}
|
||||
|
||||
public boolean isGMT() {
|
||||
return this.__isGMT;
|
||||
}
|
||||
|
||||
public String getDistributions() {
|
||||
return (this.__distributions == null) ? null : this.__distributions.toString();
|
||||
}
|
||||
|
||||
public String getNewsgroups() {
|
||||
return (this.__newsgroups == null) ? null : this.__newsgroups.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
public final class NewsgroupInfo {
|
||||
public static final int UNKNOWN_POSTING_PERMISSION = 0;
|
||||
|
||||
public static final int MODERATED_POSTING_PERMISSION = 1;
|
||||
|
||||
public static final int PERMITTED_POSTING_PERMISSION = 2;
|
||||
|
||||
public static final int PROHIBITED_POSTING_PERMISSION = 3;
|
||||
|
||||
private String __newsgroup;
|
||||
|
||||
private long __estimatedArticleCount;
|
||||
|
||||
private long __firstArticle;
|
||||
|
||||
private long __lastArticle;
|
||||
|
||||
private int __postingPermission;
|
||||
|
||||
void _setNewsgroup(String newsgroup) {
|
||||
this.__newsgroup = newsgroup;
|
||||
}
|
||||
|
||||
void _setArticleCount(long count) {
|
||||
this.__estimatedArticleCount = count;
|
||||
}
|
||||
|
||||
void _setFirstArticle(long first) {
|
||||
this.__firstArticle = first;
|
||||
}
|
||||
|
||||
void _setLastArticle(long last) {
|
||||
this.__lastArticle = last;
|
||||
}
|
||||
|
||||
void _setPostingPermission(int permission) {
|
||||
this.__postingPermission = permission;
|
||||
}
|
||||
|
||||
public String getNewsgroup() {
|
||||
return this.__newsgroup;
|
||||
}
|
||||
|
||||
public long getArticleCountLong() {
|
||||
return this.__estimatedArticleCount;
|
||||
}
|
||||
|
||||
public long getFirstArticleLong() {
|
||||
return this.__firstArticle;
|
||||
}
|
||||
|
||||
public long getLastArticleLong() {
|
||||
return this.__lastArticle;
|
||||
}
|
||||
|
||||
public int getPostingPermission() {
|
||||
return this.__postingPermission;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getArticleCount() {
|
||||
return (int)this.__estimatedArticleCount;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getFirstArticle() {
|
||||
return (int)this.__firstArticle;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getLastArticle() {
|
||||
return (int)this.__lastArticle;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
class NewsgroupIterator implements Iterator<NewsgroupInfo>, Iterable<NewsgroupInfo> {
|
||||
private final Iterator<String> stringIterator;
|
||||
|
||||
public NewsgroupIterator(Iterable<String> iterableString) {
|
||||
this.stringIterator = iterableString.iterator();
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return this.stringIterator.hasNext();
|
||||
}
|
||||
|
||||
public NewsgroupInfo next() {
|
||||
String line = this.stringIterator.next();
|
||||
return NNTPClient.__parseNewsgroupListEntry(line);
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
this.stringIterator.remove();
|
||||
}
|
||||
|
||||
public Iterator<NewsgroupInfo> iterator() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import org.apache.commons.net.io.DotTerminatedMessageReader;
|
||||
import org.apache.commons.net.io.Util;
|
||||
|
||||
class ReplyIterator implements Iterator<String>, Iterable<String> {
|
||||
private final BufferedReader reader;
|
||||
|
||||
private String line;
|
||||
|
||||
private Exception savedException;
|
||||
|
||||
ReplyIterator(BufferedReader _reader, boolean addDotReader) throws IOException {
|
||||
this.reader = addDotReader ? new DotTerminatedMessageReader(_reader) : _reader;
|
||||
this.line = this.reader.readLine();
|
||||
if (this.line == null)
|
||||
Util.closeQuietly(this.reader);
|
||||
}
|
||||
|
||||
ReplyIterator(BufferedReader _reader) throws IOException {
|
||||
this(_reader, true);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
if (this.savedException != null)
|
||||
throw new NoSuchElementException(this.savedException.toString());
|
||||
return (this.line != null);
|
||||
}
|
||||
|
||||
public String next() throws NoSuchElementException {
|
||||
if (this.savedException != null)
|
||||
throw new NoSuchElementException(this.savedException.toString());
|
||||
String prev = this.line;
|
||||
if (prev == null)
|
||||
throw new NoSuchElementException();
|
||||
try {
|
||||
this.line = this.reader.readLine();
|
||||
if (this.line == null)
|
||||
Util.closeQuietly(this.reader);
|
||||
} catch (IOException ex) {
|
||||
this.savedException = ex;
|
||||
Util.closeQuietly(this.reader);
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Iterator<String> iterator() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package org.apache.commons.net.nntp;
|
||||
|
||||
public class SimpleNNTPHeader {
|
||||
private final String __subject;
|
||||
|
||||
private final String __from;
|
||||
|
||||
private final StringBuilder __newsgroups;
|
||||
|
||||
private final StringBuilder __headerFields;
|
||||
|
||||
private int __newsgroupCount;
|
||||
|
||||
public SimpleNNTPHeader(String from, String subject) {
|
||||
this.__from = from;
|
||||
this.__subject = subject;
|
||||
this.__newsgroups = new StringBuilder();
|
||||
this.__headerFields = new StringBuilder();
|
||||
this.__newsgroupCount = 0;
|
||||
}
|
||||
|
||||
public void addNewsgroup(String newsgroup) {
|
||||
if (this.__newsgroupCount++ > 0)
|
||||
this.__newsgroups.append(',');
|
||||
this.__newsgroups.append(newsgroup);
|
||||
}
|
||||
|
||||
public void addHeaderField(String headerField, String value) {
|
||||
this.__headerFields.append(headerField);
|
||||
this.__headerFields.append(": ");
|
||||
this.__headerFields.append(value);
|
||||
this.__headerFields.append('\n');
|
||||
}
|
||||
|
||||
public String getFromAddress() {
|
||||
return this.__from;
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return this.__subject;
|
||||
}
|
||||
|
||||
public String getNewsgroups() {
|
||||
return this.__newsgroups.toString();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuilder header = new StringBuilder();
|
||||
header.append("From: ");
|
||||
header.append(this.__from);
|
||||
header.append("\nNewsgroups: ");
|
||||
header.append(this.__newsgroups.toString());
|
||||
header.append("\nSubject: ");
|
||||
header.append(this.__subject);
|
||||
header.append('\n');
|
||||
if (this.__headerFields.length() > 0)
|
||||
header.append(this.__headerFields.toString());
|
||||
header.append('\n');
|
||||
return header.toString();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue