You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2004/08/05 20:26:19 UTC

cvs commit: jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util ChecksumHelper.java AbstractFileSystemHelper.java

taylor      2004/08/05 11:26:19

  Modified:    commons/src/java/org/apache/jetspeed/util
                        AbstractFileSystemHelper.java
  Added:       commons/src/java/org/apache/jetspeed/util
                        ChecksumHelper.java
  Log:
  refactored checksum into simple util
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.2       +20 -26    jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/AbstractFileSystemHelper.java
  
  Index: AbstractFileSystemHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/AbstractFileSystemHelper.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractFileSystemHelper.java	23 Jul 2004 02:43:31 -0000	1.1
  +++ AbstractFileSystemHelper.java	5 Aug 2004 18:26:19 -0000	1.2
  @@ -17,9 +17,9 @@
   
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.FileNotFoundException;
   import java.io.IOException;
  -import java.util.zip.Adler32;
  -import java.util.zip.CheckedInputStream;
  +import java.io.InputStream;
   
   
   /**
  @@ -39,34 +39,28 @@
           {
               return 0;
           }
  -        
  -        CheckedInputStream cis = null;        
  +                
           long checksum = 0;
  -        try 
  +        InputStream is = null;
  +        try
           {
  -            cis = new CheckedInputStream(new FileInputStream(child), new Adler32());
  -            byte[] tempBuf = new byte[128];
  -            while (cis.read(tempBuf) >= 0) 
  -            {
  -            }
  -            checksum = cis.getChecksum().getValue();
  -        } 
  -        catch (IOException e) 
  +            is = new FileInputStream(child);
  +            checksum = ChecksumHelper.getChecksum(is);
  +        }
  +        catch (FileNotFoundException e)
           {
  -            checksum = 0;
           }
  -        finally
  +        finally 
           {
  -            if (cis != null)
  -            {
  -                try
  -                {
  -                    cis.close();
  -                }
  -                catch (IOException ioe)
  -                {                    
  -                }
  -            }
  +             if (is != null)
  +             {
  +                 try
  +                 {
  +                     is.close();
  +                 }
  +                 catch (IOException io)
  +                 {}
  +             }
           }
           return checksum;
       }
  
  
  
  1.1                  jakarta-jetspeed-2/commons/src/java/org/apache/jetspeed/util/ChecksumHelper.java
  
  Index: ChecksumHelper.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed 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.jetspeed.util;
  
  import java.io.InputStream;
  import java.io.IOException;
  import java.util.zip.Adler32;
  import java.util.zip.CheckedInputStream;
  
  
  /**
   * implements checksum related utilities
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
   * @version $Id: ChecksumHelper.java,v 1.1 2004/08/05 18:26:19 taylor Exp $
   */
  public final class ChecksumHelper
  {
      public static long getChecksum(InputStream is)
      {
          CheckedInputStream cis = null;        
          long checksum = 0;
          try 
          {
              cis = new CheckedInputStream(is, new Adler32());
              byte[] tempBuf = new byte[128];
              while (cis.read(tempBuf) >= 0) 
              {
              }
              checksum = cis.getChecksum().getValue();
          } 
          catch (IOException e) 
          {
              checksum = 0;
          }
          finally
          {
              if (cis != null)
              {
                  try
                  {
                      cis.close();
                  }
                  catch (IOException ioe)
                  {                    
                  }
              }
          }
          return checksum;
      }
  }
          
  
  

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