You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2001/09/28 04:22:27 UTC

cvs commit: jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources FileDirContext.java

remm        01/09/27 19:22:27

  Modified:    catalina/src/share/org/apache/naming/resources
                        FileDirContext.java
  Log:
  - Optimize the file dir context to use lazy loading. This should make the
    implementation very efficient, except on Windows where the case sensitivity checks
    probably kill performance anyway.
  
  Revision  Changes    Path
  1.8       +155 -15   jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/FileDirContext.java
  
  Index: FileDirContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/FileDirContext.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- FileDirContext.java	2001/08/16 00:57:18	1.7
  +++ FileDirContext.java	2001/09/28 02:22:27	1.8
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/FileDirContext.java,v 1.7 2001/08/16 00:57:18 craigmcc Exp $
  - * $Revision: 1.7 $
  - * $Date: 2001/08/16 00:57:18 $
  + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/naming/resources/FileDirContext.java,v 1.8 2001/09/28 02:22:27 remm Exp $
  + * $Revision: 1.8 $
  + * $Date: 2001/09/28 02:22:27 $
    *
    * ====================================================================
    *
  @@ -99,7 +99,7 @@
    * Filesystem Directory Context implementation helper class.
    *
    * @author Remy Maucherat
  - * @version $Revision: 1.7 $ $Date: 2001/08/16 00:57:18 $
  + * @version $Revision: 1.8 $ $Date: 2001/09/28 02:22:27 $
    */
   
   public class FileDirContext extends BaseDirContext {
  @@ -450,16 +450,7 @@
               throw new NamingException
                   (sm.getString("resources.notFound", name));
   
  -        // Return all the attributes all the time
  -        // FIXME
  -        ResourceAttributes attrs = new ResourceAttributes();
  -        attrs.setCreationDate(new Date(file.lastModified()));
  -        attrs.setName(file.getName());
  -        if (!file.isDirectory())
  -            attrs.setResourceType("");
  -        attrs.setContentLength(file.length());
  -        attrs.setLastModified(new Date(file.lastModified()));
  -        return attrs;
  +        return new FileResourceAttributes(file);
   
       }
   
  @@ -944,19 +935,168 @@
           // --------------------------------------------------- Member Variables
           
           
  +        /**
  +         * Associated file object.
  +         */
           protected File file;
           
           
           /**
  +         * File length.
  +         */
  +        protected long length = -1L;
  +        
  +        
  +        // --------------------------------------------------- Resource Methods
  +        
  +        
  +        /**
            * Content accessor.
            * 
            * @return InputStream
            */
           public InputStream streamContent()
               throws IOException {
  -            if (binaryContent == null)
  +            if (binaryContent == null) {
                   inputStream = new FileInputStream(file);
  +            }
               return super.streamContent();
  +        }
  +        
  +        
  +    }
  +
  +
  +    // ------------------------------------- FileResourceAttributes Inner Class
  +
  +
  +    /**
  +     * This specialized resource attribute implementation does some lazy 
  +     * reading (to speed up simple checks, like checking the last modified 
  +     * date).
  +     */
  +    protected class FileResourceAttributes extends ResourceAttributes {
  +
  +
  +        // -------------------------------------------------------- Constructor
  +
  +
  +        public FileResourceAttributes(File file) {
  +            this.file = file;
  +        }
  +        
  +        // --------------------------------------------------- Member Variables
  +        
  +        
  +        protected File file;
  +        
  +        
  +        protected boolean accessed = false;
  +        
  +        
  +        // ----------------------------------------- ResourceAttributes Methods
  +        
  +        
  +        /**
  +         * Is collection.
  +         */
  +        public boolean isCollection() {
  +            if (!accessed) {
  +                collection = file.isDirectory();
  +                accessed = true;
  +            }
  +            return super.isCollection();
  +        }
  +        
  +        
  +        /**
  +         * Get content length.
  +         * 
  +         * @return content length value
  +         */
  +        public long getContentLength() {
  +            if (contentLength != -1L)
  +                return contentLength;
  +            contentLength = file.length();
  +            return contentLength;
  +        }
  +        
  +        
  +        /**
  +         * Get creation time.
  +         * 
  +         * @return creation time value
  +         */
  +        public long getCreation() {
  +            if (creation != -1L)
  +                return creation;
  +            creation = file.lastModified();
  +            return creation;
  +        }
  +        
  +        
  +        /**
  +         * Get creation date.
  +         * 
  +         * @return Creation date value
  +         */
  +        public Date getCreationDate() {
  +            if (creation == -1L) {
  +                creation = file.lastModified();
  +            }
  +            return super.getCreationDate();
  +        }
  +        
  +        
  +        /**
  +         * Get last modified time.
  +         * 
  +         * @return lastModified time value
  +         */
  +        public long getLastModified() {
  +            if (lastModified != -1L)
  +                return lastModified;
  +            lastModified = file.lastModified();
  +            return lastModified;
  +        }
  +        
  +        
  +        /**
  +         * Get lastModified date.
  +         * 
  +         * @return LastModified date value
  +         */
  +        public Date getLastModifiedDate() {
  +            if (lastModified == -1L) {
  +                lastModified = file.lastModified();
  +            }
  +            return super.getLastModifiedDate();
  +        }
  +        
  +        
  +        /**
  +         * Get name.
  +         * 
  +         * @return Name value
  +         */
  +        public String getName() {
  +            if (name == null)
  +                name = file.getName();
  +            return name;
  +        }
  +        
  +        
  +        /**
  +         * Get resource type.
  +         * 
  +         * @return String resource type
  +         */
  +        public String getResourceType() {
  +            if (!accessed) {
  +                collection = file.isDirectory();
  +                accessed = true;
  +            }
  +            return super.getResourceType();
           }