01: /*
02: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: ResourceReader.java,v 1.7 2008/01/02 12:07:04 andy_seaborne Exp $
05: */
06:
07: /*
08: * ResourceReader.java
09: *
10: * Created on June 29, 2001, 9:54 PM
11: */
12:
13: package com.hp.hpl.jena.regression;
14:
15: import java.io.InputStream;
16: import java.io.FileInputStream;
17: import java.io.IOException;
18:
19: /**
20: * read a data file stored on the class path.
21: * To use this, ensure your data is on the class path (e.g. in the
22: * program jar, or in a separate data.jar), and give a relative path
23: * name to the data.
24: * Not intended for an applet environment.
25: *
26: * @author jjc
27: * @version Release='$Name: $' Revision='$Revision: 1.7 $' Date='$Date: 2008/01/02 12:07:04 $'
28: */
29: class ResourceReader {
30: // If false use FileInputSDtream's assuming we are in the correct directory;
31: static boolean useClassLoader = false;
32:
33: /** Creates new ResourceReader
34: * @param resource The filename of the data file relative to the Java classpath.
35: * @exception java.lang.SecurityException If cannot access the classloader, e.g. in applet.
36: * @exception java.lang.IllegalArgumentException If file not found.
37: */
38: private ResourceReader() {
39: }
40:
41: /*
42: public ResourceReader(String resource) throws IOException {
43: super(getInputStream(resource));
44: }
45: */
46:
47: static InputStream getInputStream(String prop) throws IOException {
48: if (useClassLoader) {
49: ClassLoader loader = ResourceReader.class.getClassLoader();
50: if (loader == null)
51: throw new SecurityException(
52: "Cannot access class loader");
53: InputStream in = loader.getResourceAsStream(prop);
54: if (in == null)
55: throw new IllegalArgumentException("Resource: " + prop
56: + " not found on class path.");
57: return in;
58: } else {
59: return new FileInputStream(prop);
60: }
61: }
62:
63: }
64:
65: /*
66: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
67: All rights reserved.
68:
69: Redistribution and use in source and binary forms, with or without
70: modification, are permitted provided that the following conditions
71: are met:
72:
73: 1. Redistributions of source code must retain the above copyright
74: notice, this list of conditions and the following disclaimer.
75:
76: 2. Redistributions in binary form must reproduce the above copyright
77: notice, this list of conditions and the following disclaimer in the
78: documentation and/or other materials provided with the distribution.
79:
80: 3. The name of the author may not be used to endorse or promote products
81: derived from this software without specific prior written permission.
82:
83: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
84: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
85: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
86: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
87: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
88: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
89: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
90: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
91: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
92: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
93: */
|