Class AbstractFileHandler
- java.lang.Object
-
- org.silverpeas.core.process.io.file.AbstractFileHandler
-
- Direct Known Subclasses:
FileHandler
public abstract class AbstractFileHandler extends Object
Bases of file handler functionnalities whose a lot of these are protected and only usable by extended classes and byProcessManagement
services (@seeProcessManagement
). This class contains the transactionnal mechanism of file system manipulations.- Author:
- Yohann Chastagnier
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractFileHandler(ProcessSession session)
Default constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDummyHandledFile(DummyHandledFile dummyHandledFile)
Add a dummy file.protected void
checkinSessionWorkingPath()
Checkin session pathprotected void
deleteSessionWorkingPath()
Delete session pathprotected static boolean
exists(File file)
Verify if the given file existsSet<DummyHandledFile>
getDummyHandledFiles(String componentInstanceId)
Gets the dummy handled files from a given component instance id.protected File
getExistingFile(FileBasePath basePath, File file)
If the given file doesn't exist in session path, then the file existing in real path is returned.protected File
getFileForWriting(FileBasePath basePath, File file)
If the given file doesn't exist in session path, then the file existing in real path is returned.protected File
getFileForWriting(FileBasePath basePath, File file, boolean append)
If the given file doesn't exist in session path, then the file existing in real path is returned.IOAccess
getIoAccess()
Collection<String>
getSessionHandledRootPathNames()
Gets handled root directories from the session.Collection<String>
getSessionHandledRootPathNames(boolean skipDeleted)
Gets handled root directories from the session.protected Collection<String>
getSessionHandledRootPathNames(FileBasePath basePath, boolean skipDeleted)
Gets handled root directories of a base path from the session.protected boolean
isHandledPath(FileBasePath basePath)
Indicates if the given path is handled or notprotected boolean
isMarkedToDelete(FileBasePath basePath, File file)
Indicates if the file will be deletedCollection<File>
listAllSessionHandledRootPathFiles()
Gets handled root directory Files of a base path from the session.protected Collection<File>
listAllSessionHandledRootPathFiles(FileBasePath basePath)
Gets handled root directory Files of a base path from the session.protected boolean
markToDelete(FileBasePath basePath, File file)
Mark the given file to be deleted.void
removeDummyHandledFile(DummyHandledFile dummyHandledFile)
Remove a dummy file.long
sizeOfSessionWorkingPath(String... relativeRootPath)
This method calculates the size of files contained in the given relative root path from the session and subtracts from the previous result the size of files marked to be deleted.protected long
sizeOfSessionWorkingPath(FileBasePath basePath, String... relativeRootPath)
This method calculates the size of files contained in the given relative root path from the session and subtracts from the previous result the size of files marked to be deleted.protected File
translateToRealPath(FileBasePath basePath, File file)
Translate to real.protected File
translateToSessionPath(FileBasePath basePath, File file)
Translate to session path.protected void
verify(FileBasePath basePath, File file)
Verify the integrity between handled path and fileprotected void
verify(FileBasePath basePath, File file, boolean isReadOnly)
Verify the integrity between handled path and file
-
-
-
Constructor Detail
-
AbstractFileHandler
protected AbstractFileHandler(ProcessSession session)
Default constructor- Parameters:
session
-
-
-
Method Detail
-
markToDelete
protected boolean markToDelete(FileBasePath basePath, File file) throws Exception
Mark the given file to be deleted.- Parameters:
basePath
-file
-- Returns:
- true if the file exists and when it is the first time that it is registred to be deleted
- Throws:
Exception
-
isMarkedToDelete
protected boolean isMarkedToDelete(FileBasePath basePath, File file)
Indicates if the file will be deleted- Parameters:
basePath
-file
-- Returns:
-
translateToRealPath
protected File translateToRealPath(FileBasePath basePath, File file)
Translate to real. Attention please : verify has to be called before.- Parameters:
basePath
-file
-- Returns:
-
translateToSessionPath
protected File translateToSessionPath(FileBasePath basePath, File file)
Translate to session path. Attention please : verify has to be called before.- Parameters:
basePath
-file
-- Returns:
-
getExistingFile
protected File getExistingFile(FileBasePath basePath, File file)
If the given file doesn't exist in session path, then the file existing in real path is returned. If the given file doesn't exist in real path, then the new session file is returned.- Parameters:
basePath
-file
-- Returns:
-
getFileForWriting
protected File getFileForWriting(FileBasePath basePath, File file) throws Exception
If the given file doesn't exist in session path, then the file existing in real path is returned. If the given file doesn't exist in real path, then the new session file is returned.- Parameters:
basePath
-file
-- Returns:
- Throws:
Exception
-
getFileForWriting
protected File getFileForWriting(FileBasePath basePath, File file, boolean append) throws Exception
If the given file doesn't exist in session path, then the file existing in real path is returned. If the given file doesn't exist in real path, then the new session file is returned.- Parameters:
basePath
-file
-append
-- Returns:
- Throws:
Exception
-
sizeOfSessionWorkingPath
public long sizeOfSessionWorkingPath(String... relativeRootPath)
This method calculates the size of files contained in the given relative root path from the session and subtracts from the previous result the size of files marked to be deleted. Dummy handled files are included (according to relativeRootPath that is normally a list of component instance ids).
-
sizeOfSessionWorkingPath
protected long sizeOfSessionWorkingPath(FileBasePath basePath, String... relativeRootPath)
This method calculates the size of files contained in the given relative root path from the session and subtracts from the previous result the size of files marked to be deleted.
-
getSessionHandledRootPathNames
public Collection<String> getSessionHandledRootPathNames()
Gets handled root directories from the session. (reads, writes, deletes)- Returns:
-
getSessionHandledRootPathNames
public Collection<String> getSessionHandledRootPathNames(boolean skipDeleted)
Gets handled root directories from the session. (reads, writes, deletes) The result contains root directories of dummy handled files.- Parameters:
skipDeleted
-- Returns:
-
getSessionHandledRootPathNames
protected Collection<String> getSessionHandledRootPathNames(FileBasePath basePath, boolean skipDeleted)
Gets handled root directories of a base path from the session. (reads, writes, deletes)- Parameters:
basePath
-skipDeleted
-- Returns:
-
listAllSessionHandledRootPathFiles
public Collection<File> listAllSessionHandledRootPathFiles()
Gets handled root directory Files of a base path from the session. (reads, writes)- Returns:
-
listAllSessionHandledRootPathFiles
protected Collection<File> listAllSessionHandledRootPathFiles(FileBasePath basePath)
Gets handled root directory Files of a base path from the session. (reads, writes)- Parameters:
basePath
-- Returns:
-
deleteSessionWorkingPath
protected void deleteSessionWorkingPath()
Delete session path
-
checkinSessionWorkingPath
protected void checkinSessionWorkingPath() throws Exception
Checkin session path- Throws:
Exception
-
verify
protected void verify(FileBasePath basePath, File file)
Verify the integrity between handled path and file- Parameters:
basePath
-file
-
-
verify
protected void verify(FileBasePath basePath, File file, boolean isReadOnly)
Verify the integrity between handled path and file- Parameters:
basePath
-file
-isReadOnly
-
-
exists
protected static boolean exists(File file)
Verify if the given file exists- Parameters:
file
-- Returns:
-
isHandledPath
protected boolean isHandledPath(FileBasePath basePath)
Indicates if the given path is handled or not- Parameters:
basePath
-- Returns:
-
getIoAccess
public IOAccess getIoAccess()
- Returns:
- the ioAccess
-
addDummyHandledFile
public void addDummyHandledFile(DummyHandledFile dummyHandledFile)
Add a dummy file. It can be useful for process check operations.- Parameters:
dummyHandledFile
-
-
removeDummyHandledFile
public void removeDummyHandledFile(DummyHandledFile dummyHandledFile)
Remove a dummy file. It can be useful for process check operations.- Parameters:
dummyHandledFile
-
-
getDummyHandledFiles
public Set<DummyHandledFile> getDummyHandledFiles(String componentInstanceId)
Gets the dummy handled files from a given component instance id. A component instance id can be see as a root handled directory.- Returns:
-
-