Package org.apache.jena.util
Class FileManagerImpl
- java.lang.Object
-
- org.apache.jena.util.FileManagerImpl
-
- All Implemented Interfaces:
FileManager
public class FileManagerImpl extends java.lang.Object implements FileManager
FileManager A FileManager provides access to named file-like resources by opening InputStreams to things in the filing system, by URL (http: and file:) and found by the classloader. It can also load RDF data from such a system resource into an existing model or create a new (Memory-based) model. There is a global FileManager which provide uniform access to system resources: applications may also create specialised FileManagers. A FileManager contains a list of location functions to try: the global FileManger has oneLocatorFile
, oneLocatorClassLoader
and oneLocatorURL
Main operations: *- loadModel, readModel : URI to model
- open, openNoMap : URI to input stream
- mapURI : map URI to another by
LocationMapper
- readWholeFileAsUTF8
- optional caching of models
LocationMapper
is a set of alternative locations for system resources and a set of alternative prefix locations. For example, a local copy of a common RDF dataset may be used whenever the usual URL is used by the application. TheLocatorFile
also supports the idea of "current directory".- See Also:
LocationMapper
,FileUtils
-
-
Field Summary
-
Fields inherited from interface org.apache.jena.util.FileManager
filePathSeparator, logAllLookups, PATH_DELIMITER
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addCacheModel(java.lang.String uri, Model m)
void
addLocator(Locator loc)
Add a locator to the end of the locators listvoid
addLocatorClassLoader(java.lang.ClassLoader cLoad)
Deprecated.void
addLocatorFile()
Deprecated.void
addLocatorFile(java.lang.String dir)
Deprecated.void
addLocatorURL()
Deprecated.void
addLocatorZip(java.lang.String zfn)
Deprecated.FileManager
clone()
static FileManager
get()
Get the global file manager.Model
getFromCache(java.lang.String filenameOrURI)
Read out of the cache - return null if not in the cacheLocationMapper
getLocationMapper()
Get the location mappingboolean
hasCachedModel(java.lang.String filenameOrURI)
boolean
isCachingModels()
return whether caching is on of offModel
loadModel(java.lang.String filenameOrURI, java.lang.String rdfSyntax)
Load a model from a file (local or remote).Model
loadModel(java.lang.String filenameOrURI, java.lang.String baseURI, java.lang.String rdfSyntax)
Load a model from a file (local or remote).Model
loadModelInternal(java.lang.String filenameOrURI)
Load a model from a file (local or remote).java.util.Iterator<Locator>
locators()
Return an iterator over all the handlersstatic FileManager
makeGlobal()
Create a "standard" FileManager.java.lang.String
mapURI(java.lang.String filenameOrURI)
Apply the mapping of a filename or URIjava.io.InputStream
open(java.lang.String filenameOrURI)
Open a file using the locators of this FileManagerjava.io.InputStream
openNoMap(java.lang.String filenameOrURI)
Open a file using the locators of this FileManager but without location mappingTypedStream
openNoMapOrNull(java.lang.String filenameOrURI)
Open a file using the locators of this FileManager but without location mapping.Model
readModel(Model model, java.lang.String filenameOrURI, java.lang.String rdfSyntax)
Read a file of RDF into a model.Model
readModel(Model model, java.lang.String filenameOrURI, java.lang.String baseURI, java.lang.String syntax)
Read a file of RDF into a model.Model
readModelInternal(Model model, java.lang.String filenameOrURI)
Read a file of RDF into a model.java.lang.String
readWholeFileAsUTF8(java.io.InputStream in)
Slurp up a whole filejava.lang.String
readWholeFileAsUTF8(java.lang.String filename)
Slurp up a whole file: map filename as necessaryvoid
remove(Locator loc)
Remove a locatorvoid
removeCacheModel(java.lang.String uri)
void
resetCache()
Reset the model cachestatic void
setGlobalFileManager(FileManager globalFileManager)
Set the global file manager (as returned by get()) If called before any call to get(), then the usual default filemanager is not createdvoid
setLocationMapper(LocationMapper _mapper)
Set the location mappingvoid
setModelCaching(boolean state)
Change the state of model cache : does not clear the cache-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.jena.util.FileManager
loadModel, readModel
-
-
-
-
Method Detail
-
get
public static FileManager get()
Get the global file manager.- Returns:
- the global file manager
-
setGlobalFileManager
public static void setGlobalFileManager(FileManager globalFileManager)
Set the global file manager (as returned by get()) If called before any call to get(), then the usual default filemanager is not created- Parameters:
globalFileManager
-
-
clone
public FileManager clone()
- Specified by:
clone
in interfaceFileManager
-
makeGlobal
public static FileManager makeGlobal()
Create a "standard" FileManager.
-
setLocationMapper
public void setLocationMapper(LocationMapper _mapper)
Set the location mapping- Specified by:
setLocationMapper
in interfaceFileManager
-
getLocationMapper
public LocationMapper getLocationMapper()
Get the location mapping- Specified by:
getLocationMapper
in interfaceFileManager
-
locators
public java.util.Iterator<Locator> locators()
Return an iterator over all the handlers- Specified by:
locators
in interfaceFileManager
-
addLocator
public void addLocator(Locator loc)
Add a locator to the end of the locators list- Specified by:
addLocator
in interfaceFileManager
-
addLocatorFile
@Deprecated public void addLocatorFile()
Deprecated.Add a file locator- Specified by:
addLocatorFile
in interfaceFileManager
-
addLocatorFile
@Deprecated public void addLocatorFile(java.lang.String dir)
Deprecated.Add a file locator which uses dir as its working directory- Specified by:
addLocatorFile
in interfaceFileManager
-
addLocatorClassLoader
@Deprecated public void addLocatorClassLoader(java.lang.ClassLoader cLoad)
Deprecated.Add a class loader locator- Specified by:
addLocatorClassLoader
in interfaceFileManager
-
addLocatorURL
@Deprecated public void addLocatorURL()
Deprecated.Add a URL locator- Specified by:
addLocatorURL
in interfaceFileManager
-
addLocatorZip
@Deprecated public void addLocatorZip(java.lang.String zfn)
Deprecated.Add a zip file locator- Specified by:
addLocatorZip
in interfaceFileManager
-
remove
public void remove(Locator loc)
Remove a locator- Specified by:
remove
in interfaceFileManager
-
resetCache
public void resetCache()
Reset the model cache- Specified by:
resetCache
in interfaceFileManager
-
setModelCaching
public void setModelCaching(boolean state)
Change the state of model cache : does not clear the cache- Specified by:
setModelCaching
in interfaceFileManager
-
isCachingModels
public boolean isCachingModels()
return whether caching is on of off- Specified by:
isCachingModels
in interfaceFileManager
-
getFromCache
public Model getFromCache(java.lang.String filenameOrURI)
Read out of the cache - return null if not in the cache- Specified by:
getFromCache
in interfaceFileManager
-
hasCachedModel
public boolean hasCachedModel(java.lang.String filenameOrURI)
- Specified by:
hasCachedModel
in interfaceFileManager
-
addCacheModel
public void addCacheModel(java.lang.String uri, Model m)
- Specified by:
addCacheModel
in interfaceFileManager
-
removeCacheModel
public void removeCacheModel(java.lang.String uri)
- Specified by:
removeCacheModel
in interfaceFileManager
-
loadModelInternal
public Model loadModelInternal(java.lang.String filenameOrURI)
Load a model from a file (local or remote). This operation may attempt content negotiation for http URLs.- Specified by:
loadModelInternal
in interfaceFileManager
- Parameters:
filenameOrURI
- The filename or a URI (file:, http:)- Returns:
- a new model
- Throws:
JenaException
- if there is syntax error in file.
-
loadModel
public Model loadModel(java.lang.String filenameOrURI, java.lang.String rdfSyntax)
Load a model from a file (local or remote). URI is the base for reading the model.- Specified by:
loadModel
in interfaceFileManager
- Parameters:
filenameOrURI
- The filename or a URI (file:, http:)rdfSyntax
- RDF Serialization syntax.- Returns:
- a new model
- Throws:
JenaException
- if there is syntax error in file.
-
loadModel
public Model loadModel(java.lang.String filenameOrURI, java.lang.String baseURI, java.lang.String rdfSyntax)
Load a model from a file (local or remote).- Specified by:
loadModel
in interfaceFileManager
- Parameters:
filenameOrURI
- The filename or a URI (file:, http:)baseURI
- Base URI for loading the RDF model.rdfSyntax
- RDF Serialization syntax.- Returns:
- a new model
- Throws:
JenaException
- if there is syntax error in file.
-
readModelInternal
public Model readModelInternal(Model model, java.lang.String filenameOrURI)
Read a file of RDF into a model. Guesses the syntax of the file based on filename extension, defaulting to RDF/XML.- Specified by:
readModelInternal
in interfaceFileManager
- Parameters:
model
-filenameOrURI
-- Returns:
- The model or null, if there was an error.
- Throws:
JenaException
- if there is syntax error in file.
-
readModel
public Model readModel(Model model, java.lang.String filenameOrURI, java.lang.String rdfSyntax)
Read a file of RDF into a model.- Specified by:
readModel
in interfaceFileManager
- Parameters:
model
-filenameOrURI
-rdfSyntax
- RDF Serialization syntax.- Returns:
- The model or null, if there was an error.
- Throws:
JenaException
- if there is syntax error in file.
-
readModel
public Model readModel(Model model, java.lang.String filenameOrURI, java.lang.String baseURI, java.lang.String syntax)
Read a file of RDF into a model.- Specified by:
readModel
in interfaceFileManager
- Parameters:
model
-filenameOrURI
-baseURI
-syntax
-- Returns:
- The model
- Throws:
JenaException
- if there is syntax error in file.
-
open
public java.io.InputStream open(java.lang.String filenameOrURI)
Open a file using the locators of this FileManager- Specified by:
open
in interfaceFileManager
-
mapURI
public java.lang.String mapURI(java.lang.String filenameOrURI)
Apply the mapping of a filename or URI- Specified by:
mapURI
in interfaceFileManager
-
readWholeFileAsUTF8
public java.lang.String readWholeFileAsUTF8(java.io.InputStream in)
Slurp up a whole file- Specified by:
readWholeFileAsUTF8
in interfaceFileManager
-
readWholeFileAsUTF8
public java.lang.String readWholeFileAsUTF8(java.lang.String filename)
Slurp up a whole file: map filename as necessary- Specified by:
readWholeFileAsUTF8
in interfaceFileManager
-
openNoMap
public java.io.InputStream openNoMap(java.lang.String filenameOrURI)
Open a file using the locators of this FileManager but without location mapping- Specified by:
openNoMap
in interfaceFileManager
-
openNoMapOrNull
public TypedStream openNoMapOrNull(java.lang.String filenameOrURI)
Open a file using the locators of this FileManager but without location mapping. Return null if not found- Specified by:
openNoMapOrNull
in interfaceFileManager
-
-