Package de.intarsys.tools.file
Class ArchiveTools
java.lang.Object
de.intarsys.tools.file.ArchiveTools
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
archive
(File root, String relativePath, File file, int max, String sourceEncoding, String destinationEncoding, boolean deleteSource, boolean forceArchive) Archive a files content.static String
archive
(File root, String relativePath, String filename, InputStream is, int max) Create a archive file and dump the input stream to this file.static File
createArchive
(File root, String relativePath, String filename, int max) Just creates a archive file, nothing will be dumped inside this file.static OutputStream
createOutputStream
(File root, String filename, int max)
-
Constructor Details
-
ArchiveTools
public ArchiveTools()
-
-
Method Details
-
archive
public static String archive(File root, String relativePath, File file, int max, String sourceEncoding, String destinationEncoding, boolean deleteSource, boolean forceArchive) throws IOException Archive a files content.The method creates a copy in the archive directory with a unique name that is guaranteed to create a sortable representation so that newer files have a "greater" filename. Creation of file names is thread safe. If more than
max
files are in the archive directory, the oldest files are deleted. max = 0 means never create archive, max = -1 means always create archive. IfdeleteSource
istrue
, the file to be archived is deleted after the archive was created.- Parameters:
root
- The root for relative addressing.relativePath
- The path relative to root where to create the archive.file
- The file to archive.max
- The maximum number of archive files allowed.hansourceEncoding
- The encoding of the file to be archived.destinationEncoding
- The encoding of the archived file.deleteSource
- Flag if source should be deleted.forceArchive
- Flag if we should archive even if file is already in the archive directory.- Returns:
- The name of the archived file, or null.
- Throws:
IOException
-
archive
public static String archive(File root, String relativePath, String filename, InputStream is, int max) throws IOException Create a archive file and dump the input stream to this file. Calls createArchive, and then copies the is to the output stream.- Parameters:
root
- The root for relative addressing.relativePath
- The path relative to root where to create the archive.filename
- The file to archive.max
- The maximum number of archive files allowed.hanis
- The input stream to be dumped.- Returns:
- The name of the archived file, or null.
- Throws:
IOException
-
createArchive
public static File createArchive(File root, String relativePath, String filename, int max) throws IOException Just creates a archive file, nothing will be dumped inside this file.- Parameters:
root
- The root for relative addressing.relativePath
- The path relative to root where to create the archive.filename
- The file to archive.max
- The maximum number of archive files allowed.han- Returns:
- The name of the archived file, or null.
- Throws:
IOException
-
createOutputStream
public static OutputStream createOutputStream(File root, String filename, int max) throws IOException - Throws:
IOException
-