Class HandledFile
- java.lang.Object
-
- org.silverpeas.core.process.io.file.HandledFile
-
public class HandledFile extends Object
This class permits to manipulate files (read/write/delete/...) into transactional processes. It encapsulates aFileHandler
instance and knows the root path repository into that it have to work.FileHandler.getHandledFile
method has to be called to obtain aHandledFile
instance. WithHandledFile
instance, file manipulations are easier and lighter due to the hiding of internal mechanism.- Author:
- Yohann Chastagnier
-
-
Field Summary
Fields Modifier and Type Field Description protected File
file
protected FileHandler
fileHandler
-
Constructor Summary
Constructors Modifier Constructor Description protected
HandledFile(FileBasePath basePath, FileHandler fileHandler, File file)
Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanDirectory()
boolean
contentEquals(HandledFile otherFile)
The given file is handledlong
copyFile(OutputStream output)
The given file is handledvoid
copyFile(HandledFile destFile)
The given file is handledvoid
copyInputStreamToFile(InputStream inputStream)
Use this method prior to writeByteArrayToFile in order to process very large filevoid
copyURLToFile(URL source)
The given file is handledboolean
delete()
boolean
exists(String... names)
Indicates if the file exists in session or in real path.FileBasePath
getBasePath()
File
getFile()
FileHandler
getFileHandler()
HandledFile
getHandledFile(String... names)
Gets a sub file from the current HandledFile.HandledFile
getParentHandledFile(String... names)
Gets a sub file from the parent of the current HandledFile.String
getRealPath()
Gets the real path of the file, even if the file exists only in the session pathboolean
isFileNewer(long timeMillis)
boolean
isFileNewer(File reference)
boolean
isFileNewer(Date date)
boolean
isFileNewer(HandledFile reference)
boolean
isFileOlder(long timeMillis)
boolean
isFileOlder(File reference)
boolean
isFileOlder(Date date)
boolean
isFileOlder(HandledFile reference)
Collection<HandledFile>
listFiles(boolean recursive, String... extensions)
Collection<HandledFile>
listFiles(String... extensions)
Collection<HandledFile>
listFiles(org.apache.commons.io.filefilter.IOFileFilter fileFilter, org.apache.commons.io.filefilter.IOFileFilter dirFilter)
void
moveFile(HandledFile destFile)
Given file is handledInputStream
openInputStream()
OutputStream
openOutputStream()
OutputStream
openOutputStream(boolean append)
byte[]
readFileToByteArray()
String
readFileToString()
String
readFileToString(String encoding)
List<String>
readLines()
List<String>
readLines(String encoding)
long
size()
void
touch(String... names)
boolean
waitFor(int seconds)
void
write(CharSequence data)
void
write(CharSequence data, boolean append)
void
write(CharSequence data, String encoding)
void
write(CharSequence data, String encoding, boolean append)
void
writeByteArrayToFile(byte[] data)
void
writeByteArrayToFile(byte[] data, boolean append)
void
writeLines(String encoding, Collection<?> lines)
void
writeLines(String encoding, Collection<?> lines, boolean append)
void
writeLines(String encoding, Collection<?> lines, String lineEnding)
void
writeLines(String encoding, Collection<?> lines, String lineEnding, boolean append)
void
writeLines(Collection<?> lines)
void
writeLines(Collection<?> lines, boolean append)
void
writeLines(Collection<?> lines, String lineEnding)
void
writeLines(Collection<?> lines, String lineEnding, boolean append)
void
writeStringToFile(String data)
void
writeStringToFile(String data, boolean append)
void
writeStringToFile(String data, String encoding)
void
writeStringToFile(String data, String encoding, boolean append)
-
-
-
Field Detail
-
fileHandler
protected final FileHandler fileHandler
-
file
protected final File file
-
-
Constructor Detail
-
HandledFile
protected HandledFile(FileBasePath basePath, FileHandler fileHandler, File file)
Default constructor- Parameters:
basePath
-fileHandler
-file
-
-
-
Method Detail
-
getBasePath
public FileBasePath getBasePath()
- Returns:
- the basePath
-
getFileHandler
public FileHandler getFileHandler()
- Returns:
- the fileHandler
-
getRealPath
public String getRealPath()
Gets the real path of the file, even if the file exists only in the session path
-
getFile
public File getFile()
- Returns:
- the file
-
exists
public boolean exists(String... names)
Indicates if the file exists in session or in real path.- See Also:
FileUtils
-
getHandledFile
public HandledFile getHandledFile(String... names)
Gets a sub file from the current HandledFile. If no parameter is given, then the current HandledFile is returned.- See Also:
FileUtils
-
getParentHandledFile
public HandledFile getParentHandledFile(String... names)
Gets a sub file from the parent of the current HandledFile. If no parameter is given, then the parent of current HandledFile is returned.- See Also:
FileUtils
-
openOutputStream
public OutputStream openOutputStream() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
openOutputStream
public OutputStream openOutputStream(boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
openInputStream
public InputStream openInputStream() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
touch
public void touch(String... names) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
listFiles
public Collection<HandledFile> listFiles(String... extensions)
- See Also:
fileHandler
-
listFiles
public Collection<HandledFile> listFiles(boolean recursive, String... extensions)
- See Also:
fileHandler
-
listFiles
public Collection<HandledFile> listFiles(org.apache.commons.io.filefilter.IOFileFilter fileFilter, org.apache.commons.io.filefilter.IOFileFilter dirFilter)
- See Also:
fileHandler
-
contentEquals
public boolean contentEquals(HandledFile otherFile) throws Exception
The given file is handled- Throws:
Exception
- See Also:
fileHandler
-
copyFile
public void copyFile(HandledFile destFile) throws Exception
The given file is handled- Throws:
Exception
- See Also:
fileHandler
-
copyFile
public long copyFile(OutputStream output) throws Exception
The given file is handled- Throws:
Exception
- See Also:
fileHandler
-
copyURLToFile
public void copyURLToFile(URL source) throws Exception
The given file is handled- Throws:
Exception
- See Also:
fileHandler
-
delete
public boolean delete() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
cleanDirectory
public void cleanDirectory() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
waitFor
public boolean waitFor(int seconds)
- See Also:
fileHandler
-
readFileToString
public String readFileToString() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
readFileToString
public String readFileToString(String encoding) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
readFileToByteArray
public byte[] readFileToByteArray() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
readLines
public List<String> readLines() throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
readLines
public List<String> readLines(String encoding) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeStringToFile
public void writeStringToFile(String data) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeStringToFile
public void writeStringToFile(String data, String encoding) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeStringToFile
public void writeStringToFile(String data, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeStringToFile
public void writeStringToFile(String data, String encoding, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
write
public void write(CharSequence data) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
write
public void write(CharSequence data, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
write
public void write(CharSequence data, String encoding) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
write
public void write(CharSequence data, String encoding, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeByteArrayToFile
public void writeByteArrayToFile(byte[] data) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeByteArrayToFile
public void writeByteArrayToFile(byte[] data, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
copyInputStreamToFile
public void copyInputStreamToFile(InputStream inputStream) throws Exception
Use this method prior to writeByteArrayToFile in order to process very large file- Parameters:
inputStream
- the input stream to write- Throws:
Exception
-
writeLines
public void writeLines(Collection<?> lines) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(Collection<?> lines, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(Collection<?> lines, String lineEnding) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(Collection<?> lines, String lineEnding, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(String encoding, Collection<?> lines) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(String encoding, Collection<?> lines, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(String encoding, Collection<?> lines, String lineEnding) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
writeLines
public void writeLines(String encoding, Collection<?> lines, String lineEnding, boolean append) throws Exception
- Throws:
Exception
- See Also:
fileHandler
-
moveFile
public void moveFile(HandledFile destFile) throws Exception
Given file is handled- Throws:
Exception
- See Also:
fileHandler
-
size
public long size()
- See Also:
fileHandler
-
isFileNewer
public boolean isFileNewer(HandledFile reference)
- See Also:
fileHandler
-
isFileNewer
public boolean isFileNewer(File reference)
- See Also:
fileHandler
-
isFileNewer
public boolean isFileNewer(Date date)
- See Also:
fileHandler
-
isFileNewer
public boolean isFileNewer(long timeMillis)
- See Also:
fileHandler
-
isFileOlder
public boolean isFileOlder(HandledFile reference)
- See Also:
fileHandler
-
isFileOlder
public boolean isFileOlder(File reference)
- See Also:
fileHandler
-
isFileOlder
public boolean isFileOlder(Date date)
- See Also:
fileHandler
-
isFileOlder
public boolean isFileOlder(long timeMillis)
- See Also:
fileHandler
-
-