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