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.ram;
18  
19  import org.apache.commons.vfs2.FileSystem;
20  import org.apache.commons.vfs2.FileSystemConfigBuilder;
21  import org.apache.commons.vfs2.FileSystemOptions;
22  
23  /**
24   * Config Builder for the RAM file system.
25   */
26  public final class RamFileSystemConfigBuilder extends FileSystemConfigBuilder {
27  
28      /** max size key. */
29      private static final String MAX_SIZE_KEY = "maxsize";
30  
31      /** config builder SINGLETON. */
32      private static final RamFileSystemConfigBuilderystemConfigBuilder.html#RamFileSystemConfigBuilder">RamFileSystemConfigBuilder SINGLETON = new RamFileSystemConfigBuilder();
33  
34      /**
35       * Constructor
36       */
37      private RamFileSystemConfigBuilder() {
38          super("ram.");
39      }
40  
41      /**
42       * Gets the singleton builder.
43       *
44       * @return the singleton builder.
45       */
46      public static RamFileSystemConfigBuilder getInstance() {
47          return SINGLETON;
48      }
49  
50      /**
51       * {@inheritDoc}
52       */
53      @Override
54      protected Class<? extends FileSystem> getConfigClass() {
55          return RamFileSystem.class;
56      }
57  
58      /**
59       * Defaults to {@link Integer#MAX_VALUE}.
60       *
61       * @param opts The FileSystem options.
62       * @return The maximum size of the file.
63       * @see #setMaxSize(FileSystemOptions, long)
64       * @since 2.1
65       */
66      public long getLongMaxSize(final FileSystemOptions opts) {
67          return getLong(opts, MAX_SIZE_KEY, Long.MAX_VALUE);
68      }
69  
70      /**
71       * Defaults to {@link Integer#MAX_VALUE}.
72       *
73       * @param opts The FileSystem options.
74       * @return The maximum size of the file. The next major version will change the return type to a long.
75       * @see #setMaxSize(FileSystemOptions, int)
76       */
77      public int getMaxSize(final FileSystemOptions opts) {
78          return getLong(opts, MAX_SIZE_KEY, Long.valueOf(Integer.MAX_VALUE)).intValue();
79      }
80  
81      /**
82       * Sets the maximum size of the file system.
83       *
84       * @param opts The FileSystem options.
85       * @param sizeInBytes The maximum file size.
86       * @deprecated Use {@link #setMaxSize(FileSystemOptions, long)}
87       */
88      @Deprecated
89      public void setMaxSize(final FileSystemOptions opts, final int sizeInBytes) {
90          setParam(opts, MAX_SIZE_KEY, Long.valueOf(sizeInBytes));
91      }
92  
93      /**
94       * Sets the maximum size of the file system.
95       *
96       * @param opts The FileSystem options.
97       * @param sizeInBytes The maximum file size.
98       */
99      public void setMaxSize(final FileSystemOptions opts, final long sizeInBytes) {
100         setParam(opts, MAX_SIZE_KEY, Long.valueOf(sizeInBytes));
101     }
102 
103 }