Author: rwinston
Date: Thu Nov 2 13:02:43 2006
New Revision: 470520
URL: http://svn.apache.org/viewvc?view=rev&rev=470520
Log:
* Add _socket_.isConnected() and null check
* Add some generification
Modified:
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/SocketClient.java
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTP.java
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTPClient.java
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java
Modified:
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/SocketClient.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/SocketClient.java?view=diff&rev=470520&r1=470519&r2=470520
==============================================================================
---
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/SocketClient.java
(original)
+++
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/SocketClient.java
Thu Nov 2 13:02:43 2006
@@ -68,11 +68,6 @@
/** The socket used for the connection. */
protected Socket _socket_;
- /**
- * A status variable indicating if the client's socket is currently open.
- */
- protected boolean _isConnected_;
-
/** The default port the client should connect to. */
protected int _defaultPort_;
@@ -101,7 +96,6 @@
_output_ = null;
_timeout_ = 0;
_defaultPort_ = 0;
- _isConnected_ = false;
_socketFactory_ = __DEFAULT_SOCKET_FACTORY;
_serverSocketFactory_ = __DEFAULT_SERVER_SOCKET_FACTORY;
}
@@ -128,7 +122,6 @@
_socket_.setSoTimeout(_timeout_);
_input_ = _socket_.getInputStream();
_output_ = _socket_.getOutputStream();
- _isConnected_ = true;
}
@@ -279,7 +272,6 @@
if (_socket_ != null) _socket_ = null;
_input_ = null;
_output_ = null;
- _isConnected_ = false;
}
@@ -291,7 +283,10 @@
*/
public boolean isConnected()
{
- return _isConnected_;
+ if (_socket_ == null)
+ return false;
+
+ return _socket_.isConnected();
}
Modified:
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTP.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTP.java?view=diff&rev=470520&r1=470519&r2=470520
==============================================================================
---
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTP.java
(original)
+++
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTP.java
Thu Nov 2 13:02:43 2006
@@ -22,8 +22,8 @@
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
-import java.util.Enumeration;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Arrays;
import org.apache.commons.net.MalformedServerReplyException;
import org.apache.commons.net.ProtocolCommandListener;
@@ -214,7 +214,7 @@
private StringBuilder __commandBuffer = new StringBuilder();
protected int _replyCode;
- protected Vector<String> _replyLines;
+ protected ArrayList<String> _replyLines;
protected boolean _newReplyString;
protected String _replyString;
protected String _controlEncoding;
@@ -252,7 +252,7 @@
{
super();
setDefaultPort(DEFAULT_PORT);
- _replyLines = new Vector<String>();
+ _replyLines = new ArrayList<String>();
_newReplyString = false;
_replyString = null;
_commandSupport_ = new ProtocolCommandSupport(this);
@@ -264,7 +264,7 @@
int length;
_newReplyString = true;
- _replyLines.setSize(0);
+ //_replyLines. setSize(0);
String line = _controlInput_.readLine();
@@ -290,7 +290,7 @@
"Could not parse response code.\nServer Reply: " + line);
}
- _replyLines.addElement(line);
+ _replyLines.add(line);
// Get extra lines if message continues.
if (length > 3 && line.charAt(3) == '-')
@@ -303,7 +303,7 @@
throw new FTPConnectionClosedException(
"Connection closed without indication.");
- _replyLines.addElement(line);
+ _replyLines.add(line);
// The length() check handles problems that could arise from
readLine()
// returning too soon after encountering a naked CR or some
other
@@ -407,7 +407,6 @@
super.disconnect();
_controlInput_ = null;
_controlOutput_ = null;
- _replyLines.setSize(0);
_newReplyString = false;
_replyString = null;
}
@@ -612,7 +611,7 @@
{
String[] lines;
lines = new String[_replyLines.size()];
- _replyLines.copyInto(lines);
+ _replyLines.addAll(Arrays.asList(lines));
return lines;
}
@@ -625,22 +624,20 @@
***/
public String getReplyString()
{
- Enumeration en;
- StringBuffer buffer;
+ StringBuilder buffer;
if (!_newReplyString) {
return _replyString;
}
- buffer = new StringBuffer(256);
- en = _replyLines.elements();
- while (en.hasMoreElements())
- {
- buffer.append((String)en.nextElement());
- buffer.append(SocketClient.NETASCII_EOL);
+ buffer = new StringBuilder(256);
+
+ for (String line : _replyLines) {
+ buffer.append(line);
+ buffer.append(SocketClient.NETASCII_EOL);
}
-
- _newReplyString = false;
+
+ _newReplyString = false;
return (_replyString = buffer.toString());
}
Modified:
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTPClient.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTPClient.java?view=diff&rev=470520&r1=470519&r2=470520
==============================================================================
---
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTPClient.java
(original)
+++
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/FTPClient.java
Thu Nov 2 13:02:43 2006
@@ -24,7 +24,8 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
-import java.util.Vector;
+import java.util.ArrayList;
+import java.util.Arrays;
import org.apache.commons.net.MalformedServerReplyException;
import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory;
@@ -231,6 +232,7 @@
* @see FTPFileEntryParserFactory
* @see DefaultFTPFileEntryParserFactory
* @see FTPClientConfig
+ *
* @see org.apache.commons.net.MalformedServerReplyException
**/
public class FTPClient extends FTP
@@ -513,7 +515,7 @@
if (pasv() != FTPReply.ENTERING_PASSIVE_MODE)
return null;
- __parsePassiveModeReply((String)_replyLines.elementAt(0));
+ __parsePassiveModeReply((String)_replyLines.get(0));
socket = _socketFactory_.createSocket(__passiveHost,
__passivePort);
if ((__restartOffset > 0) && !restart(__restartOffset))
@@ -902,7 +904,7 @@
return false;
__dataConnectionMode = PASSIVE_REMOTE_DATA_CONNECTION_MODE;
- __parsePassiveModeReply((String)_replyLines.elementAt(0));
+ __parsePassiveModeReply((String)_replyLines.get(0));
return true;
}
@@ -1814,7 +1816,7 @@
if (pwd() != FTPReply.PATHNAME_CREATED)
return null;
- return __parsePathname((String)_replyLines.elementAt(0));
+ return __parsePathname((String)_replyLines.get(0));
}
@@ -1861,7 +1863,7 @@
// in practice FTP servers deviate, so we soften the condition to
// a positive completion.
if (__systemName == null && FTPReply.isPositiveCompletion(syst()))
- __systemName = ((String)_replyLines.elementAt(0)).substring(4);
+ __systemName = ((String)_replyLines.get(0)).substring(4);
return __systemName;
}
@@ -1959,7 +1961,7 @@
String line;
Socket socket;
BufferedReader reader;
- Vector results;
+ ArrayList<String> results;
if ((socket = _openDataConnection_(FTPCommand.NLST, pathname)) == null)
return null;
@@ -1967,9 +1969,9 @@
reader =
new BufferedReader(new InputStreamReader(socket.getInputStream(),
getControlEncoding()));
- results = new Vector();
+ results = new ArrayList<String>();
while ((line = reader.readLine()) != null)
- results.addElement(line);
+ results.add(line);
reader.close();
socket.close();
@@ -1977,7 +1979,7 @@
{
String[] result;
result = new String[results.size()];
- results.copyInto(result);
+ results.addAll(Arrays.asList(result));
return result;
}
@@ -2011,91 +2013,6 @@
return listNames(null);
}
-
- /**
- * Using the supplied <code>parserKey</code>, obtain a list
- * of file information for the current working directory or for just a
- * single file.
- * <p>
- * If <code>key</code> is null, this object will try to autodetect
- * the system-type/parser-type by calling the SYST command.
- * <p>
- * Under the DefaultFTPFileEntryParserFactory, which is used unless a
- * different factory has been specified, the key
- * can be either a recognized System type for which a parser has been
- * defined, or the fully qualified class name of a class that implements
- * org.apache.commons.net.ftp.FTPFileEntryParser.
- * <p>
- * This information is obtained through the LIST command. The contents of
- * the returned array is determined by the<code> FTPFileEntryParser </code>
- * used.
- * <p>
- * @param parserKey This is a "handle" which the parser factory used
- * must be able to resolve into a class implementing
- * FTPFileEntryParser.
- * <p>
- * In the DefaultFTPFileEntryParserFactory, this
- * may either be a specific key identifying a server type,
- * which is used to identify a parser type,
- * or the fully qualified class name of the parser. See
- * DefaultFTPFileEntryParserFactory.createFileEntryParser
- * for full details.
- * <p>
- * If this parameter is null, will attempt to generate a
key
- * by running the SYST command. This should cause no
problem
- * with the functionality implemented in the
- * DefaultFTPFileEntryParserFactory, but may not map so
well
- * to an alternative user-created factory. If that is the
- * case, calling this routine with a null parameter and a
- * custom parser factory may not be advisable.
- * <p>
- * @param pathname The file or directory to list. Since the server may
- * or may not expand glob expressions, using them here
- * is not recommended and may well cause this method to
- * fail.
- *
- * @return The list of file information contained in the given path in
- * the format determined by the parser represented by the
- * <code> parserKey </code> parameter.
- * <p><b>
- * NOTE:</b> This array may contain null members if any
of the
- * individual file listings failed to parse. The caller should
- * check each entry for null before referencing it.
- * @exception FTPConnectionClosedException
- * If the FTP server prematurely closes the connection
- * as a result of the client being idle or some other
- * reason causing the server to send FTP reply code 421.
- * This exception may be caught either as an IOException
- * or independently as itself.
- * @exception IOException
- * If an I/O error occurs while either sending a
- * command to the server or receiving a reply
- * from the server.
- * @exception ParserInitializationException
- * Thrown if the parserKey parameter cannot be
- * resolved by the selected parser factory.
- * In the DefaultFTPEntryParserFactory, this will
- * happen when parserKey is neither
- * the fully qualified class name of a class
- * implementing the interface
- * org.apache.commons.net.ftp.FTPFileEntryParser
- * nor a string containing one of the recognized keys
- * mapping to such a parser or if class loader
- * security issues prevent its being loaded.
- * @see org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
- * @see org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
- * @see org.apache.commons.net.ftp.FTPFileEntryParser
- * @deprecated use [EMAIL PROTECTED] #listFiles() listFiles()} or
- * [EMAIL PROTECTED] #listFiles(String) listFiles(String)} instead and
specify the
- * parser Key in an [EMAIL PROTECTED] #FTPClientConfig FTPClientConfig}
object instead.
- */
- public FTPFile[] listFiles(String parserKey, String pathname)
- throws IOException
- {
- FTPListParseEngine engine =
- initiateListParsing(parserKey, pathname);
- return engine.getFiles();
- }
/**
Modified:
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java?view=diff&rev=470520&r1=470519&r2=470520
==============================================================================
---
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
(original)
+++
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/ftp/parser/VMSVersioningFTPEntryParser.java
Thu Nov 2 13:02:43 2006
@@ -116,7 +116,7 @@
*/
public List preParse(List original) {
original = super.preParse(original);
- HashMap existingEntries = new HashMap();
+ HashMap<String, NameVersion> existingEntries = new HashMap<String,
NameVersion>();
ListIterator iter = original.listIterator();
while (iter.hasNext()) {
String entry = ((String)iter.next()).trim();
Modified:
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java?view=diff&rev=470520&r1=470519&r2=470520
==============================================================================
---
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java
(original)
+++
jakarta/commons/proper/net/branches/JDK_1_5_BRANCH/src/main/java/org/apache/commons/net/nntp/SimpleNNTPHeader.java
Thu Nov 2 13:02:43 2006
@@ -47,8 +47,8 @@
public class SimpleNNTPHeader
{
private String __subject, __from;
- private StringBuffer __newsgroups;
- private StringBuffer __headerFields;
+ private StringBuilder __newsgroups;
+ private StringBuilder __headerFields;
private int __newsgroupCount;
/***
@@ -64,8 +64,8 @@
{
__from = from;
__subject = subject;
- __newsgroups = new StringBuffer();
- __headerFields = new StringBuffer();
+ __newsgroups = new StringBuilder();
+ __headerFields = new StringBuilder();
__newsgroupCount = 0;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]