NASA World Wind

gov.nasa.worldwind.cache
Class AbstractFileStore

java.lang.Object
  extended by gov.nasa.worldwind.cache.AbstractFileStore
All Implemented Interfaces:
FileStore
Direct Known Subclasses:
BasicDataFileStore

public class AbstractFileStore
extends Object
implements FileStore


Nested Class Summary
protected static class AbstractFileStore.StoreLocation
           
 
Field Summary
protected  List<AbstractFileStore.StoreLocation> readLocations
           
protected  AbstractFileStore.StoreLocation writeLocation
           
 
Fields inherited from interface gov.nasa.worldwind.cache.FileStore
OS_SPECIFIC_DATA_PATH
 
Constructor Summary
AbstractFileStore()
           
 
Method Summary
 void addLocation(int index, String newPath, boolean isInstall)
           
 void addLocation(String newPath, boolean isInstall)
           
protected static String appendPathPart(String firstPart, String secondPart)
           
protected static String buildLocationPath(String property, String append, String wwDir)
           
protected  void buildReadPaths(Node dataFileStoreNode)
           
protected  void buildWritePaths(Node dataFileCacheNode)
           
 boolean containsFile(String fileName)
           
protected static String determineAllUserLocation()
           
protected static String determineSingleUserLocation()
           
protected  void doFindDataDescriptors(AbstractFileStore.StoreLocation location, File dir, List<DataDescriptor> descriptors)
           
protected  void doListFileNames(AbstractFileStore.StoreLocation location, File dir, FileStoreFilter filter, boolean recurse, boolean exitBranchOnFirstMatch, Collection<String> names)
           
protected  String[] doListFileNames(String pathName, FileStoreFilter filter, boolean recurse, boolean exitBranchOnFirstMatch)
           
 List<? extends DataDescriptor> findAllDataDescriptors()
           
 List<? extends DataDescriptor> findDataDescriptors(String path)
           
 URL findFile(String fileName, boolean checkClassPath)
           
 List<? extends File> getLocations()
           
protected static String getUserHomeDir()
           
 File getWriteLocation()
           
protected  void initialize(InputStream xmlConfigStream)
           
 boolean isInstallLocation(String path)
           
 String[] listAllFileNames(String pathName, FileStoreFilter filter)
          Returns an array of strings naming the files discovered under a specified file store path name.
protected  boolean listFile(AbstractFileStore.StoreLocation location, File file, FileStoreFilter filter, Collection<String> names)
           
protected  boolean listFileName(AbstractFileStore.StoreLocation location, String fileName, FileStoreFilter filter, Collection<String> names)
           
 String[] listFileNames(String pathName, FileStoreFilter filter)
          Returns an array of strings naming the files discovered directly under a specified file store path name.
 String[] listTopFileNames(String pathName, FileStoreFilter filter)
          Returns an array of strings naming the files discovered under a specified file store path name.
protected static File makeAbsoluteFile(File file, String fileName)
           
protected static String makeAbsolutePath(File dir, String fileName)
           
protected static void markFileUsed(File file)
           
 File newFile(String fileName)
           
protected static String normalizeFileStoreName(String fileName)
           
protected static String propertyToPath(String propName)
           
protected  boolean readDataDescriptor(AbstractFileStore.StoreLocation location, File descriptorFile, List<DataDescriptor> descriptors)
           
 void removeFile(URL url)
           
 void removeLocation(String path)
           
protected  AbstractFileStore.StoreLocation storeLocationFor(String path)
           
protected static String storePathForFile(AbstractFileStore.StoreLocation location, File file)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

readLocations

protected final List<AbstractFileStore.StoreLocation> readLocations

writeLocation

protected AbstractFileStore.StoreLocation writeLocation
Constructor Detail

AbstractFileStore

public AbstractFileStore()
Method Detail

addLocation

public void addLocation(int index,
                        String newPath,
                        boolean isInstall)
Specified by:
addLocation in interface FileStore

addLocation

public void addLocation(String newPath,
                        boolean isInstall)
Specified by:
addLocation in interface FileStore

appendPathPart

protected static String appendPathPart(String firstPart,
                                       String secondPart)

buildLocationPath

protected static String buildLocationPath(String property,
                                          String append,
                                          String wwDir)

buildReadPaths

protected void buildReadPaths(Node dataFileStoreNode)

buildWritePaths

protected void buildWritePaths(Node dataFileCacheNode)

containsFile

public boolean containsFile(String fileName)
Specified by:
containsFile in interface FileStore

determineAllUserLocation

protected static String determineAllUserLocation()

determineSingleUserLocation

protected static String determineSingleUserLocation()

doFindDataDescriptors

protected void doFindDataDescriptors(AbstractFileStore.StoreLocation location,
                                     File dir,
                                     List<DataDescriptor> descriptors)

doListFileNames

protected void doListFileNames(AbstractFileStore.StoreLocation location,
                               File dir,
                               FileStoreFilter filter,
                               boolean recurse,
                               boolean exitBranchOnFirstMatch,
                               Collection<String> names)

doListFileNames

protected String[] doListFileNames(String pathName,
                                   FileStoreFilter filter,
                                   boolean recurse,
                                   boolean exitBranchOnFirstMatch)

findAllDataDescriptors

public List<? extends DataDescriptor> findAllDataDescriptors()
Specified by:
findAllDataDescriptors in interface FileStore

findDataDescriptors

public List<? extends DataDescriptor> findDataDescriptors(String path)
Specified by:
findDataDescriptors in interface FileStore

findFile

public URL findFile(String fileName,
                    boolean checkClassPath)
Specified by:
findFile in interface FileStore
Parameters:
fileName - the name of the file to find
checkClassPath - if true, the class path is first searched for the file, otherwise the class path is not searched unless it's one of the explicit paths in the cache search directories
Returns:
a handle to the requested file if it exists in the cache, otherwise null
Throws:
IllegalArgumentException - if fileName is null

getLocations

public List<? extends File> getLocations()
Specified by:
getLocations in interface FileStore

getUserHomeDir

protected static String getUserHomeDir()

getWriteLocation

public File getWriteLocation()
Specified by:
getWriteLocation in interface FileStore

initialize

protected void initialize(InputStream xmlConfigStream)

isInstallLocation

public boolean isInstallLocation(String path)
Specified by:
isInstallLocation in interface FileStore

listAllFileNames

public String[] listAllFileNames(String pathName,
                                 FileStoreFilter filter)
Description copied from interface: FileStore
Returns an array of strings naming the files discovered under a specified file store path name. If the path name is null, the entire file store will be searched. Otherwise the file store is recursively searched under the specified path name for files accepted by the specified filter, until the entire path tree is exhausted. This returns null if the path does not exist in the store. Returned names are relative pointers to a file in the store; they are not necessarily a file system path.

Specified by:
listAllFileNames in interface FileStore
Parameters:
pathName - relative path in the file store to search, or null to search the entire file store.
filter - a file filter.
Returns:
an array of file store names. Returns null if the path does not exist in the file store.

listFile

protected boolean listFile(AbstractFileStore.StoreLocation location,
                           File file,
                           FileStoreFilter filter,
                           Collection<String> names)

listFileName

protected boolean listFileName(AbstractFileStore.StoreLocation location,
                               String fileName,
                               FileStoreFilter filter,
                               Collection<String> names)

listFileNames

public String[] listFileNames(String pathName,
                              FileStoreFilter filter)
Description copied from interface: FileStore
Returns an array of strings naming the files discovered directly under a specified file store path name. If the path name is null, files under the store root are searched. This returns null if the path does not exist in the store. Returned names are relative pointers to a file in the store; they are not necessarily a file system path.

Specified by:
listFileNames in interface FileStore
Parameters:
pathName - relative path in the file store to search, or null to search the entire file store.
filter - a file filter.
Returns:
an array of file store names. Returns null if the path does not exist in the file store.

listTopFileNames

public String[] listTopFileNames(String pathName,
                                 FileStoreFilter filter)
Description copied from interface: FileStore
Returns an array of strings naming the files discovered under a specified file store path name. If the path name is null, the entire file store will be searched. Otherwise the file store is recursively searched under each branch of the the specified path name until a matching file is found, or that branch is exhausted. Unlinke FileStore.listAllFileNames(String, FileStoreFilter), This has the effect of locating the top file name under each branch. This returns null if the path does not exist in the store. Returned names are relative pointers to a file in the store; they are not necessarily a file system path.

Specified by:
listTopFileNames in interface FileStore
Parameters:
pathName - relative path in the file store to search, or null to search the entire file store.
filter - a file filter.
Returns:
an array of file store names. Returns null if the path does not exist in the file store.

makeAbsoluteFile

protected static File makeAbsoluteFile(File file,
                                       String fileName)

makeAbsolutePath

protected static String makeAbsolutePath(File dir,
                                         String fileName)

markFileUsed

protected static void markFileUsed(File file)

newFile

public File newFile(String fileName)
Specified by:
newFile in interface FileStore
Parameters:
fileName - the name to give the newly created file
Returns:
a handle to the newly created file if it could be created and added to the file store, otherwise null
Throws:
IllegalArgumentException - if fileName is null

normalizeFileStoreName

protected static String normalizeFileStoreName(String fileName)

propertyToPath

protected static String propertyToPath(String propName)

readDataDescriptor

protected boolean readDataDescriptor(AbstractFileStore.StoreLocation location,
                                     File descriptorFile,
                                     List<DataDescriptor> descriptors)

removeFile

public void removeFile(URL url)
Specified by:
removeFile in interface FileStore
Parameters:
url - the "file:" URL of the file to remove from the file store
Throws:
IllegalArgumentException - if url is null

removeLocation

public void removeLocation(String path)
Specified by:
removeLocation in interface FileStore

storeLocationFor

protected AbstractFileStore.StoreLocation storeLocationFor(String path)

storePathForFile

protected static String storePathForFile(AbstractFileStore.StoreLocation location,
                                         File file)

NASA World Wind