    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.configuration2.io;
    018
    019import java.io.File;
    020import java.io.InputStream;
    021import java.io.OutputStream;
    022import java.net.MalformedURLException;
    023import java.net.URL;
    024
    025import org.apache.commons.configuration2.ex.ConfigurationException;
    026
    027/**
    028 * Abstract layer to allow various types of file systems.
    029 * @since 1.7
    030 * @author <a
    031 * href="http://commons.apache.org/configuration/team-list.html">Commons Configuration team</a>
    032 * @version $Id: FileSystem.java 1842194 2018-09-27 22:24:23Z ggregory $
    033 */
    034public abstract class FileSystem
    035{
    036    /** Constant for the default logger. */
    037    private static final ConfigurationLogger DEFAULT_LOG = ConfigurationLogger.newDummyLogger();
    038
    039    /** The Logger */
    040    private volatile ConfigurationLogger log;
    041
    042    /** FileSystem options provider */
    043    private volatile FileOptionsProvider optionsProvider;
    044
    045    /**
    046     * Returns the logger used by this FileSystem.
    047     *
    048     * @return the logger
    049     */
    050    public ConfigurationLogger getLogger()
    051    {
    052        final ConfigurationLogger result = log;
    053        return (result != null) ? result : DEFAULT_LOG;
    054    }
    055
    056    /**
    057     * Allows setting the logger to be used by this FileSystem. This
    058     * method makes it possible for clients to exactly control logging behavior.
    059     * Per default a logger is set that will ignore all log messages. Derived
    060     * classes that want to enable logging should call this method during their
    061     * initialization with the logger to be used. Passing in a <b>null</b> argument
    062     * disables logging.
    063     *
    064     * @param log the new logger
    065     */
    066    public void setLogger(final ConfigurationLogger log)
    067    {
    068        this.log = log;
    069    }
    070
    071    /**
    072     * Set the FileOptionsProvider
    073     * @param provider The FileOptionsProvider
    074     */
    075    public void setFileOptionsProvider(final FileOptionsProvider provider)
    076    {
    077        this.optionsProvider = provider;
    078    }
    079
    080    public FileOptionsProvider getFileOptionsProvider()
    081    {
    082        return this.optionsProvider;
    083    }
    084
    085    public abstract InputStream getInputStream(URL url) throws ConfigurationException;
    086
    087    public abstract OutputStream getOutputStream(URL url) throws ConfigurationException;
    088
    089    public abstract OutputStream getOutputStream(File file) throws ConfigurationException;
    090
    091    public abstract String getPath(File file, URL url, String basePath, String fileName);
    092
    093    public abstract String getBasePath(String path);
    094
    095    public abstract String getFileName(String path);
    096
    097    public abstract URL locateFromURL(String basePath, String fileName);
    098
    099    public abstract URL getURL(String basePath, String fileName) throws MalformedURLException;
    100}