mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Add FileUtils.maybeCreateFileWithParentDirectories(File)
This commit is contained in:
parent
a70ae7ab8e
commit
fb3009adb2
3 changed files with 26 additions and 28 deletions
|
@ -120,26 +120,12 @@ public class FileBasedOpenPgpMetadataStore extends AbstractOpenPgpMetadataStore
|
|||
|
||||
static void writeFingerprintsAndDates(Map<OpenPgpV4Fingerprint, Date> data, File destination)
|
||||
throws IOException {
|
||||
|
||||
if (data == null || data.isEmpty()) {
|
||||
FileUtils.maybeDeleteFileOrThrow(destination);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!destination.exists()) {
|
||||
File parent = destination.getParentFile();
|
||||
if (!parent.exists() && !parent.mkdirs()) {
|
||||
throw new IOException("Cannot create directory " + parent.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (!destination.createNewFile()) {
|
||||
throw new IOException("Cannot create file " + destination.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
if (destination.isDirectory()) {
|
||||
throw new IOException("File " + destination.getAbsolutePath() + " is a directory.");
|
||||
}
|
||||
FileUtils.maybeCreateFileWithParentDirectories(destination);
|
||||
|
||||
BufferedWriter writer = null;
|
||||
try {
|
||||
|
|
|
@ -102,19 +102,7 @@ public class FileBasedOpenPgpTrustStore extends AbstractOpenPgpTrustStore {
|
|||
FileUtils.maybeDeleteFileOrThrow(file);
|
||||
}
|
||||
|
||||
File parent = file.getParentFile();
|
||||
if (!parent.exists() && !parent.mkdirs()) {
|
||||
throw new IOException("Cannot create directory " + parent.getAbsolutePath());
|
||||
}
|
||||
if (!file.exists()) {
|
||||
if (!file.createNewFile()) {
|
||||
throw new IOException("Cannot create file " + file.getAbsolutePath());
|
||||
}
|
||||
} else {
|
||||
if (file.isDirectory()) {
|
||||
throw new IOException("File " + file.getAbsolutePath() + " is a directory.");
|
||||
}
|
||||
}
|
||||
FileUtils.maybeCreateFileWithParentDirectories(file);
|
||||
|
||||
BufferedWriter writer = null;
|
||||
try {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue