diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-12-08 16:08:21 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-12-08 16:08:21 +0100 |
commit | 52809a748da8bf2c3b2e43f71a9aefb833bfe94c (patch) | |
tree | 13a7270e34237d5a949485f769bb1b3cafabcabf /sonar-home/src | |
parent | 93ea25fb4634f91147b4c49b5df2c2ad48177e00 (diff) | |
download | sonarqube-52809a748da8bf2c3b2e43f71a9aefb833bfe94c.tar.gz sonarqube-52809a748da8bf2c3b2e43f71a9aefb833bfe94c.zip |
Refactor FileCache#newTempFile()
Diffstat (limited to 'sonar-home/src')
-rw-r--r-- | sonar-home/src/main/java/org/sonar/home/cache/FileCache.java | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java index 090546c21cf..d41da7a866d 100644 --- a/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java +++ b/sonar-home/src/main/java/org/sonar/home/cache/FileCache.java @@ -28,7 +28,6 @@ import javax.annotation.CheckForNull; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.Random; import java.util.zip.ZipEntry; /** @@ -133,23 +132,11 @@ public class FileCache { } private File newTempFile() { - String baseName = System.currentTimeMillis() + "-"; - Random random = new Random(); - for (int counter = 0; counter < TEMP_FILE_ATTEMPTS; counter++) { - try { - String filename = baseName + random.nextInt(1000); - File tempFile = new File(tmpDir, filename); - if (tempFile.createNewFile()) { - return tempFile; - } - } catch (IOException e) { - // ignore except the last try - if (counter == TEMP_FILE_ATTEMPTS - 1) { - throw new IllegalStateException("Fail to create temp file", e); - } - } + try { + return File.createTempFile("fileCache", null, tmpDir); + } catch (IOException e) { + throw new IllegalStateException("Fail to create temp file in " + tmpDir, e); } - throw new IllegalStateException("Fail to create temporary file in " + tmpDir); } private File createTempDir() { |