View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider.zip;
18  
19  import java.util.Arrays;
20  import java.util.Collection;
21  import java.util.Collections;
22  
23  import org.apache.commons.vfs2.Capability;
24  import org.apache.commons.vfs2.FileName;
25  import org.apache.commons.vfs2.FileObject;
26  import org.apache.commons.vfs2.FileSystem;
27  import org.apache.commons.vfs2.FileSystemConfigBuilder;
28  import org.apache.commons.vfs2.FileSystemException;
29  import org.apache.commons.vfs2.FileSystemOptions;
30  import org.apache.commons.vfs2.FileType;
31  import org.apache.commons.vfs2.provider.AbstractFileName;
32  import org.apache.commons.vfs2.provider.AbstractLayeredFileProvider;
33  import org.apache.commons.vfs2.provider.LayeredFileName;
34  import org.apache.commons.vfs2.provider.hdfs.HdfsFileSystemConfigBuilder;
35  
36  /**
37   * A file system provider for ZIP files. Provides read-only file systems.
38   */
39  public class ZipFileProvider extends AbstractLayeredFileProvider {
40  
41      /** The list of capabilities this provider supports */
42      protected static final Collection<Capability> capabilities = Collections.unmodifiableCollection(Arrays
43              .asList(new Capability[] { Capability.GET_LAST_MODIFIED, Capability.GET_TYPE, Capability.LIST_CHILDREN,
44                      Capability.READ_CONTENT, Capability.URI, Capability.COMPRESS, Capability.VIRTUAL }));
45  
46      public ZipFileProvider() {
47          super();
48      }
49  
50      /**
51       * Creates a layered file system. This method is called if the file system is
52       * not cached.
53       *
54       * @param scheme The URI scheme.
55       * @param file   The file to create the file system on top of.
56       * @return The file system.
57       */
58      @Override
59      protected FileSystem doCreateFileSystem(final String scheme, final FileObject file,
60              final FileSystemOptions fileSystemOptions) throws FileSystemException {
61          final AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH,
62                  FileType.FOLDER);
63          return new ZipFileSystem(rootName, file, fileSystemOptions);
64      }
65  
66      @Override
67      public Collection<Capability> getCapabilities() {
68          return capabilities;
69      }
70  
71      /**
72       * Return config builder.
73       *
74       * @return A config builder for ZipFileProvider.
75       * @see org.apache.commons.vfs2.provider.AbstractFileProvider#getConfigBuilder()
76       */
77      @Override
78      public FileSystemConfigBuilder getConfigBuilder() {
79          return ZipFileSystemConfigBuilder.getInstance();
80      }
81  }