public class ShpFiles extends Object
This class has methods for performing actions on the files. Currently mainly for obtaining read and write channels and streams. But in the future a move method may be introduced.
Note: The method that require locks (such as getInputStream()) will automatically acquire
locks and the javadocs should document how to release the lock. Therefore the methods acquireRead(ShpFileType, FileReader)
and acquireWrite(ShpFileType, FileWriter)
svn
Modifier and Type | Class and Description |
---|---|
static class |
ShpFiles.State |
Constructor and Description |
---|
ShpFiles(File file)
Searches for all the files and adds then to the map of files.
|
ShpFiles(String fileName)
Searches for all the files and adds then to the map of files.
|
ShpFiles(URL url)
Searches for all the files and adds then to the map of files.
|
Modifier and Type | Method and Description |
---|---|
URL |
acquireRead(ShpFileType type,
FileReader requestor)
Acquire a URL for read only purposes.
|
File |
acquireReadFile(ShpFileType type,
FileReader requestor)
Acquire a File for read only purposes.
|
URL |
acquireWrite(ShpFileType type,
FileWriter requestor)
Acquire a URL for read and write purposes.
|
File |
acquireWriteFile(ShpFileType type,
FileWriter requestor)
Acquire a File for read and write purposes.
|
boolean |
delete()
Delete all the shapefile files.
|
void |
dispose() |
boolean |
exists(ShpFileType fileType)
Returns true if the file exists.
|
protected void |
finalize()
This verifies that this class has been closed correctly (nothing locking)
|
String |
get(ShpFileType type)
Returns the string form of the url that identifies the file indicated by the type parameter
or null if it is known that the file does not exist.
|
Map<ShpFileType,String> |
getFileNames()
Returns the URLs (in string form) of all the files for the shapefile datastore.
|
InputStream |
getInputStream(ShpFileType type,
FileReader requestor)
Opens a input stream for the indicated file.
|
OutputStream |
getOutputStream(ShpFileType type,
FileWriter requestor)
Opens a output stream for the indicated file.
|
ReadableByteChannel |
getReadChannel(ShpFileType type,
FileReader requestor)
Obtain a ReadableByteChannel from the given URL.
|
StorageFile |
getStorageFile(ShpFileType type)
Obtains a Storage file for the type indicated.
|
String |
getTypeName() |
WritableByteChannel |
getWriteChannel(ShpFileType type,
FileWriter requestor)
Obtain a WritableByteChannel from the given URL.
|
boolean |
isLocal()
Determine if the location of this shapefile is local or remote.
|
boolean |
isMemoryMapCacheEnabled()
Returns the status of the memory map cache.
|
boolean |
isWritable()
Returns true if the files are writable
|
void |
logCurrentLockers(Level logLevel)
Writes to the log all the lockers and when they were constructed.
|
int |
numberOfLocks()
Returns the number of locks on the current set of shapefile files.
|
void |
setMemoryMapCacheEnabled(boolean memoryMapCacheEnabled)
Enables the memory map cache.
|
Result<URL,ShpFiles.State> |
tryAcquireRead(ShpFileType type,
FileReader requestor)
Tries to acquire a URL for read only purposes.
|
Result<URL,ShpFiles.State> |
tryAcquireWrite(ShpFileType type,
FileWriter requestor)
Tries to acquire a URL for read/write purposes.
|
void |
unlockRead(File file,
FileReader requestor)
Unlocks a read lock.
|
void |
unlockRead(URL url,
FileReader requestor)
Unlocks a read lock.
|
void |
unlockWrite(File file,
FileWriter requestor)
Unlocks a read lock.
|
void |
unlockWrite(URL url,
FileWriter requestor)
Unlocks a read lock.
|
public ShpFiles(String fileName) throws MalformedURLException
fileName
- the filename or url of any one of the shapefile filesMalformedURLException
- if it isn't possible to create a URL from string. It will be
used to create a file and create a URL from that if both fail this exception is thrownpublic ShpFiles(File file) throws MalformedURLException
file
- any one of the shapefile filesFileNotFoundException
- if the shapefile associated with file is not foundMalformedURLException
public ShpFiles(URL url) throws IllegalArgumentException
file
- any one of the shapefile filesIllegalArgumentException
protected void finalize() throws Throwable
public void dispose()
public void logCurrentLockers(Level logLevel)
logLevel
- the level at which to log.public Map<ShpFileType,String> getFileNames()
public String get(ShpFileType type)
Note: a URL should NOT be constructed from the string instead the URL should be obtained through calling one of the aquireLock methods.
type
- indicates the type of file the caller is interested in.public int numberOfLocks()
public File acquireReadFile(ShpFileType type, FileReader requestor)
type
- the type of the file desired.requestor
- the object that is requesting the File. The same object must release the
lock and is also used for debugging.getInputStream(ShpFileType, FileReader)
,
getReadChannel(ShpFileType, FileReader)
,
#getWriteChannel(ShpFileType, FileReader)
public URL acquireRead(ShpFileType type, FileReader requestor)
type
- the type of the file desired.requestor
- the object that is requesting the URL. The same object must release the lock
and is also used for debugging.getInputStream(ShpFileType, FileReader)
,
getReadChannel(ShpFileType, FileReader)
,
#getWriteChannel(ShpFileType, FileReader)
public Result<URL,ShpFiles.State> tryAcquireRead(ShpFileType type, FileReader requestor)
It is recommended that get*Stream or get*Channel methods are used when reading or writing to the file is desired.
type
- the type of the file desired.requestor
- the object that is requesting the URL. The same object must release the lock
and is also used for debugging.getInputStream(ShpFileType, FileReader)
,
getReadChannel(ShpFileType, FileReader)
,
#getWriteChannel(ShpFileType, FileReader)
public void unlockRead(File file, FileReader requestor)
file
- file that was lockedrequestor
- the class that requested the filepublic void unlockRead(URL url, FileReader requestor)
url
- url that was lockedrequestor
- the class that requested the urlpublic File acquireWriteFile(ShpFileType type, FileWriter requestor)
It is recommended that get*Stream or get*Channel methods are used when reading or writing to the file is desired.
type
- the type of the file desired.requestor
- the object that is requesting the File. The same object must release the
lock and is also used for debugging.getInputStream(ShpFileType, FileReader)
,
getReadChannel(ShpFileType, FileReader)
,
#getWriteChannel(ShpFileType, FileReader)
public URL acquireWrite(ShpFileType type, FileWriter requestor)
It is recommended that get*Stream or get*Channel methods are used when reading or writing to the file is desired.
type
- the type of the file desired.requestor
- the object that is requesting the URL. The same object must release the lock
and is also used for debugging.getInputStream(ShpFileType, FileReader)
,
getReadChannel(ShpFileType, FileReader)
,
#getWriteChannel(ShpFileType, FileReader)
public Result<URL,ShpFiles.State> tryAcquireWrite(ShpFileType type, FileWriter requestor)
It is recommended that get*Stream or get*Channel methods are used when reading or writing to the file is desired.
type
- the type of the file desired.requestor
- the object that is requesting the URL. The same object must release the lock
and is also used for debugging.getInputStream(ShpFileType, FileReader)
,
getReadChannel(ShpFileType, FileReader)
,
#getWriteChannel(ShpFileType, FileReader)
public void unlockWrite(File file, FileWriter requestor)
file
- file that was lockedrequestor
- the class that requested the filepublic void unlockWrite(URL url, FileWriter requestor)
url
- url that was lockedrequestor
- the class that requested the urlpublic boolean isLocal()
public boolean isWritable()
public boolean delete()
public InputStream getInputStream(ShpFileType type, FileReader requestor) throws IOException
type
- the type of file to open the stream to.requestor
- the object requesting the streamIOException
- if a problem occurred opening the stream.public OutputStream getOutputStream(ShpFileType type, FileWriter requestor) throws IOException
type
- the type of file to open the stream to.requestor
- the object requesting the streamIOException
- if a problem occurred opening the stream.public ReadableByteChannel getReadChannel(ShpFileType type, FileReader requestor) throws IOException
A read lock is obtained when this method is called and released when the channel is closed.
type
- the type of file to open the channel to.requestor
- the object requesting the channelIOException
public WritableByteChannel getWriteChannel(ShpFileType type, FileWriter requestor) throws IOException
A write lock is obtained when this method is called and released when the channel is closed.
type
- the type of file to open the stream to.requestor
- the object requesting the streamIOException
- if there is an error opening the streampublic StorageFile getStorageFile(ShpFileType type) throws IOException
type
- the type of file to create and returnIOException
- if temporary files cannot be createdpublic String getTypeName()
public boolean isMemoryMapCacheEnabled()
memoryMapCacheEnabled
- public void setMemoryMapCacheEnabled(boolean memoryMapCacheEnabled)
memoryMapCacheEnabled
- public boolean exists(ShpFileType fileType) throws IllegalArgumentException
fileType
- the type of file to check existance for.IllegalArgumentException
- if the files are not local.Copyright © 1996–2019 Geotools. All rights reserved.