|
|
 |
|
Depends: |
log |
Related: |
n/a |
|
|
|
Description
The purpose of 'fs' service is to simplify different file system operations. This service includes
number of well-known and often practiced usage patterns for working with file system resources. Main functional
areas of this service include:
- Copying, moving, deleting files and directories.
-
Searching files with different search criteria’s, such as file filter, filename filter, filename
pattern using wildcard search (‘*’ and ‘?’ symbols), regular expression patterns, search in files
content, including SOUNDEX search.
-
Abilities to read and modify file permissions and attributes – ’read’, ’write’,
and ’execute’ permissions, ’archive’, ’system’, and ’hidden’,
attributes.
-
Special directories operation - cleaning directory, recursive directory 'touch', getting directory
size.
- Ability to get location of a class.
- Simplified abilities to read and write binary and character files.
-
Object/file tracking. File can be registered for tracking with some marker object. When marker
object is reclaimed by garbage collector, service performs special callback. User implementation of
callback interface may perform any operation with tracked file, for example delete file when object
which had used this file was garbage collected.
Top
Configuration
'fs' service does not have any configuration and therefore does not have associated XML configuration file.
Top
Examples
Usage of 'fs' service follows the standard pattern of using xTier service: you need to obtain
an instance of xTier kernel that serves as a service registry. Once you have xTier kernel you can get
an instance of any service, in our case the 'fs' service. Once the service instance is obtained
the service API can be used.
'fs' service has a long list of methods that can be functionally grouped as follows:
- File & directory copy/delete/move utilities.
- File & directory cleaning and other utilities.
- Path & filename utilities.
- File & file content search utilities.
- File & directory attributed utilities.
- Closing utilities.
- File/object tracking utilities.
- Input/output stream utilities.
- Miscellaneous utilities.
Following is an code snippet example of usage for 'fs' service demonstrates copying of test file:
| 1 |  | |
| 2 |  | FsService fs = XtierKernel.getInstance().fs(); |
| 3 |  | |
| 4 |  | File testDir = new File("testDir"); |
| 5 |  | |
| 6 |  | testDir.mkdirs(); |
| 7 |  | |
| 8 |  | File srcFile = new File(testDir, "testFile.txt"); |
| 9 |  | |
| 10 |  | |
| 11 |  | fs.writeStr2File(srcFile, "This is test file content.", |
| 12 |  | System.getProperty("file.encoding"), true); |
| 13 |  | |
| 14 |  | File destFile = new File(testDir, "testFile2.txt"); |
| 15 |  | |
| 16 |  | |
| 17 |  | fs.cp(srcFile, destFile, true); |
Download xTier for full examples and documentation.
Top
|