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/16 20:19:05 UTC

cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/gzip GzipFileObject.java GzipFileProvider.java GzipFileSystem.java

imario      2004/06/16 11:19:05

  Modified:    vfs/src/java/org/apache/commons/vfs/provider/compressed
                        CompressedFileFileObject.java
                        CompressedFileFileProvider.java
                        CompressedFileFileSystem.java
  Added:       vfs/src/java/org/apache/commons/vfs/provider/bzip2
                        Bzip2FileObject.java Bzip2FileProvider.java
                        Bzip2FileSystem.java
               vfs/src/java/org/apache/commons/vfs/provider/gzip
                        GzipFileObject.java GzipFileProvider.java
                        GzipFileSystem.java
  Log:
  handle gzip and bzip2 compressed files like a filesystem with only one child
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/bzip2/Bzip2FileObject.java
  
  Index: Bzip2FileObject.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.bzip2;
  
  import org.apache.commons.compress.bzip2.CBZip2OutputStream;
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.provider.compressed.CompressedFileFileObject;
  import org.apache.commons.vfs.provider.compressed.CompressedFileFileSystem;
  import org.apache.tools.bzip2.CBZip2InputStream;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  
  /**
   * the bzip2 file
   * 
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/16 18:19:05 $
   */
  public class Bzip2FileObject extends CompressedFileFileObject
  {
      public Bzip2FileObject(FileName name, FileObject container, CompressedFileFileSystem fs)
      {
          super(name, container, fs);
      }
  
      protected InputStream doGetInputStream() throws Exception
      {
          // check file
          InputStream is = getContainer().getContent().getInputStream();
          final int b1 = is.read();
          final int b2 = is.read();
          if (b1 != 'B' || b2 != 'Z')
          {
              throw new FileSystemException("vfs.provider.compressedFile/not-a-compressedFile-file.error", getName());
          }
          return new CBZip2InputStream(is);
      }
  
      protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
      {
          OutputStream os = getContainer().getContent().getOutputStream(false);
          os.write('B');
          os.write('Z');
  
          return new CBZip2OutputStream(os);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/bzip2/Bzip2FileProvider.java
  
  Index: Bzip2FileProvider.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.bzip2;
  
  import org.apache.commons.vfs.Capability;
  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.compressed.CompressedFileFileProvider;
  
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Collections;
  
  /**
   * Provides access to the content of bzip2 compressed files
   *
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/16 18:19:05 $
   */
  public class Bzip2FileProvider extends CompressedFileFileProvider
  {
      protected final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
      {
          Capability.GET_LAST_MODIFIED,
          Capability.GET_TYPE,
          Capability.LIST_CHILDREN,
          Capability.READ_CONTENT,
          Capability.WRITE_CONTENT,
          Capability.URI
      }));
  
      public Bzip2FileProvider()
      {
          super();
      }
  
      protected FileSystem createFileSystem(FileName name, FileObject file, FileSystemOptions fileSystemOptions) throws FileSystemException
      {
          return new Bzip2FileSystem(name, file, fileSystemOptions);
      }
  
      public Collection getCapabilities()
      {
          return capabilities;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/bzip2/Bzip2FileSystem.java
  
  Index: Bzip2FileSystem.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.bzip2;
  
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileSystemOptions;
  import org.apache.commons.vfs.provider.compressed.CompressedFileFileSystem;
  
  import java.util.Collection;
  
  /**
   * Filesytem to handle compressed files using the bzip2 method
   * 
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/16 18:19:05 $
   */
  public class Bzip2FileSystem extends CompressedFileFileSystem
  {
      public Bzip2FileSystem(FileName rootName, FileObject parentLayer, FileSystemOptions fileSystemOptions) throws FileSystemException
      {
          super(rootName, parentLayer, fileSystemOptions);
      }
  
      protected FileObject createFile(FileName name) throws FileSystemException
      {
          return new Bzip2FileObject(name, getParentLayer(), this);
      }
  
      protected void addCapabilities(final Collection caps)
      {
          caps.addAll(Bzip2FileProvider.capabilities);
      }
  }
  
  
  
  1.2       +3 -2      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressed/CompressedFileFileObject.java
  
  Index: CompressedFileFileObject.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressed/CompressedFileFileObject.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CompressedFileFileObject.java	16 Jun 2004 10:30:33 -0000	1.1
  +++ CompressedFileFileObject.java	16 Jun 2004 18:19:05 -0000	1.2
  @@ -23,7 +23,8 @@
   import org.apache.commons.vfs.provider.AbstractFileObject;
   
   /**
  - * A compressedFile compressed file
  + * A compressed file.<br>
  + * Such a file do only have one child (the compressed filename with stripped last extension)
    *
    * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
    * @version $Revision$ $Date$
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressed/CompressedFileFileProvider.java
  
  Index: CompressedFileFileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressed/CompressedFileFileProvider.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CompressedFileFileProvider.java	16 Jun 2004 10:30:33 -0000	1.1
  +++ CompressedFileFileProvider.java	16 Jun 2004 18:19:05 -0000	1.2
  @@ -27,7 +27,7 @@
   import java.util.Collection;
   
   /**
  - * A file system provider for compressedFile compressed files.  Provides read-only file
  + * A file system provider for compressed files.  Provides read-only file
    * systems.
    *
    * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressed/CompressedFileFileSystem.java
  
  Index: CompressedFileFileSystem.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/compressed/CompressedFileFileSystem.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CompressedFileFileSystem.java	16 Jun 2004 10:30:33 -0000	1.1
  +++ CompressedFileFileSystem.java	16 Jun 2004 18:19:05 -0000	1.2
  @@ -25,7 +25,7 @@
   import java.util.Collection;
   
   /**
  - * A read-only file system for compressedFile files.
  + * A read-only file system for compressed files.
    *
    * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
    * @version $Revision$ $Date$
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/gzip/GzipFileObject.java
  
  Index: GzipFileObject.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.gzip;
  
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.provider.compressed.CompressedFileFileObject;
  import org.apache.commons.vfs.provider.compressed.CompressedFileFileSystem;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.zip.GZIPInputStream;
  import java.util.zip.GZIPOutputStream;
  
  /**
   * the gzip file
   *
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/16 18:19:05 $
   */
  public class GzipFileObject extends CompressedFileFileObject
  {
      public GzipFileObject(FileName name, FileObject container, CompressedFileFileSystem fs)
      {
          super(name, container, fs);
      }
  
      protected InputStream doGetInputStream() throws Exception
      {
          InputStream is = getContainer().getContent().getInputStream();
          return new GZIPInputStream(is);
      }
  
      protected OutputStream doGetOutputStream(boolean bAppend) throws Exception
      {
          OutputStream os = getContainer().getContent().getOutputStream(false);
          return new GZIPOutputStream(os);
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/gzip/GzipFileProvider.java
  
  Index: GzipFileProvider.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.gzip;
  
  import org.apache.commons.vfs.Capability;
  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.compressed.CompressedFileFileProvider;
  
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Collections;
  
  /**
   * Provides access to the content of gzip compressed files
   *
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/16 18:19:05 $
   */
  public class GzipFileProvider extends CompressedFileFileProvider
  {
      protected final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
      {
          Capability.GET_LAST_MODIFIED,
          Capability.GET_TYPE,
          Capability.LIST_CHILDREN,
          Capability.WRITE_CONTENT,
          Capability.READ_CONTENT,
          Capability.URI
      }));
  
      public GzipFileProvider()
      {
          super();
      }
  
      protected FileSystem createFileSystem(FileName name, FileObject file, FileSystemOptions fileSystemOptions) throws FileSystemException
      {
          return new GzipFileSystem(name, file, fileSystemOptions);
      }
  
      public Collection getCapabilities()
      {
          return capabilities;
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/gzip/GzipFileSystem.java
  
  Index: GzipFileSystem.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.gzip;
  
  import org.apache.commons.vfs.FileName;
  import org.apache.commons.vfs.FileObject;
  import org.apache.commons.vfs.FileSystemException;
  import org.apache.commons.vfs.FileSystemOptions;
  import org.apache.commons.vfs.provider.compressed.CompressedFileFileSystem;
  
  import java.util.Collection;
  
  /**
   * Filesytem to handle compressed files using the gzip method
   * 
   * @author <a href="mailto:imario@apache.org">Mario Ivankovits</a>
   * @version $Revision: 1.1 $ $Date: 2004/06/16 18:19:05 $
   */
  public class GzipFileSystem extends CompressedFileFileSystem
  {
      public GzipFileSystem(FileName rootName, FileObject parentLayer, FileSystemOptions fileSystemOptions) throws FileSystemException
      {
          super(rootName, parentLayer, fileSystemOptions);
      }
  
      protected FileObject createFile(FileName name) throws FileSystemException
      {
          return new GzipFileObject(name, getParentLayer(), this);
      }
  
      protected void addCapabilities(final Collection caps)
      {
          caps.addAll(GzipFileProvider.capabilities);
      }
  }
  
  
  

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