01: package gnu.kawa.functions;
02:
03: import java.io.*;
04: import gnu.mapping.InPort;
05:
06: public class FileUtils {
07: /* #ifndef JAVA2 */
08: // static private int tempFileNumber;
09: /* #endif */
10:
11: public static/* #ifndef JAVA2 */
12: // synchronized
13: /* #endif */
14: File createTempFile(String format) throws java.io.IOException {
15: if (format == null)
16: format = "kawa~d.tmp";
17: int tilde = format.indexOf('~');
18: String prefix, suffix;
19: File directory = null;
20: if (tilde < 0) {
21: prefix = format;
22: suffix = ".tmp";
23: } else {
24: prefix = format.substring(0, tilde);
25: suffix = format.substring(tilde + 2);
26: }
27: int sep = prefix.indexOf(File.separatorChar);
28: if (sep >= 0) {
29: directory = new File(prefix.substring(0, sep));
30: prefix = prefix.substring(sep + 1);
31: }
32: /* #ifdef JAVA2 */
33: return File.createTempFile(prefix, suffix, directory);
34: /* #else */
35: // if (directory == null)
36: // directory = new File(File.separatorChar == '\\' ? "c:\\temp" : "/tmp");
37: // for (;;)
38: // {
39: // File temp = new File(directory,
40: // prefix + (++tempFileNumber) + suffix);
41: // if (! temp.exists())
42: // {
43: // OutputStream out = new FileOutputStream(temp);
44: // out.close();
45: // return temp;
46: // }
47: // }
48: /* #endif */
49: }
50: }
|