* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.file.model;
+package org.onap.oom.truststoremerger.common;
import java.io.File;
import java.io.FileOutputStream;
import java.nio.file.Files;
-import java.util.List;
-import org.onap.oom.truststoremerger.api.ExitableException;
-import org.onap.oom.truststoremerger.certification.file.provider.entry.CertificateWithAlias;
-import org.onap.oom.truststoremerger.certification.file.exception.CreateBackupException;
+import org.onap.oom.truststoremerger.merger.exception.CreateBackupException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public abstract class Truststore {
+public final class BackupCreator {
- private static final Logger LOGGER = LoggerFactory.getLogger(Truststore.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(BackupCreator.class);
private static final String BACKUP_EXTENSION = ".bak";
- private final File file;
- Truststore(File file) {
- this.file = file;
+ private BackupCreator() {
}
- public abstract List<CertificateWithAlias> getCertificates() throws ExitableException;
-
- public abstract void addCertificate(List<CertificateWithAlias> certificates) throws ExitableException;
-
- public abstract void saveFile() throws ExitableException;
-
- public File getFile() {
- return file;
- }
-
- public void createBackup() throws CreateBackupException {
+ public static void createBackup(File file) throws CreateBackupException {
LOGGER.debug("Create backup of file: {}", file.getPath());
String backupFilePath = file.getAbsolutePath() + BACKUP_EXTENSION;
try (FileOutputStream fileOutputStream = new FileOutputStream(backupFilePath)) {
Files.copy(file.toPath(), fileOutputStream);
} catch (Exception e) {
- LOGGER.error("Cannot create backup of file: {} ", getFile().getPath());
+ LOGGER.error("Cannot create backup of file: {} ", file.getPath());
throw new CreateBackupException(e);
}
+ LOGGER.debug("Backup was successfully created in: {}", backupFilePath);
}
}