org.silverpeas.process.io.file
Class HandledFile

java.lang.Object
  extended by org.silverpeas.process.io.file.HandledFile

public class HandledFile
extends Object

This class permits to manipulate files (read/write/delete/...) into transactional processes. It encapsulates a FileHandler instance and knows the root path repository into that it have to work. FileHandler.getHandledFile method has to be called to obtain a HandledFile instance. With HandledFile instance, file manipulations are easier and lighter due to the hiding of internal mechanism.

Author:
Yohann Chastagnier

Field Summary
protected  File file
           
protected  FileHandler fileHandler
           
 
Constructor Summary
protected HandledFile(FileBasePath basePath, FileHandler fileHandler, File file)
          Default constructor
 
Method Summary
 void cleanDirectory()
           
 boolean contentEquals(HandledFile otherFile)
          The given file is handled
 void copyFile(HandledFile destFile)
          The given file is handled
 long copyFile(OutputStream output)
          The given file is handled
 void copyInputStreamToFile(InputStream inputStream)
          Use this method prior to writeByteArrayToFile in order to process very large file
 void copyURLToFile(URL source)
          The given file is handled
 boolean 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 path
 boolean isFileNewer(Date date)
           
 boolean isFileNewer(File reference)
           
 boolean isFileNewer(HandledFile reference)
           
 boolean isFileNewer(long timeMillis)
           
 boolean isFileOlder(Date date)
           
 boolean isFileOlder(File reference)
           
 boolean isFileOlder(HandledFile reference)
           
 boolean isFileOlder(long timeMillis)
           
 Collection<HandledFile> listFiles(boolean recursive, String... extensions)
           
 Collection<HandledFile> listFiles(org.apache.commons.io.filefilter.IOFileFilter fileFilter, org.apache.commons.io.filefilter.IOFileFilter dirFilter)
           
 Collection<HandledFile> listFiles(String... extensions)
           
 void moveFile(HandledFile destFile)
          Given file is handled
 InputStream 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(Collection<?> lines)
           
 void writeLines(Collection<?> lines, boolean append)
           
 void writeLines(Collection<?> lines, String lineEnding)
           
 void writeLines(Collection<?> lines, String lineEnding, 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 writeStringToFile(String data)
           
 void writeStringToFile(String data, boolean append)
           
 void writeStringToFile(String data, String encoding)
           
 void writeStringToFile(String data, String encoding, boolean append)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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


Copyright © 2016 Silverpeas. All Rights Reserved.