mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Temp dirs/files creation reorganized
This commit is contained in:
@@ -134,49 +134,31 @@ public class FileUtilRt {
|
||||
return createTempDirectory(prefix, suffix, true);
|
||||
}
|
||||
|
||||
public static File createTempDirectory(@NotNull @NonNls String prefix, @Nullable @NonNls String suffix, boolean deleteOnExit) throws IOException {
|
||||
File file = doCreateTempFile(prefix, suffix);
|
||||
file.delete();
|
||||
file.mkdir();
|
||||
if (deleteOnExit) {
|
||||
file.deleteOnExit();
|
||||
}
|
||||
return file;
|
||||
public static File createTempDirectory(@NotNull @NonNls String prefix, @Nullable @NonNls String suffix,
|
||||
boolean deleteOnExit) throws IOException {
|
||||
final File dir = new File(getTempDirectory());
|
||||
return createTempDirectory(dir, prefix, suffix, deleteOnExit);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempDirectory(@NotNull File dir, @NotNull @NonNls String prefix, @Nullable @NonNls String suffix) throws IOException {
|
||||
return createTempDirectory(dir, prefix, suffix,true);
|
||||
public static File createTempDirectory(@NotNull File dir,
|
||||
@NotNull @NonNls String prefix, @Nullable @NonNls String suffix) throws IOException {
|
||||
return createTempDirectory(dir, prefix, suffix, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempDirectory(@NotNull File dir, @NotNull @NonNls String prefix, @Nullable @NonNls String suffix,boolean deleteOnExit) throws IOException {
|
||||
public static File createTempDirectory(@NotNull File dir,
|
||||
@NotNull @NonNls String prefix, @Nullable @NonNls String suffix,
|
||||
boolean deleteOnExit) throws IOException {
|
||||
File file = doCreateTempFile(dir, prefix, suffix);
|
||||
file.delete();
|
||||
file.mkdir();
|
||||
if (deleteOnExit) {
|
||||
file.deleteOnExit();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempFile(@NonNls File dir, @NotNull @NonNls String prefix, @Nullable @NonNls String suffix, boolean create) throws IOException {
|
||||
return createTempFile(dir, prefix, suffix, create, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempFile(@NonNls final File dir,
|
||||
@NotNull @NonNls String prefix,
|
||||
@Nullable @NonNls String suffix,
|
||||
final boolean create,
|
||||
boolean deleteOnExit) throws IOException {
|
||||
File file = doCreateTempFile(dir, prefix, suffix);
|
||||
file.delete();
|
||||
if (create) {
|
||||
file.createNewFile();
|
||||
if (!file.delete() && file.exists()) {
|
||||
throw new IOException("Cannot delete file: " + file);
|
||||
}
|
||||
if (deleteOnExit) {
|
||||
file.deleteOnExit();
|
||||
if (!file.mkdir() && !file.isDirectory()) {
|
||||
throw new IOException("Cannot create directory: " + file);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
@@ -187,23 +169,39 @@ public class FileUtilRt {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempFile(@NotNull @NonNls String prefix, @Nullable @NonNls String suffix, boolean deleteOnExit) throws IOException {
|
||||
File file = doCreateTempFile(prefix, suffix);
|
||||
file.delete();
|
||||
file.createNewFile();
|
||||
public static File createTempFile(@NotNull @NonNls String prefix, @Nullable @NonNls String suffix,
|
||||
boolean deleteOnExit) throws IOException {
|
||||
final File dir = new File(getTempDirectory());
|
||||
return createTempFile(dir, prefix, suffix, true, deleteOnExit);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempFile(@NonNls File dir,
|
||||
@NotNull @NonNls String prefix, @Nullable @NonNls String suffix,
|
||||
boolean create) throws IOException {
|
||||
return createTempFile(dir, prefix, suffix, create, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File createTempFile(@NonNls File dir,
|
||||
@NotNull @NonNls String prefix, @Nullable @NonNls String suffix,
|
||||
boolean create, boolean deleteOnExit) throws IOException {
|
||||
File file = doCreateTempFile(dir, prefix, suffix);
|
||||
if (deleteOnExit) {
|
||||
file.deleteOnExit();
|
||||
}
|
||||
if (!create) {
|
||||
if (!file.delete() && file.exists()) {
|
||||
throw new IOException("Cannot delete file: " + file);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File doCreateTempFile(String prefix, String suffix) throws IOException {
|
||||
return doCreateTempFile(new File(getTempDirectory()), prefix, suffix);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static File doCreateTempFile(@NotNull File dir, @NotNull String prefix, String suffix) throws IOException {
|
||||
private static File doCreateTempFile(@NotNull File dir,
|
||||
@NotNull @NonNls String prefix, @Nullable @NonNls String suffix) throws IOException {
|
||||
//noinspection ResultOfMethodCallIgnored
|
||||
dir.mkdirs();
|
||||
|
||||
if (prefix.length() < 3) {
|
||||
@@ -246,8 +244,7 @@ public class FileUtilRt {
|
||||
return canonical;
|
||||
}
|
||||
}
|
||||
catch (IOException ignore) {
|
||||
}
|
||||
catch (IOException ignore) { }
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user