hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Ideas for code clarity
Date Mon, 11 Jun 2007 07:40:04 GMT
On Sun, 2007-06-10 at 21:10 +0200, Daniel Mueller wrote:
> Hi all,
> 
> While scouting through the source code I stumbled across
> org.apache.http.conn.EofSensorInputStream. You have there three methods
> along the lines of:
> 
>      protected void checkEOF(int eof) throws IOException {
> 
>         if ((wrappedStream != null) && (eof < 0)) {
>             try {
>                 boolean scws = true; // should close wrapped stream?
>                 if (eofWatcher != null)
>                     scws = eofWatcher.eofDetected(wrappedStream);
>                 if (scws)
>                     wrappedStream.close();
>             } finally {
>                 wrappedStream = null;
>             }
>         }
>     }
> 
> This could be simplified by introducing:
> 
>     private static final EofSensorWatcher NULL_EOF_WATCHER = new
> EofSensorWatcher() {
>         public boolean eofDetected(InputStream wrapped) throws IOException {
>             return true;
>         }
> 
>         public boolean streamAbort(InputStream wrapped) throws IOException {
>             return true;
>         }
> 
>         public boolean streamClosed(InputStream wrapped) throws IOException
> {
>             return true;
>         }
>     };
> 
> which can be assigned in the constructor if there's no default
> EofSensorWatcher submitted. This changes the implementation to the
> following:
> 
>     protected void checkEOF(int eof) throws IOException {
> 
>         if ((wrappedStream != null) && (eof < 0)) {
>             try {
>                 if (eofWatcher.eofDetected(wrappedStream))
>                     wrappedStream.close();
>             } finally {
>                 wrappedStream = null;
>             }
>         }
>     }
> 
> which I think reads itself nicer. I avoid null checks in code when I can. I
> like NULL implementations much more.
> 
> Just some thoughts.
> 
> Cheers,
> Daniel

Hi Daniel,

The best way to go about things like that is to open a JIRA ticket and
attach a patch to it. Someone will eventually pick up the report and
will get back to you with some feedback. This particular piece of code
was initially written by Roland, so he should take a look at the
proposed changes.

Cheers

Oleg



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


Mime
View raw message