Skip to content

Commit

Permalink
Merge pull request #1 from matthewadams/master
Browse files Browse the repository at this point in the history
Support nested working/temp directories
  • Loading branch information
michaelmosmann committed Nov 12, 2012
2 parents 7357d45 + 4d5f9ba commit 0eb8f75
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/main/java/de/flapdoodle/embed/process/io/file/Files.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ private Files() {

@Deprecated
public static File createTempFile(String tempFileName) throws IOException {
return createTempFile(PropertyOrPlatformTempDir.defaultInstance(), tempFileName);
return createTempFile(PropertyOrPlatformTempDir.defaultInstance(),
tempFileName);
}

public static File createTempFile(IDirectory directory, String tempFileName) throws IOException {
public static File createTempFile(IDirectory directory, String tempFileName)
throws IOException {
File tempDir = directory.asFile();
File tempFile = new File(tempDir, tempFileName);
if (!tempFile.createNewFile())
Expand All @@ -63,7 +65,7 @@ public static File createOrCheckDir(String dir) throws IOException {
File tempFile = new File(dir);
if ((tempFile.exists()) && (tempFile.isDirectory()))
return tempFile;
if (!tempFile.mkdir())
if (!tempFile.mkdirs())
throw new IOException("Could not create Tempdir: " + tempFile);
return tempFile;
}
Expand All @@ -73,20 +75,23 @@ public static File createOrCheckUserDir(String prefix) throws IOException {
File tempFile = new File(tempDir, prefix);
if ((tempFile.exists()) && (tempFile.isDirectory()))
return tempFile;
if (!tempFile.mkdir())
if (!tempFile.mkdirs())
throw new IOException("Could not create Tempdir: " + tempFile);
return tempFile;
}

@Deprecated
public static File createTempDir(String prefix) throws IOException {
return createTempDir(PropertyOrPlatformTempDir.defaultInstance(), prefix);
return createTempDir(PropertyOrPlatformTempDir.defaultInstance(),
prefix);
}

public static File createTempDir(IDirectory directory, String prefix) throws IOException {
File tempDir=directory.asFile();
File tempFile = new File(tempDir, prefix + "-" + UUID.randomUUID().toString());
if (!tempFile.mkdir())
public static File createTempDir(IDirectory directory, String prefix)
throws IOException {
File tempDir = directory.asFile();
File tempFile = new File(tempDir, prefix + "-"
+ UUID.randomUUID().toString());
if (!tempFile.mkdirs())
throw new IOException("Could not create Tempdir: " + tempFile);
return tempFile;
}
Expand All @@ -101,15 +106,17 @@ public static boolean forceDelete(File fileOrDir) {
ret = true;
}
} catch (IOException e) {
logger.warning("Could not delete " + fileOrDir + ". Will try to delete it again when program exits.");
logger.warning("Could not delete " + fileOrDir
+ ". Will try to delete it again when program exits.");
FileCleaner.forceDeleteOnExit(fileOrDir);
ret = true;
}

return ret;
}

public static void write(InputStream in, long size, File output) throws IOException {
public static void write(InputStream in, long size, File output)
throws IOException {
FileOutputStream out = new FileOutputStream(output);

try {
Expand Down Expand Up @@ -147,8 +154,8 @@ public static void write(InputStream in, File output) throws IOException {

public static void write(String content, File output) throws IOException {
FileOutputStream out = new FileOutputStream(output);
OutputStreamWriter w=new OutputStreamWriter(out);
OutputStreamWriter w = new OutputStreamWriter(out);

try {
w.write(content);
w.flush();
Expand All @@ -170,7 +177,8 @@ public static boolean moveFile(File source, File destination) {
return true;
}

private static void copyFile(File source, File destination) throws IOException {
private static void copyFile(File source, File destination)
throws IOException {
FileInputStream reader = null;
FileOutputStream writer = null;
try {
Expand Down

0 comments on commit 0eb8f75

Please sign in to comment.