KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > config > source > FileConfigSource


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.config.source;
18
19 import java.io.BufferedInputStream JavaDoc;
20 import java.io.FileInputStream JavaDoc;
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.List JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 /**
30  * ConfigSource implementation that gets its data via a file or files.
31  *
32  * @author gavinc
33  */

34 public class FileConfigSource extends BaseConfigSource
35 {
36     private static Log logger = LogFactory.getLog(FileConfigSource.class);
37     
38     /**
39      * Constructs a file configuration source that uses a single file
40      *
41      * @param filename the name of the file from which to get config
42      *
43      * @see FileConfigSource#FileConfigSource(List<String>)
44      */

45     public FileConfigSource(String JavaDoc filename)
46     {
47         this(Collections.singletonList(filename));
48     }
49     
50     /**
51      * @param sources
52      * List of file paths to get config from
53      */

54     public FileConfigSource(List JavaDoc<String JavaDoc> sourceStrings)
55     {
56         super(sourceStrings);
57     }
58
59     /**
60      * @param sourceString
61      * a valid filename as accepted by the
62      * {@link java.io.File#File(java.lang.String) file constructor}
63      * @return Returns a stream onto the file
64      */

65     protected InputStream JavaDoc getInputStream(String JavaDoc sourceString)
66     {
67         InputStream JavaDoc is = null;
68
69         try
70         {
71             is = new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(sourceString));
72         }
73         catch (IOException JavaDoc ioe)
74         {
75             if (logger.isDebugEnabled())
76             {
77                 logger.debug("Failed to obtain input stream to file: " + sourceString, ioe);
78             }
79         }
80
81         return is;
82     }
83 }
84
Popular Tags