001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.provider.ram;
018
019import org.apache.commons.vfs2.FileSystem;
020import org.apache.commons.vfs2.FileSystemConfigBuilder;
021import org.apache.commons.vfs2.FileSystemOptions;
022
023/**
024 * Config Builder for the RAM file system.
025 */
026public final class RamFileSystemConfigBuilder extends FileSystemConfigBuilder {
027
028    /** Max size key. */
029    private static final String MAX_SIZE_KEY = "maxsize";
030
031    /** Config builder SINGLETON. */
032    private static final RamFileSystemConfigBuilder SINGLETON = new RamFileSystemConfigBuilder();
033
034    /**
035     * Gets the singleton builder.
036     *
037     * @return the singleton builder.
038     */
039    public static RamFileSystemConfigBuilder getInstance() {
040        return SINGLETON;
041    }
042
043    /**
044     * Constructor
045     */
046    private RamFileSystemConfigBuilder() {
047        super("ram.");
048    }
049
050    /**
051     * {@inheritDoc}
052     */
053    @Override
054    protected Class<? extends FileSystem> getConfigClass() {
055        return RamFileSystem.class;
056    }
057
058    /**
059     * Defaults to {@link Integer#MAX_VALUE}.
060     *
061     * @param opts The FileSystem options.
062     * @return The maximum size of the file.
063     * @see #setMaxSize(FileSystemOptions, long)
064     * @since 2.1
065     */
066    public long getLongMaxSize(final FileSystemOptions opts) {
067        return getLong(opts, MAX_SIZE_KEY, Long.MAX_VALUE);
068    }
069
070    /**
071     * Defaults to {@link Integer#MAX_VALUE}.
072     *
073     * @param opts The FileSystem options.
074     * @return The maximum size of the file. The next major version will change the return type to a long.
075     * @see #setMaxSize(FileSystemOptions, int)
076     */
077    public int getMaxSize(final FileSystemOptions opts) {
078        return getLong(opts, MAX_SIZE_KEY, Long.valueOf(Integer.MAX_VALUE)).intValue();
079    }
080
081    /**
082     * Sets the maximum size of the file system.
083     *
084     * @param opts The FileSystem options.
085     * @param sizeInBytes The maximum file size.
086     * @deprecated Use {@link #setMaxSize(FileSystemOptions, long)}
087     */
088    @Deprecated
089    public void setMaxSize(final FileSystemOptions opts, final int sizeInBytes) {
090        setParam(opts, MAX_SIZE_KEY, Long.valueOf(sizeInBytes));
091    }
092
093    /**
094     * Sets the maximum size of the file system.
095     *
096     * @param opts The FileSystem options.
097     * @param sizeInBytes The maximum file size.
098     */
099    public void setMaxSize(final FileSystemOptions opts, final long sizeInBytes) {
100        setParam(opts, MAX_SIZE_KEY, Long.valueOf(sizeInBytes));
101    }
102
103}