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