public void Archive() throws Exception {
final String conMethodName = conClassName + "::Archive";
String nameOfArchiveFile = null;
JSFile fleArchiveFile = null;
String strFName = null;
String strFileName = null;
SignalInfo(String.format("%1$s: starting, file to archive: '%2$s', archive-folder: '%3$s'.", conMethodName, objOptions.FileName(), objOptions
.ArchiveFolderName()));
if (objOptions == null) {
SignalAbort(String.format("%1$s: no Options specified. Archive aborted.", conMethodName));
}
objOptions.CheckMandatory();
strFileName = objOptions.FileName();
JSFile fileToArchive = new JSFile(strFileName);
fileToArchive.registerMessageListener(this);
fileToArchive.MustExist();
// String strOriginalFileName = fileToArchive.getName();
if (objOptions.CreateTimeStamp()) {
/*
* kein Rename-TimeStamp verwenden, zur Sicherheit, damit die
* Original-Datei erhalten bleibt (jedenfalls erstmal).
*/
fileToArchive = new JSFile(fileToArchive.CopyTimeStamp());
// geht nicht auf be0027 fileToArchive.deleteOnExit();
strFName = fileToArchive.getName();
}
else {
strFName = fileToArchive.getName();
}
if (objOptions.CompressArchivedFile()) {
// TODO: eigene Klasse mit eigenen Optionen implementieren
// TODO: entweder als "eigenen" File ablegen oder in ein bestehendes ZIP-File integrieren.
nameOfArchiveFile = objOptions.ArchiveFolderName() + strFName + ".gz";
fleArchiveFile = new JSFile(nameOfArchiveFile);
if (fleArchiveFile.exists()) {
SignalAbort(String.format("%1$s: file '%2$s' already exist.", conMethodName, nameOfArchiveFile));
}
SignalInfo(String.format("%3$s: Zip '%1$s' into Zip-File '%2$s'", fileToArchive.getAbsoluteFile(), fleArchiveFile.getAbsoluteFile(), conMethodName));
final BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileToArchive));
final GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(fleArchiveFile));
try {
final byte buffer[] = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
} catch (final Exception e) {
throw e;
} finally {
try {
in.close();
} catch (final Exception e) {
throw e;
}
try {
out.close();
} catch (final Exception e) {
throw e;
}
}
}
else {
nameOfArchiveFile = objOptions.ArchiveFolderName() + strFName;
fileToArchive.copy(nameOfArchiveFile);
}
message(String.format("%1$s: Archive file created '%2$s'.", conMethodName, nameOfArchiveFile));
if (objOptions.DeleteFileAfterArchiving() || objOptions.CreateTimeStamp()) {
final JSFile fileToDelete = new JSFile(strFileName);
fileToDelete.delete();
SignalInfo(String.format("%1$s: archived file deleted '%2$s'.", conMethodName, strFileName));
}
if (objOptions.CreateTimeStamp()) {
/*
* hier mu� gel�scht werden, da der die Datei mit dem Time-Stamp-Namen