@Named @Singleton public class DefaultFileManager extends Object implements FileManager
FileManager.ProgressListener
Constructor and Description |
---|
DefaultFileManager() |
Modifier and Type | Method and Description |
---|---|
void |
copy(File source,
File target) |
long |
copy(File source,
File target,
FileManager.ProgressListener listener)
Copy src- to target-file.
|
boolean |
mkdirs(File directory)
Null-safe variant of
File.mkdirs() . |
void |
move(File source,
File target) |
Lock |
readLock(File target)
Obtain a lock object that may be used to lock the target file for reading.
|
void |
write(File file,
InputStream source) |
void |
write(File file,
String data)
Write the given data to a file.
|
Lock |
writeLock(File target)
Obtain a lock object that may be used to lock the target file for writing.
|
public Lock readLock(File target)
FileManager
Lock.lock()
).readLock
in interface FileManager
target
- the file to lock, never null
.null
.public Lock writeLock(File target)
FileManager
Lock.lock()
).writeLock
in interface FileManager
target
- the file to lock, never null
.null
.public boolean mkdirs(File directory)
File.mkdirs()
.mkdirs
in interface FileManager
directory
- The directory to create, may be null
.true
if and only if the directory was created, along with all necessary parent
directories; false
otherwisepublic void copy(File source, File target) throws IOException
copy
in interface FileManager
IOException
public long copy(File source, File target, FileManager.ProgressListener listener) throws IOException
This method performs R/W-locking on the given files to provide concurrent access to files without data
corruption, and will honor FileLock
s from an external process.
copy
in interface FileManager
source
- the file to copy from, must not be null
.target
- the file to copy to, must not be null
.listener
- the listener to notify about the copy progress, may be null
.IOException
- if an I/O error occurs.public void write(File file, InputStream source) throws IOException
write
in interface FileManager
IOException
public void write(File file, String data) throws IOException
write
in interface FileManager
file
- The file to write to, must not be null
. This file will be truncated.data
- The data to write, may be null
.IOException
- if an I/O error occurs.public void move(File source, File target) throws IOException
move
in interface FileManager
IOException
Copyright © 2013–2017. All rights reserved.