Author: bago
Date: Fri Jun 20 08:56:58 2008
New Revision: 669958
URL: http://svn.apache.org/viewvc?rev=669958&view=rev
Log:
Extracted CRLFOutputStream from ExtraDotOutputStream (remove com.sun dependency)
Added:
james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java
(with props)
Modified:
james/server/trunk/core-library/src/main/java/org/apache/james/util/ExtraDotOutputStream.java
Added:
james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java?rev=669958&view=auto
==============================================================================
---
james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java
(added)
+++
james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java
Fri Jun 20 08:56:58 2008
@@ -0,0 +1,91 @@
+/****************************************************************
+ * 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. *
+ ****************************************************************/
+
+
+
+package org.apache.james.util;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A Filter for use with SMTP or other protocols in which lines must end with
+ * CRLF. Converts every "isolated" occourency of \r or \n with \r\n
+ */
+public class CRLFOutputStream extends FilterOutputStream {
+
+ /**
+ * Counter for number of last (0A or 0D).
+ */
+ protected int countLast0A0D;
+
+ /**
+ * Constructor that wraps an OutputStream.
+ *
+ * @param out the OutputStream to be wrapped
+ */
+ public CRLFOutputStream(OutputStream out) {
+ super(out);
+ countLast0A0D = 2; // we already assume a CRLF at beginning (otherwise
TOP would not work correctly !)
+ }
+
+ /**
+ * Writes a byte to the stream
+ * Fixes any naked CR or LF to the RFC 2821 mandated CFLF
+ * pairing.
+ *
+ * @param b the byte to write
+ *
+ * @throws IOException if an error occurs writing the byte
+ */
+ public void write(int b) throws IOException {
+ switch (b) {
+ case '\r':
+ if (countLast0A0D == 1) out.write('\n'); // two CR in a row,
so insert an LF first
+ countLast0A0D = 1;
+ break;
+ case '\n':
+ /* RFC 2821 #2.3.7 mandates that line termination is
+ * CRLF, and that CR and LF must not be transmitted
+ * except in that pairing. If we get a naked LF,
+ * convert to CRLF.
+ */
+ if (countLast0A0D != 1) out.write('\r');
+ countLast0A0D = 2;
+ break;
+ default:
+ // we're no longer at the start of a line
+ countLast0A0D = 0;
+ break;
+ }
+ out.write(b);
+ }
+
+ /**
+ * Ensure that the stream is CRLF terminated.
+ *
+ * @throws IOException if an error occurs writing the byte
+ */
+ public void checkCRLFTerminator() throws IOException {
+ if (countLast0A0D != 2) {
+ write('\n');
+ }
+ }
+}
Propchange:
james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
james/server/trunk/core-library/src/main/java/org/apache/james/util/CRLFOutputStream.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
james/server/trunk/core-library/src/main/java/org/apache/james/util/ExtraDotOutputStream.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/core-library/src/main/java/org/apache/james/util/ExtraDotOutputStream.java?rev=669958&r1=669957&r2=669958&view=diff
==============================================================================
---
james/server/trunk/core-library/src/main/java/org/apache/james/util/ExtraDotOutputStream.java
(original)
+++
james/server/trunk/core-library/src/main/java/org/apache/james/util/ExtraDotOutputStream.java
Fri Jun 20 08:56:58 2008
@@ -21,7 +21,6 @@
package org.apache.james.util;
-import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -29,22 +28,7 @@
* Adds extra dot if dot occurs in message body at beginning of line
(according to RFC1939)
* Compare also org.apache.james.smtpserver.SMTPInputStream
*/
-public class ExtraDotOutputStream extends FilterOutputStream {
-
- /*
- static public void main(String[] args) throws IOException
- {
- String data = ".This is a test\r\nof the thing.\r\nWe should not have
much trouble.\r\n.doubled?\r\nor not?\n.doubled\nor not?\r\n\r\n\n\n\r\r\r\n";
-
- OutputStream os = new ExtraDotOutputStream(System.out);
- os.write(data.getBytes());
- }
- */
-
- /**
- * Counter for number of last (0A or 0D).
- */
- protected int countLast0A0D;
+public class ExtraDotOutputStream extends CRLFOutputStream {
/**
* Constructor that wraps an OutputStream.
@@ -53,12 +37,11 @@
*/
public ExtraDotOutputStream(OutputStream out) {
super(out);
- countLast0A0D = 2; // we already assume a CRLF at beginning (otherwise
TOP would not work correctly !)
}
/**
* Writes a byte to the stream, adding dots where appropriate.
- * Also fixes any naked CR or LF to the RFC 2821 mandated CFLF
+ * Also fixes any naked CR or LF to the RFC 2821 mandated CRLF
* pairing.
*
* @param b the byte to write
@@ -66,43 +49,10 @@
* @throws IOException if an error occurs writing the byte
*/
public void write(int b) throws IOException {
- switch (b) {
- case '.':
- if (countLast0A0D == 2) {
- // add extra dot (the first of the pair)
- out.write('.');
- }
- countLast0A0D = 0;
- break;
- case '\r':
- if (countLast0A0D == 1) out.write('\n'); // two CR in a row,
so insert an LF first
- countLast0A0D = 1;
- break;
- case '\n':
- /* RFC 2821 #2.3.7 mandates that line termination is
- * CRLF, and that CR and LF must not be transmitted
- * except in that pairing. If we get a naked LF,
- * convert to CRLF.
- */
- if (countLast0A0D != 1) out.write('\r');
- countLast0A0D = 2;
- break;
- default:
- // we're no longer at the start of a line
- countLast0A0D = 0;
- break;
- }
- out.write(b);
- }
-
- /**
- * Ensure that the stream is CRLF terminated.
- *
- * @throws IOException if an error occurs writing the byte
- */
- public void checkCRLFTerminator() throws IOException {
- if (countLast0A0D != 2) {
- write('\n');
+ if (b == '.' && countLast0A0D == 2) {
+ // add extra dot (the first of the pair)
+ out.write('.');
}
+ super.write(b);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]