Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2016-08-25 08:30:01 +0000
committerEike Stepper2016-08-25 08:30:01 +0000
commit58eb0dd28337648b9e53f259111355cb90ed9333 (patch)
tree21968df4372c26c7231a0c71298f9a46ff66a8d4 /plugins/org.eclipse.net4j.util
parent63d092b3bf6eaa7521ec07570a5cc66ae9b2c318 (diff)
downloadcdo-58eb0dd28337648b9e53f259111355cb90ed9333.tar.gz
cdo-58eb0dd28337648b9e53f259111355cb90ed9333.tar.xz
cdo-58eb0dd28337648b9e53f259111355cb90ed9333.zip
[500245] Lob cache can't be deleted (streams not closed?)
https://bugs.eclipse.org/bugs/show_bug.cgi?id=500245
Diffstat (limited to 'plugins/org.eclipse.net4j.util')
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/TMPUtil.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/TMPUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/TMPUtil.java
index b6f9b3a017..e93d036679 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/TMPUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/io/TMPUtil.java
@@ -17,6 +17,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
+import java.util.Random;
/**
* @author Eike Stepper
@@ -33,6 +34,8 @@ public final class TMPUtil
*/
public static final String SYSTEM_TEMP_FOLDER = OMPlatform.INSTANCE.getProperty("java.io.tmpdir"); //$NON-NLS-1$
+ private static final Random RANDOM = new Random(System.currentTimeMillis());
+
private static File tempFolder;
private TMPUtil()
@@ -104,6 +107,48 @@ public final class TMPUtil
TMPUtil.tempFolder = new File(tempFolder);
}
+ /**
+ * @since 3.7
+ */
+ public static File getTempName() throws IORuntimeException
+ {
+ return getTempName("tmp"); //$NON-NLS-1$
+ }
+
+ /**
+ * @since 3.7
+ */
+ public static File getTempName(String prefix) throws IORuntimeException
+ {
+ return getTempName(prefix, ""); //$NON-NLS-1$
+ }
+
+ /**
+ * @since 3.7
+ */
+ public static File getTempName(String prefix, String suffix) throws IORuntimeException
+ {
+ return getTempName(prefix, suffix, getTempFolder());
+ }
+
+ /**
+ * @since 3.7
+ */
+ public static File getTempName(String prefix, String suffix, File directory) throws IORuntimeException
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ long random = Math.abs(RANDOM.nextLong());
+ File name = new File(directory, prefix + random + suffix);
+ if (!name.exists())
+ {
+ return name;
+ }
+ }
+
+ throw new IORuntimeException("Could not determine unique name in " + directory);
+ }
+
public static File createTempFolder() throws IORuntimeException
{
return createTempFolder("tmp"); //$NON-NLS-1$

Back to the top