@Test public void testTempDir() { File file = TempUtils.createTempDir("foo"); Assert.assertTrue(file.exists()); Assert.assertTrue(file.isDirectory()); Assert.assertTrue(file.getName().contains("foo")); file.delete(); }
public static File createTempDir(String prefix) { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseName = prefix + System.currentTimeMillis() + "-"; for (int counter = 0; counter < 10000; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException( "Failed to create directory within " + 10000 + " attempts (tried " + baseName + "0 to " + baseName + (10000 - 1) + ')'); }
TempUtils { public static File createTempDir(String prefix) { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseName = prefix + System.currentTimeMillis() + "-"; for (int counter = 0; counter < 10000; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException( "Failed to create directory within " + 10000 + " attempts (tried " + baseName + "0 to " + baseName + (10000 - 1) + ')'); } }
TempUtils { public static File createTempDir(String prefix) { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseName = prefix + System.currentTimeMillis() + "-"; for (int counter = 0; counter < 10000; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException( "Failed to create directory within " + 10000 + " attempts (tried " + baseName + "0 to " + baseName + (10000 - 1) + ')'); } private  TempUtils(); }
TempUtils { public static File createTempDir(String prefix) { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseName = prefix + System.currentTimeMillis() + "-"; for (int counter = 0; counter < 10000; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException( "Failed to create directory within " + 10000 + " attempts (tried " + baseName + "0 to " + baseName + (10000 - 1) + ')'); } private  TempUtils(); static File createTempDir(String prefix); static File copyIntoTempFile(String fileName, InputStream inputStream); }
TempUtils { public static File createTempDir(String prefix) { File baseDir = new File(System.getProperty("java.io.tmpdir")); String baseName = prefix + System.currentTimeMillis() + "-"; for (int counter = 0; counter < 10000; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException( "Failed to create directory within " + 10000 + " attempts (tried " + baseName + "0 to " + baseName + (10000 - 1) + ')'); } private  TempUtils(); static File createTempDir(String prefix); static File copyIntoTempFile(String fileName, InputStream inputStream);  }