james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Harmeet Bedi" <harm...@kodemuse.com>
Subject Re: NNTP Changes
Date Tue, 18 Mar 2003 03:10:19 GMT
----- Original Message -----
From: "Noel J. Bergman" <noel@devtech.com>
Subject: TODO: NNTP Changes


> We don't want to use a Reader when dealing with message bodies. Readers
know
> about character encodings, and we don't want to do that for the message
> body.

James seems to be dealing a lot with readers and writers. For example an
igrep on InternetPrintWriter shows this

./core/MimeMessageWrapper.java:98:import
org.apache.james.util.InternetPrintWriter;
./core/MimeMessageWrapper.java:288:            PrintWriter pos = new
InternetPrintWriter(new BufferedWriter(new OutputStreamWriter(headerOs),
512), true);
./core/MimeMessageWrapper.java:328:            PrintWriter pos = new
InternetPrintWriter(new BufferedWriter(new OutputStreamWriter(headerOs),
512), true);
./nntpserver/NNTPHandler.java:84:import
org.apache.james.util.InternetPrintWriter;
./nntpserver/NNTPHandler.java:376:            writer = new
InternetPrintWriter(new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()), 1024), true);
./pop3server/POP3Handler.java:85:import
org.apache.james.util.InternetPrintWriter;
./pop3server/POP3Handler.java:298:            out = new
InternetPrintWriter(outs, true);
./smtpserver/SMTPHandler.java:96:import
org.apache.james.util.InternetPrintWriter;
./smtpserver/SMTPHandler.java:389:            out = new
InternetPrintWriter(new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()), 1024), false);

I think it is fine to use Readers and Writers as long as they are used
consistently. An alternative to removing Reader/Writer usage and only using
streams would be to use either Reader/Writers without enforcing a
ByteToCharacter conversion or to explicitly specify the ByteToCharacter
conversion everywhere.

We don't seem to be specifying the conversion consistently. For instance
here is the grep on Reader.

./core/MailImpl.java:475:            br = new BufferedReader(new
InputStreamReader(message.getInputStream()));
./core/MimeMessageWrapper.java:500:            LineNumberReader counter =
new LineNumberReader(new InputStreamReader(in, getEncoding()));
./nntpserver/NNTPHandler.java:375:            reader = new
BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"),
1024);
./nntpserver/NNTPHandler.java:515:            doMODEREADER(argument);
./nntpserver/NNTPHandler.java:1269:    private void doMODEREADER(String
argument) {
./nntpserver/repository/NNTPArticleImpl.java:138:            reader = new
BufferedReader(new FileReader(articleFile));
./nntpserver/repository/NNTPArticleImpl.java:165:            BufferedReader
reader = new BufferedReader(new FileReader(articleFile));
./nntpserver/repository/NNTPArticleImpl.java:183:            BufferedReader
reader = new BufferedReader(new FileReader(articleFile));
./pop3server/POP3Handler.java:268:            in = new BufferedReader(new
InputStreamReader(socket.getInputStream(), "ASCII"), 512);
./remotemanager/RemoteManagerHandler.java:290:            in = new
BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"),
512);
./smtpserver/SMTPHandler.java:357:            inReader = new
BufferedReader(new InputStreamReader(in, "ASCII"), 512);

If replacing the Readers/Writers with Streams is right, I think we should at
least replace InternetPrintWriter with InternetPrintStream. Code conversion
to completely get rid of Readers and Writers may be significant and there
may not be a gain. There may be performance gain in replacing Reader/Writers
with streams but code does need to deal with lines and strings.

I favor leaving readers and writers as they are but removing the "ASCII"
encoding rule for conversion in James code or having a consitent character
conversion mechanism everywhere over removing Readers and Writers.

The way I see it bytes are input and output from James, to either network or
disk. Whatever byte to char conversion james uses is transient and is ok as
long as it is consistent.

If this is the right approach at least to fix in NNTP would be as suggested
be Stanislav Mironov in
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=james-user@jakarta.apach
e.org&msgNo=5445

Message has the patch flipped. Here is the patch from head
Index: NNTPHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/NNTPHandler.jav
a,v
retrieving revision 1.37
diff -u -r1.37 NNTPHandler.java
--- NNTPHandler.java 8 Mar 2003 21:14:04 -0000 1.37
+++ NNTPHandler.java 18 Mar 2003 03:01:44 -0000
@@ -372,7 +372,7 @@
             synchronized (this) {
                 handlerThread = Thread.currentThread();
             }
-            reader = new BufferedReader(new
InputStreamReader(socket.getInputStream(), "ASCII"), 1024);
+            reader = new BufferedReader(new
InputStreamReader(socket.getInputStream()), 1024);
             writer = new InternetPrintWriter(new BufferedWriter(new
OutputStreamWriter(socket.getOutputStream()), 1024), true);
         } catch (Exception e) {
             getLogger().error( "Cannot open connection from: " +
e.getMessage(), e );

There should be similar fixes in SMTPHandler and POP3Handler. Would be good
to remove "ASCII" in reading esp. as we don't specify that conversion
mechanism in Writing.

thoughts ???

Harmeet


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org


Mime
View raw message