|
|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
package net.ranides.assira.io;
|
|
|
|
|
|
+import edu.umd.cs.findbugs.annotations.SuppressWarnings;
|
|
|
import java.io.*;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.MissingResourceException;
|
|
|
@@ -127,7 +128,10 @@ public final class FileHelper {
|
|
|
* @param input
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- @edu.umd.cs.findbugs.annotations.SuppressWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
|
|
|
+ @SuppressWarnings({
|
|
|
+ "OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
|
|
+ "OBL_UNSATISFIED_OBLIGATION"
|
|
|
+ })
|
|
|
public static void copy(File output, File input) throws IOException {
|
|
|
copy(new FileOutputStream(output), new FileInputStream(input));
|
|
|
}
|
|
|
@@ -140,7 +144,10 @@ public final class FileHelper {
|
|
|
* @param input
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- @edu.umd.cs.findbugs.annotations.SuppressWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE")
|
|
|
+ @SuppressWarnings({
|
|
|
+ "OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE",
|
|
|
+ "OBL_UNSATISFIED_OBLIGATION"
|
|
|
+ })
|
|
|
public static void copy(String output, String input) throws IOException {
|
|
|
copy(new FileOutputStream(output), new FileInputStream(input));
|
|
|
}
|
|
|
@@ -227,21 +234,18 @@ public final class FileHelper {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static final class TempService {
|
|
|
- private TempService() { }
|
|
|
+ private static final class TempService { // NOPMD
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- private static final File location = new File(PrivilegedActions.getProperty("java.io.tmpdir"));
|
|
|
+ private static final File LOCATION = new File(PrivilegedActions.getProperty("java.io.tmpdir"));
|
|
|
|
|
|
public static String path() {
|
|
|
- return location.getPath();
|
|
|
+ return LOCATION.getPath();
|
|
|
}
|
|
|
public static File location(String name) {
|
|
|
- return new File(location.getPath() + File.separator + name);
|
|
|
+ return new File(LOCATION.getPath() + File.separator + name);
|
|
|
}
|
|
|
public static File location() {
|
|
|
- return location;
|
|
|
+ return LOCATION;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -259,12 +263,13 @@ public final class FileHelper {
|
|
|
public static File createTempFile(String prefix, String suffix, Class<?> clazz) throws IOException {
|
|
|
final String dir = PathHelper.getClassDir(clazz);
|
|
|
final File file = TempService.location(dir);
|
|
|
- if( file.mkdirs() ) {
|
|
|
- return File.createTempFile(clazz.getSimpleName() + prefix, suffix, file);
|
|
|
- } else {
|
|
|
+ if(!file.exists() && !file.mkdirs()) {
|
|
|
throw new IOException("can't create directory: " + file);
|
|
|
-
|
|
|
}
|
|
|
+ if(!file.isDirectory()) {
|
|
|
+ throw new IOException("path is not a directory: " + file);
|
|
|
+ }
|
|
|
+ return File.createTempFile(clazz.getSimpleName() + prefix, suffix, file);
|
|
|
}
|
|
|
|
|
|
/**
|