Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * The MIT License
   * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
   * Permission is hereby granted, free of charge, to any person obtaining a copy
   * of this software and associated documentation files (the "Software"), to deal
   * in the Software without restriction, including without limitation the rights
   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
  * furnished to do so, subject to the following conditions:
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
 package org.jvnet.hudson.test;
 import java.util.Set;

Allocates temporary directories and cleans it up at the end.

Kohsuke Kawaguchi
 public class TemporaryDirectoryAllocator {
Remember allocated directories to delete them later.
     private final Set<FiletmpDirectories = new HashSet<File>();

Directory in which we allocate temporary directories.
     private final File base;
     public TemporaryDirectoryAllocator(File base) {
         this. = base;
     public TemporaryDirectoryAllocator() {
         this(new File(System.getProperty("")));

Allocates a new empty temporary directory and returns it. This directory will be wiped out when TemporaryDirectoryAllocator gets disposed. When this method returns, the directory already exists.
     public synchronized File allocate() throws IOException {
         try {
             File f = File.createTempFile("hudson""test");
             return f;
         } catch (IOException e) {
             throw new IOException2("Failed to create a temporary directory in "+,e);

Deletes all allocated temporary directories.
     public synchronized void dispose() throws IOExceptionInterruptedException {
         IOException x = null;
         for (File dir : )
             try {
                 new FilePath(dir).deleteRecursive();
             } catch (IOException e) {
                 x = e;
         if (x!=null)    throw new IOException2("Failed to clean up temp dirs",x);

Deletes all allocated temporary directories asynchronously.
     public synchronized void disposeAsync() {
         final Set<Filetbr = new HashSet<File>();
         new Thread("Disposing "+) {
             public void run() {
                 for (File dir : tbr)
                    try {
                        new FilePath(dir).deleteRecursive();
                    } catch (IOException e) {
                    } catch (InterruptedException e) {
New to GrepCode? Check out our FAQ X