1 package org.feistymeow.utility;
4 import java.io.IOException;
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
10 // Name : Extemporizer
11 // Author : Chris Koeritz
12 // Rights : Copyright (c) 2012-$now By University of Virginia
14 // This file is free software; you can modify/redistribute it under the terms
15 // of the Apache License v2.0: http://www.apache.org/licenses/LICENSE-2.0
16 // Feel free to send updates to: [ koeritz@virginia.edu ]
20 * A set of useful utilities for dealing with temporary items.
22 public class Extemporizer
24 static private Log _logger = LogFactory.getLog(Extemporizer.class);
27 * creates a uniquely named temporary directory. thanks for guidance to article at:
28 * http://stackoverflow.com/questions/617414/create-a-temporary-directory-in-java
30 * @return a File object pointing at the new temporary directory.
33 public static File createTempDirectory(String prefix, String suffix)
35 if ((prefix == null) || (suffix == null))
38 final File temp = File.createTempFile(prefix, suffix);
40 throw new IOException("failed to delete temporary file: " + temp.getAbsolutePath());
42 throw new IOException("failed to create temporary directory: "
43 + temp.getAbsolutePath());
44 temp.deleteOnExit(); // set for cleanup.
46 } catch (Throwable cause) {
47 _logger.error("caught exception while creating temporary directory", cause);