feisty meow concerns codebase  2.140
Extemporizer.java
Go to the documentation of this file.
1 package org.feistymeow.utility;
2 
3 import java.io.File;
4 import java.io.IOException;
5 
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8 
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 ]
18 
22 public class Extemporizer
23 {
24  static private Log _logger = LogFactory.getLog(Extemporizer.class);
25 
33  public static File createTempDirectory(String prefix, String suffix)
34  {
35  if ((prefix == null) || (suffix == null))
36  return null;
37  try {
38  final File temp = File.createTempFile(prefix, suffix);
39  if (!temp.delete())
40  throw new IOException("failed to delete temporary file: " + temp.getAbsolutePath());
41  if (!temp.mkdir())
42  throw new IOException("failed to create temporary directory: "
43  + temp.getAbsolutePath());
44  temp.deleteOnExit(); // set for cleanup.
45  return temp;
46  } catch (Throwable cause) {
47  _logger.error("caught exception while creating temporary directory", cause);
48  return null;
49  }
50  }
51 }
static File createTempDirectory(String prefix, String suffix)