SimpleTempStoragepublic class SimpleTempStorage extends TempStorage
Fields Summary |
---|
private static Log | log | private TempPath | rootPath | private Random | random |
Constructors Summary |
---|
public SimpleTempStorage()Creates a new SimpleTempStorageManager instance.
rootPath = new SimpleTempPath(System.getProperty("java.io.tmpdir"));
|
Methods Summary |
---|
private TempFile | createTempFile(TempPath parent, java.lang.String prefix, java.lang.String suffix)
if (prefix == null) {
prefix = "";
}
if (suffix == null) {
suffix = ".tmp";
}
File f = null;
int count = 1000;
synchronized (this) {
do {
long n = Math.abs(random.nextLong());
f = new File(parent.getAbsolutePath(), prefix + n + suffix);
count--;
} while (f.exists() && count > 0);
if (f.exists()) {
throw new IOException("Creating temp file failed: "
+ "Unable to find unique file name");
}
try {
f.createNewFile();
} catch (IOException e) {
throw new IOException("Creating dir '"
+ f.getAbsolutePath() + "' failed.");
}
}
return new SimpleTempFile(f);
| private TempPath | createTempPath(TempPath parent, java.lang.String prefix)
if (prefix == null) {
prefix = "";
}
File p = null;
int count = 1000;
do {
long n = Math.abs(random.nextLong());
p = new File(parent.getAbsolutePath(), prefix + n);
count--;
} while (p.exists() && count > 0);
if (p.exists() || !p.mkdirs()) {
log.error("Unable to mkdirs on " + p.getAbsolutePath());
throw new IOException("Creating dir '"
+ p.getAbsolutePath() + "' failed.");
}
return new SimpleTempPath(p);
| public TempPath | getRootTempPath()
return rootPath;
|
|