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 */ 033public abstract class FileSystem 034{ 035 /** Constant for the default logger. */ 036 private static final ConfigurationLogger DEFAULT_LOG = ConfigurationLogger.newDummyLogger(); 037 038 /** The Logger */ 039 private volatile ConfigurationLogger log; 040 041 /** FileSystem options provider */ 042 private volatile FileOptionsProvider optionsProvider; 043 044 /** 045 * Returns the logger used by this FileSystem. 046 * 047 * @return the logger 048 */ 049 public ConfigurationLogger getLogger() 050 { 051 final ConfigurationLogger result = log; 052 return (result != null) ? result : DEFAULT_LOG; 053 } 054 055 /** 056 * Allows setting the logger to be used by this FileSystem. This 057 * method makes it possible for clients to exactly control logging behavior. 058 * Per default a logger is set that will ignore all log messages. Derived 059 * classes that want to enable logging should call this method during their 060 * initialization with the logger to be used. Passing in a <b>null</b> argument 061 * disables logging. 062 * 063 * @param log the new logger 064 */ 065 public void setLogger(final ConfigurationLogger log) 066 { 067 this.log = log; 068 } 069 070 /** 071 * Set the FileOptionsProvider 072 * @param provider The FileOptionsProvider 073 */ 074 public void setFileOptionsProvider(final FileOptionsProvider provider) 075 { 076 this.optionsProvider = provider; 077 } 078 079 public FileOptionsProvider getFileOptionsProvider() 080 { 081 return this.optionsProvider; 082 } 083 084 public abstract InputStream getInputStream(URL url) throws ConfigurationException; 085 086 public abstract OutputStream getOutputStream(URL url) throws ConfigurationException; 087 088 public abstract OutputStream getOutputStream(File file) throws ConfigurationException; 089 090 public abstract String getPath(File file, URL url, String basePath, String fileName); 091 092 public abstract String getBasePath(String path); 093 094 public abstract String getFileName(String path); 095 096 public abstract URL locateFromURL(String basePath, String fileName); 097 098 public abstract URL getURL(String basePath, String fileName) throws MalformedURLException; 099}