Author: rwinston
Date: Sun Feb 17 15:16:12 2008
New Revision: 628576
URL: http://svn.apache.org/viewvc?rev=628576&view=rev
Log:
NET-178
Modified:
commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java
Modified:
commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java
URL:
http://svn.apache.org/viewvc/commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java?rev=628576&r1=628575&r2=628576&view=diff
==============================================================================
---
commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java
(original)
+++
commons/proper/net/branches/NET_2_0/src/main/java/org/apache/commons/net/smtp/SMTP.java
Sun Feb 17 15:16:12 2008
@@ -22,6 +22,8 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;
@@ -93,13 +95,16 @@
// but we use ISO-8859-1 just in case 8-bit characters cross
// the wire.
private static final String __DEFAULT_ENCODING = "ISO-8859-1";
+
+ /** The encoding to use (user-settable) */
+ private String encoding = __DEFAULT_ENCODING;
private StringBuffer __commandBuffer;
BufferedReader _reader;
BufferedWriter _writer;
int _replyCode;
- Vector _replyLines;
+ ArrayList<String> _replyLines;
boolean _newReplyString;
String _replyString;
@@ -118,11 +123,20 @@
{
setDefaultPort(DEFAULT_PORT);
__commandBuffer = new StringBuffer();
- _replyLines = new Vector();
+ _replyLines = new ArrayList<String>();
_newReplyString = false;
_replyString = null;
_commandSupport_ = new ProtocolCommandSupport(this);
}
+
+ /**
+ * Overloaded constructor where the user may specify a default encoding.
+ * @param encoding
+ */
+ public SMTP(String encoding) {
+ this();
+ this.encoding = encoding;
+ }
private int __sendCommand(String command, String args, boolean
includeSpace)
throws IOException
@@ -162,7 +176,7 @@
int length;
_newReplyString = true;
- _replyLines.setSize(0);
+ _replyLines.clear();
String line = _reader.readLine();
@@ -188,7 +202,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) == '-')
@@ -201,7 +215,7 @@
throw new SMTPConnectionClosedException(
"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
@@ -228,11 +242,12 @@
super._connectAction_();
_reader =
new BufferedReader(new InputStreamReader(_input_,
- __DEFAULT_ENCODING));
+ encoding));
_writer =
new BufferedWriter(new OutputStreamWriter(_output_,
- __DEFAULT_ENCODING));
+ encoding));
__getReply();
+
}
@@ -273,7 +288,7 @@
_reader = null;
_writer = null;
_replyString = null;
- _replyLines.setSize(0);
+ _replyLines.clear();
_newReplyString = false;
}
@@ -428,7 +443,7 @@
{
String[] lines;
lines = new String[_replyLines.size()];
- _replyLines.copyInto(lines);
+ _replyLines.addAll(Arrays.asList(lines));
return lines;
}
@@ -441,17 +456,16 @@
***/
public String getReplyString()
{
- Enumeration en;
- StringBuffer buffer;
+ StringBuilder buffer;
if (!_newReplyString)
return _replyString;
- buffer = new StringBuffer(256);
- en = _replyLines.elements();
- while (en.hasMoreElements())
+ buffer = new StringBuilder();
+
+ for (String line : _replyLines)
{
- buffer.append((String)en.nextElement());
+ buffer.append((String)line);
buffer.append(SocketClient.NETASCII_EOL);
}