intarsys runtime library

de.intarsys.tools.file
Class ArchiveTools

java.lang.Object
  extended by de.intarsys.tools.file.ArchiveTools

public class ArchiveTools
extends Object


Constructor Summary
ArchiveTools()
           
 
Method Summary
static 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)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArchiveTools

public ArchiveTools()
Method Detail

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. If deleteSource is true, 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.han
sourceEncoding - 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.han
is - 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

intarsys runtime library

Copyright © 2008 intarsys consulting GmbH. All Rights Reserved.