You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/08/08 02:43:30 UTC

cvs commit: jakarta-james/src/java/org/apache/james/nntpserver/repository NNTPSpooler.java NNTPArticleImpl.java ArticleIDRepository.java

pgoldstein    2002/08/07 17:43:30

  Modified:    src/java/org/apache/james/nntpserver/repository
                        NNTPSpooler.java NNTPArticleImpl.java
                        ArticleIDRepository.java
  Log:
  Part of the String=>StringBuffer changes.  Includes some additional
  commenting, formatting fixes, and wrapping of logging calls in log
  level checks.  Also converted equalsIgnoreCase paradigm as discussed on
  mailing list.  Locale issue for both toUpperCase() and toLowerCase() was
  addressed as well.  Additionally, some finally clauses were added to ensure
  resources are closed in the case of exception.
  
  Revision  Changes    Path
  1.6       +7 -1      jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java
  
  Index: NNTPSpooler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPSpooler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NNTPSpooler.java	18 Jan 2002 02:48:36 -0000	1.5
  +++ NNTPSpooler.java	8 Aug 2002 00:43:29 -0000	1.6
  @@ -118,7 +118,13 @@
               }
           }
           private void process(File f) throws Exception {
  -            getLogger().debug("process: "+f.getAbsolutePath()+","+f.getCanonicalPath());
  +            StringBuffer logBuffer =
  +                new StringBuffer(160)
  +                        .append("process: ")
  +                        .append(f.getAbsolutePath())
  +                        .append(",")
  +                        .append(f.getCanonicalPath());
  +            getLogger().debug(logBuffer.toString());
               final MimeMessage msg;
               String articleID;
               {   // get the message for copying to destination groups.
  
  
  
  1.5       +23 -12    jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java
  
  Index: NNTPArticleImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/NNTPArticleImpl.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- NNTPArticleImpl.java	3 Jun 2002 16:07:06 -0000	1.4
  +++ NNTPArticleImpl.java	8 Aug 2002 00:43:29 -0000	1.5
  @@ -38,13 +38,24 @@
           } catch(Exception ex) { throw new NNTPException(ex); }
       }
       public void writeArticle(PrintWriter prt) {
  +        BufferedReader reader = null;
           try {
  -            BufferedReader reader = new BufferedReader(new FileReader(f));
  +            reader = new BufferedReader(new FileReader(f));
               String line = null;
  -            while ( ( line = reader.readLine() ) != null )
  +            while ( ( line = reader.readLine() ) != null ) {
                   prt.println(line);
  -            reader.close();
  -        } catch(IOException ex) { throw new NNTPException(ex); }
  +            }
  +        } catch(IOException ex) {
  +            throw new NNTPException(ex);
  +        } finally {
  +            try {
  +                if (reader != null) {
  +                    reader.close();
  +                }
  +            } catch (IOException ioe) {
  +                throw new NNTPException(ioe);
  +            }
  +        }
       }
       public void writeHead(PrintWriter prt) {
           try {
  @@ -86,14 +97,14 @@
               String references = hdr.getHeader("References",null);
               long byteCount = f.length();
               long lineCount = -1;
  -            prt.print(articleNumber+"\t");
  -            prt.print((subject==null?"":subject)+"\t");
  -            prt.print((author==null?"":author)+"\t");
  -            prt.print((date==null?"":date)+"\t");
  -            prt.print((msgId==null?"":msgId)+"\t");
  -            prt.print((references==null?"":references)+"\t");
  -            prt.print(byteCount+"\t");
  -            prt.println(lineCount+"");
  +            prt.print(articleNumber + "\t");
  +            prt.print((subject==null?"":subject) + "\t");
  +            prt.print((author==null?"":author) + "\t");
  +            prt.print((date==null?"":date) + "\t");
  +            prt.print((msgId==null?"":msgId) + "\t");
  +            prt.print((references==null?"":references) + "\t");
  +            prt.print(byteCount + "\t");
  +            prt.println(lineCount + "");
           } catch(Exception ex) { throw new NNTPException(ex); }
       }
       public String getHeader(String header) {
  
  
  
  1.6       +30 -9     jakarta-james/src/java/org/apache/james/nntpserver/repository/ArticleIDRepository.java
  
  Index: ArticleIDRepository.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/repository/ArticleIDRepository.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ArticleIDRepository.java	18 Jan 2002 02:48:36 -0000	1.5
  +++ ArticleIDRepository.java	8 Aug 2002 00:43:29 -0000	1.6
  @@ -45,18 +45,33 @@
   
       String generateArticleID() {
           int idx = Math.abs(counter++);
  -        String unique = Thread.currentThread().hashCode()+"."+
  -            System.currentTimeMillis()+"."+idx;
  -        return "<"+unique+"@"+articleIDDomainSuffix+">";
  +        StringBuffer idBuffer =
  +            new StringBuffer(256)
  +                    .append("<")
  +                    .append(Thread.currentThread().hashCode())
  +                    .append(".")
  +                    .append(System.currentTimeMillis())
  +                    .append(".")
  +                    .append(idx)
  +                    .append("@")
  +                    .append(articleIDDomainSuffix)
  +                    .append(">");
  +        return idBuffer.toString();
       }
   
       /** @param prop contains the newsgroup name and article number */
       void addArticle(String articleID,Properties prop) throws IOException {
           if ( articleID == null )
               articleID = generateArticleID();
  -        FileOutputStream fout = new FileOutputStream(getFileFromID(articleID));
  -        prop.store(fout,new Date().toString());
  -        fout.close();
  +        FileOutputStream fout = null;
  +        try {
  +            fout = new FileOutputStream(getFileFromID(articleID));
  +            prop.store(fout,new Date().toString());
  +        } finally {
  +            if (fout != null) {
  +                fout.close();
  +            }
  +        }
       }
   
       File getFileFromID(String articleID) {
  @@ -77,10 +92,16 @@
           File f = getFileFromID(id);
           if ( f.exists() == false )
               return null;
  -        FileInputStream fin = new FileInputStream(f);
  +        FileInputStream fin = null;
           Properties prop = new Properties();
  -        prop.load(fin);
  -        fin.close();
  +        try {
  +            fin = new FileInputStream(f);
  +            prop.load(fin);
  +        } finally {
  +            if (fin != null) {
  +                fin.close();
  +            }
  +        }
           Enumeration enum = prop.keys();
           NNTPArticle article = null;
           while ( article == null && enum.hasMoreElements() ) {
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>