You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2004/06/15 21:26:21 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressedFile CompressedFileFileObject.java CompressedFileFileProvider.java CompressedFileFileSystem.java

imario      2004/06/15 12:26:21

  Added:       vfs/src/java/org/apache/commons/vfs/provider/compressedFile
                        CompressedFileFileObject.java
                        CompressedFileFileProvider.java
                        CompressedFileFileSystem.java
  Log:
  base for compressed files e.g. gzip, bzip2
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressedFile/CompressedFileFileObject.java
  
  Index: CompressedFileFileObject.java
  ===================================================================
  /*
   * Copyright 2002, 2003,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.commons.vfs.provider.compressedFile;
  
  import org.apache.commons.vfs.Capability;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileType;
  import org.apache.commons.vfs.provider.AbstractFileObject;
  
  /**
   * A compressedFile compressed file
   *
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/15 19:26:21 $
   */
  public abstract class CompressedFileFileObject
      extends AbstractFileObject
      implements FileObject
  {
      private final FileObject container;
      private String[] children;
  
      public CompressedFileFileObject(FileName name, FileObject container, CompressedFileFileSystem fs)
      {
          super(name, fs);
          this.container = container;
  
          // todo, add getBaseName(String) to FileName
          String basename = container.getName().getBaseName();
          int pos = basename.lastIndexOf('.');
          basename = basename.substring(0, pos);
  
          children = new String[]
          {
              basename
          };
      }
  
      /**
       * Returns true if this file is read-only.
       */
      public boolean isWriteable()
      {
          return getFileSystem().hasCapability(Capability.WRITE_CONTENT);
      }
  
      /**
       * Returns the file's type.
       */
      protected FileType doGetType() throws FileSystemException
      {
          return this.container.getType();
      }
  
      /**
       * Lists the children of the file.
       */
      protected String[] doListChildren()
      {
          return children;
      }
  
      /**
       * Returns the size of the file content (in bytes).  Is only called if
       * {@link #doGetType} returns {@link FileType#FILE}.
       */
      protected long doGetContentSize()
      {
          return -1;
      }
  
      /**
       * Returns the last modified time of this file.
       */
      protected long doGetLastModifiedTime() throws Exception
      {
          return container.getContent().getLastModifiedTime();
      }
  
      protected FileObject getContainer()
      {
          return container;
      }
  
      public void createFile() throws FileSystemException
      {
          container.createFile();
          injectType(FileType.FILE);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressedFile/CompressedFileFileProvider.java
  
  Index: CompressedFileFileProvider.java
  ===================================================================
  /*
   * Copyright 2002, 2003,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.commons.vfs.provider.compressedFile;
  
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystem;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileSystemOptions;
  import org.apache.commons.vfs.provider.AbstractLayeredFileProvider;
  import org.apache.commons.vfs.provider.FileProvider;
  import org.apache.commons.vfs.provider.zip.ZipFileName;
  
  import java.util.Collection;
  
  /**
   * A file system provider for compressedFile compressed files.  Provides read-only file
   * systems.
   *
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/15 19:26:21 $
   */
  public abstract class CompressedFileFileProvider
      extends AbstractLayeredFileProvider
      implements FileProvider
  {
      public CompressedFileFileProvider()
      {
          super();
      }
  
      /**
       * Parses an absolute URI.
       *
       * @param uri The URI to parse.
       */
      protected FileName parseUri(final String uri)
          throws FileSystemException
      {
          return ZipFileName.parseUri(uri);
      }
  
      /**
       * Creates a layered file system.  This method is called if the file system
       * is not cached.
       *
       * @param scheme The URI scheme.
       * @param file   The file to create the file system on top of.
       * @return The file system.
       */
      protected FileSystem doCreateFileSystem(final String scheme,
                                              final FileObject file,
                                              final FileSystemOptions fileSystemOptions)
          throws FileSystemException
      {
          final FileName name =
              new ZipFileName(scheme, file.getName().getURI(), FileName.ROOT_PATH);
          return createFileSystem(name, file, fileSystemOptions);
      }
  
      protected abstract FileSystem createFileSystem(final FileName name, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException;
  
      public abstract Collection getCapabilities();
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressedFile/CompressedFileFileSystem.java
  
  Index: CompressedFileFileSystem.java
  ===================================================================
  /*
   * Copyright 2002, 2003,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.commons.vfs.provider.compressedFile;
  
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystem;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileSystemOptions;
  import org.apache.commons.vfs.provider.AbstractFileSystem;
  
  import java.util.Collection;
  
  /**
   * A read-only file system for compressedFile files.
   *
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/15 19:26:21 $
   */
  public abstract class CompressedFileFileSystem
      extends AbstractFileSystem
      implements FileSystem
  {
      public CompressedFileFileSystem(final FileName rootName,
                                      final FileObject parentLayer,
                                      final FileSystemOptions fileSystemOptions)
          throws FileSystemException
      {
          super(rootName, parentLayer, fileSystemOptions);
      }
  
      public void init() throws FileSystemException
      {
          super.init();
  
      }
  
      /**
       * Returns the capabilities of this file system.
       */
      protected abstract void addCapabilities(final Collection caps);
  
      /**
       * Creates a file object.
       */
      protected abstract FileObject createFile(final FileName name) throws FileSystemException;
  }
  
  
  

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