Class FileHandler
- java.lang.Object
-
- org.silverpeas.core.process.io.file.AbstractFileHandler
-
- org.silverpeas.core.process.io.file.FileHandler
-
public class FileHandler extends AbstractFileHandler
This is an handler that permits to perform transactional file manipulations. It has to be used exclusively in classes that implementsSilverpeasProcess
. In a standard use,getHandledFile
method has to be called to obtain aHandledFile
instance (@seeHandledFile
).- Author:
- Yohann Chastagnier
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
FileHandler(ProcessSession session)
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cleanDirectory(FileBasePath basePath, File directory)
protected boolean
contentEquals(File file1, FileBasePath basePath, File file2)
The first given file is not handled.protected boolean
contentEquals(FileBasePath basePath, File file1, File file2)
Both of given files are handledvoid
copyFile(File srcFile, HandledFile destFile)
The first given file is not handled.protected void
copyFile(FileBasePath basePath, File srcFile, File destFile)
Both of given files are handledprotected long
copyFile(FileBasePath basePath, File input, OutputStream output)
The given file is handledprotected void
copyFile(FileBasePath basePath, File srcFile, FileBasePath basePathDest, File destFile)
Both of given files are handledprotected void
copyInputStreamToFile(FileBasePath basePath, File file, InputStream inputStream, boolean append)
protected void
copyURLToFile(URL source, FileBasePath basePath, File destination)
The given file is handledprotected boolean
delete(FileBasePath basePath, File file)
protected boolean
exists(FileBasePath basePath, File file, String... names)
Indicates if the file exists in session or in real path.File
getFile(File file, String... names)
File
getFile(String... names)
HandledFile
getHandledFile(FileBasePath basePath, File file, String... names)
Gets the handled file that represents the file in session path if exists or if the file doesn't exist into destination path.HandledFile
getHandledFile(FileBasePath basePath, String... names)
Gets the handled file that represents the file in session path if exists or if the file doesn't exist into destination path.File
getSessionTemporaryFile(String... names)
Gets a temporary file contained in session path.protected boolean
isFileNewer(FileBasePath basePath, File file, long timeMillis)
protected boolean
isFileNewer(FileBasePath basePath, File file, File reference)
protected boolean
isFileNewer(FileBasePath basePath, File file, Date date)
protected boolean
isFileOlder(FileBasePath basePath, File file, long timeMillis)
protected boolean
isFileOlder(FileBasePath basePath, File file, File reference)
protected boolean
isFileOlder(FileBasePath basePath, File file, Date date)
protected Collection<File>
listFiles(FileBasePath basePath, File directory, boolean recursive, String... extensions)
protected Collection<File>
listFiles(FileBasePath basePath, File directory, String... extensions)
Adding this simple method based on listFiles from @see FileUtilsprotected Collection<File>
listFiles(FileBasePath basePath, File directory, org.apache.commons.io.filefilter.IOFileFilter fileFilter, org.apache.commons.io.filefilter.IOFileFilter dirFilter)
void
moveFile(File srcFile, HandledFile destFile)
The first given file is not handled.protected void
moveFile(FileBasePath basePath, File srcFile, File destFile)
Both of given files are handledprotected void
moveFile(FileBasePath basePath, File srcFile, FileBasePath baseDestPath, File destFile)
Both of given files are handledprotected InputStream
openInputStream(FileBasePath basePath, File file)
protected OutputStream
openOutputStream(FileBasePath basePath, File file)
protected OutputStream
openOutputStream(FileBasePath basePath, File file, boolean append)
protected byte[]
readFileToByteArray(FileBasePath basePath, File file)
protected String
readFileToString(FileBasePath basePath, File file)
protected String
readFileToString(FileBasePath basePath, File file, String encoding)
protected List<String>
readLines(FileBasePath basePath, File file)
protected List<String>
readLines(FileBasePath basePath, File file, String encoding)
protected long
sizeOf(FileBasePath basePath, File file)
protected long
sizeOfDirectory(FileBasePath basePath, File directory)
protected void
touch(FileBasePath basePath, File file, String... names)
protected boolean
waitFor(FileBasePath basePath, File file, int seconds)
protected void
write(FileBasePath basePath, File file, CharSequence data)
protected void
write(FileBasePath basePath, File file, CharSequence data, boolean append)
protected void
write(FileBasePath basePath, File file, CharSequence data, String encoding)
protected void
write(FileBasePath basePath, File file, CharSequence data, String encoding, boolean append)
protected void
writeByteArrayToFile(FileBasePath basePath, File file, byte[] data)
protected void
writeByteArrayToFile(FileBasePath basePath, File file, byte[] data, boolean append)
protected void
writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines)
protected void
writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines, boolean append)
protected void
writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines, String lineEnding)
protected void
writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines, String lineEnding, boolean append)
protected void
writeLines(FileBasePath basePath, File file, Collection<?> lines)
protected void
writeLines(FileBasePath basePath, File file, Collection<?> lines, boolean append)
protected void
writeLines(FileBasePath basePath, File file, Collection<?> lines, String lineEnding)
protected void
writeLines(FileBasePath basePath, File file, Collection<?> lines, String lineEnding, boolean append)
protected void
writeStringToFile(FileBasePath basePath, File file, String data)
protected void
writeStringToFile(FileBasePath basePath, File file, String data, boolean append)
protected void
writeStringToFile(FileBasePath basePath, File file, String data, String encoding)
protected void
writeStringToFile(FileBasePath basePath, File file, String data, String encoding, boolean append)
-
Methods inherited from class org.silverpeas.core.process.io.file.AbstractFileHandler
addDummyHandledFile, checkinSessionWorkingPath, deleteSessionWorkingPath, exists, getDummyHandledFiles, getExistingFile, getFileForWriting, getFileForWriting, getIoAccess, getSessionHandledRootPathNames, getSessionHandledRootPathNames, getSessionHandledRootPathNames, isHandledPath, isMarkedToDelete, listAllSessionHandledRootPathFiles, listAllSessionHandledRootPathFiles, markToDelete, removeDummyHandledFile, sizeOfSessionWorkingPath, sizeOfSessionWorkingPath, translateToRealPath, translateToSessionPath, verify, verify
-
-
-
-
Constructor Detail
-
FileHandler
protected FileHandler(ProcessSession session)
Default constructor- Parameters:
session
-
-
-
Method Detail
-
getSessionTemporaryFile
public File getSessionTemporaryFile(String... names)
Gets a temporary file contained in session path. This file exists during the transaction and is deleted after commit or rollback. Otherwise it represents the file from the destination path.
-
getHandledFile
public HandledFile getHandledFile(FileBasePath basePath, String... names)
Gets the handled file that represents the file in session path if exists or if the file doesn't exist into destination path. Otherwise it represents the file from the destination path.- Parameters:
basePath
-names
- relative path from basePath param
-
getHandledFile
public HandledFile getHandledFile(FileBasePath basePath, File file, String... names)
Gets the handled file that represents the file in session path if exists or if the file doesn't exist into destination path. Otherwise it represents the file from the destination path.- Parameters:
basePath
-file
- the file or path whose the start of file path is equals to the root file path defined by basePath paramnames
- relative path from basePath param
-
exists
protected boolean exists(FileBasePath basePath, File file, String... names)
Indicates if the file exists in session or in real path.- See Also:
FileUtils
-
openOutputStream
protected OutputStream openOutputStream(FileBasePath basePath, File file) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
openOutputStream
protected OutputStream openOutputStream(FileBasePath basePath, File file, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
openInputStream
protected InputStream openInputStream(FileBasePath basePath, File file) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
touch
protected void touch(FileBasePath basePath, File file, String... names) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
listFiles
protected Collection<File> listFiles(FileBasePath basePath, File directory, String... extensions)
Adding this simple method based on listFiles from @see FileUtils- Parameters:
basePath
-directory
-extensions
-- Returns:
-
listFiles
protected Collection<File> listFiles(FileBasePath basePath, File directory, boolean recursive, String... extensions)
- See Also:
FileUtils
-
listFiles
protected Collection<File> listFiles(FileBasePath basePath, File directory, org.apache.commons.io.filefilter.IOFileFilter fileFilter, org.apache.commons.io.filefilter.IOFileFilter dirFilter)
- See Also:
FileUtils
-
contentEquals
protected boolean contentEquals(FileBasePath basePath, File file1, File file2) throws Exception
Both of given files are handled- Throws:
Exception
- See Also:
FileUtils
-
contentEquals
protected boolean contentEquals(File file1, FileBasePath basePath, File file2) throws Exception
The first given file is not handled. It have to exist in an other path than the one that is handled. The second given file is handled. Both files are handled- Throws:
Exception
- See Also:
FileUtils
-
copyFile
protected void copyFile(FileBasePath basePath, File srcFile, File destFile) throws Exception
Both of given files are handled- Throws:
Exception
- See Also:
FileUtils
-
copyFile
protected void copyFile(FileBasePath basePath, File srcFile, FileBasePath basePathDest, File destFile) throws Exception
Both of given files are handled- Throws:
Exception
- See Also:
FileUtils
-
copyFile
public void copyFile(File srcFile, HandledFile destFile) throws Exception
The first given file is not handled. It have to exist in an other path than the one that is handled. The second given file is handled. Both files are handled- Throws:
Exception
- See Also:
FileUtils
-
copyFile
protected long copyFile(FileBasePath basePath, File input, OutputStream output) throws Exception
The given file is handled- Throws:
Exception
- See Also:
FileUtils
-
copyURLToFile
protected void copyURLToFile(URL source, FileBasePath basePath, File destination) throws Exception
The given file is handled- Throws:
Exception
- See Also:
FileUtils
-
delete
protected boolean delete(FileBasePath basePath, File file) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
cleanDirectory
protected void cleanDirectory(FileBasePath basePath, File directory) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
waitFor
protected boolean waitFor(FileBasePath basePath, File file, int seconds)
- See Also:
FileUtils
-
readFileToString
protected String readFileToString(FileBasePath basePath, File file) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
readFileToString
protected String readFileToString(FileBasePath basePath, File file, String encoding) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
readFileToByteArray
protected byte[] readFileToByteArray(FileBasePath basePath, File file) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
readLines
protected List<String> readLines(FileBasePath basePath, File file) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
readLines
protected List<String> readLines(FileBasePath basePath, File file, String encoding) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeStringToFile
protected void writeStringToFile(FileBasePath basePath, File file, String data) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeStringToFile
protected void writeStringToFile(FileBasePath basePath, File file, String data, String encoding) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeStringToFile
protected void writeStringToFile(FileBasePath basePath, File file, String data, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeStringToFile
protected void writeStringToFile(FileBasePath basePath, File file, String data, String encoding, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
write
protected void write(FileBasePath basePath, File file, CharSequence data) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
write
protected void write(FileBasePath basePath, File file, CharSequence data, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
write
protected void write(FileBasePath basePath, File file, CharSequence data, String encoding) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
write
protected void write(FileBasePath basePath, File file, CharSequence data, String encoding, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeByteArrayToFile
protected void writeByteArrayToFile(FileBasePath basePath, File file, byte[] data) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeByteArrayToFile
protected void writeByteArrayToFile(FileBasePath basePath, File file, byte[] data, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
copyInputStreamToFile
protected void copyInputStreamToFile(FileBasePath basePath, File file, InputStream inputStream, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, Collection<?> lines) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, Collection<?> lines, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, Collection<?> lines, String lineEnding) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, Collection<?> lines, String lineEnding, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines, String lineEnding) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
writeLines
protected void writeLines(FileBasePath basePath, File file, String encoding, Collection<?> lines, String lineEnding, boolean append) throws Exception
- Throws:
Exception
- See Also:
FileUtils
-
moveFile
public void moveFile(File srcFile, HandledFile destFile) throws Exception
The first given file is not handled. It have to exist in an other path than the one that is handled. The second given file is handled. Both files are handled- Throws:
Exception
- See Also:
FileUtils
-
moveFile
protected void moveFile(FileBasePath basePath, File srcFile, File destFile) throws Exception
Both of given files are handled- Throws:
Exception
- See Also:
FileUtils
-
moveFile
protected void moveFile(FileBasePath basePath, File srcFile, FileBasePath baseDestPath, File destFile) throws Exception
Both of given files are handled- Throws:
Exception
- See Also:
FileUtils
-
sizeOf
protected long sizeOf(FileBasePath basePath, File file)
- See Also:
FileUtils
-
sizeOfDirectory
protected long sizeOfDirectory(FileBasePath basePath, File directory)
- See Also:
FileUtils
-
isFileNewer
protected boolean isFileNewer(FileBasePath basePath, File file, File reference)
- See Also:
FileUtils
-
isFileNewer
protected boolean isFileNewer(FileBasePath basePath, File file, Date date)
- See Also:
FileUtils
-
isFileNewer
protected boolean isFileNewer(FileBasePath basePath, File file, long timeMillis)
- See Also:
FileUtils
-
isFileOlder
protected boolean isFileOlder(FileBasePath basePath, File file, File reference)
- See Also:
FileUtils
-
isFileOlder
protected boolean isFileOlder(FileBasePath basePath, File file, Date date)
- See Also:
FileUtils
-
isFileOlder
protected boolean isFileOlder(FileBasePath basePath, File file, long timeMillis)
- See Also:
FileUtils
-
-