X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=kona%2Fsrc%2Forg%2Ffeistymeow%2Futility%2FExtemporizer.java;fp=kona%2Fsrc%2Forg%2Ffeistymeow%2Futility%2FExtemporizer.java;h=b271ab18652c9b10de6b654a285cb2c359ddeaa5;hb=67d3d9a5e40685d3898f34a3651944c8a0c3e2ca;hp=0000000000000000000000000000000000000000;hpb=2d9bf2a5bf795aabd3498d96e5b005c18889002d;p=feisty_meow.git diff --git a/kona/src/org/feistymeow/utility/Extemporizer.java b/kona/src/org/feistymeow/utility/Extemporizer.java new file mode 100644 index 00000000..b271ab18 --- /dev/null +++ b/kona/src/org/feistymeow/utility/Extemporizer.java @@ -0,0 +1,51 @@ +package org.feistymeow.utility; + +import java.io.File; +import java.io.IOException; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +////////////// +// Name : Extemporizer +// Author : Chris Koeritz +// Rights : Copyright (c) 2012-$now By University of Virginia +////////////// +// This file is free software; you can modify/redistribute it under the terms +// of the Apache License v2.0: http://www.apache.org/licenses/LICENSE-2.0 +// Feel free to send updates to: [ koeritz@virginia.edu ] +////////////// + +/** + * A set of useful utilities for dealing with temporary items. + */ +public class Extemporizer +{ + static private Log _logger = LogFactory.getLog(Extemporizer.class); + + /** + * creates a uniquely named temporary directory. thanks for guidance to article at: + * http://stackoverflow.com/questions/617414/create-a-temporary-directory-in-java + * + * @return a File object pointing at the new temporary directory. + * @throws IOException + */ + public static File createTempDirectory(String prefix, String suffix) + { + if ((prefix == null) || (suffix == null)) + return null; + try { + final File temp = File.createTempFile(prefix, suffix); + if (!temp.delete()) + throw new IOException("failed to delete temporary file: " + temp.getAbsolutePath()); + if (!temp.mkdir()) + throw new IOException("failed to create temporary directory: " + + temp.getAbsolutePath()); + temp.deleteOnExit(); // set for cleanup. + return temp; + } catch (Throwable cause) { + _logger.error("caught exception while creating temporary directory", cause); + return null; + } + } +}