100 |
* may be an absolute or relative path name. |
* may be an absolute or relative path name. |
101 |
*/ |
*/ |
102 |
private String path; |
private String path; |
103 |
|
|
104 |
|
|
105 |
|
/** |
106 |
|
* The time (millisecond), when the last temporary file was created. |
107 |
|
*/ |
108 |
|
private static long last_tmp; |
109 |
|
|
110 |
|
/** |
111 |
|
* The number of files, created during the current millisecond. |
112 |
|
*/ |
113 |
|
private static int n_created; |
114 |
|
|
115 |
/** |
/** |
116 |
* This method tests whether or not the current thread is allowed to |
* This method tests whether or not the current thread is allowed to |
1070 |
* |
* |
1071 |
* @since 1.2 |
* @since 1.2 |
1072 |
*/ |
*/ |
1073 |
public static File createTempFile(String prefix, String suffix, |
public static synchronized File createTempFile(String prefix, String suffix, |
1074 |
File directory) |
File directory) |
1075 |
throws IOException |
throws IOException |
1076 |
{ |
{ |
1102 |
// Now identify a file name and make sure it doesn't exist. |
// Now identify a file name and make sure it doesn't exist. |
1103 |
File file; |
File file; |
1104 |
if (!VMFile.IS_DOS_8_3) |
if (!VMFile.IS_DOS_8_3) |
1105 |
{ |
{ |
1106 |
do |
do |
1107 |
{ |
{ |
1108 |
String filename = prefix + System.currentTimeMillis() + suffix; |
long now = System.currentTimeMillis(); |
1109 |
|
if (now > last_tmp) |
1110 |
|
{ |
1111 |
|
// The last temporary file was created more than 1 ms ago. |
1112 |
|
last_tmp = now; |
1113 |
|
n_created = 0; |
1114 |
|
} |
1115 |
|
else |
1116 |
|
n_created++; |
1117 |
|
|
1118 |
|
String name = Long.toHexString(now); |
1119 |
|
if (n_created > 0) |
1120 |
|
name += '_'+Integer.toHexString(n_created); |
1121 |
|
String filename = prefix + name + suffix; |
1122 |
file = new File(directory, filename); |
file = new File(directory, filename); |
1123 |
} |
} |
1124 |
while (VMFile.exists(file.path)); |
while (VMFile.exists(file.path)); |