diff options
author | Sven Gothel <[email protected]> | 2011-09-28 17:03:32 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-09-28 17:03:32 +0200 |
commit | 3b52b7adafeda64730fb0070ab16655aa706b254 (patch) | |
tree | 4c68ec83aa9e00fdc12935d8382d927a80e1cd8c /src/java/com/jogamp | |
parent | e70d4a081750fc1386435f37c86d66fadb66d988 (diff) |
IOUtil/Android: Convenient createTempFile wrapper for Android, using the context's directory + '/temp' (if stored at StaticContext)
Diffstat (limited to 'src/java/com/jogamp')
-rw-r--r-- | src/java/com/jogamp/common/util/IOUtil.java | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java index beb3deb..4038caf 100644 --- a/src/java/com/jogamp/common/util/IOUtil.java +++ b/src/java/com/jogamp/common/util/IOUtil.java @@ -42,6 +42,9 @@ import java.net.URLConnection; import java.nio.ByteBuffer; import jogamp.common.Debug; +import jogamp.common.os.android.StaticContext; + +import android.content.Context; import com.jogamp.common.nio.Buffers; import com.jogamp.common.os.MachineDescription; @@ -440,5 +443,36 @@ public class IOUtil { } return v; - } + } + + /** + * @see File#createTempFile(String, String) + * @see File#createTempFile(String, String, File) + * + * @param prefix + * @param suffix + * @return + * @throws IllegalArgumentException + * @throws IOException + * @throws SecurityException + */ + public static File createTempFile(String prefix, String suffix) + throws IllegalArgumentException, IOException, SecurityException + { + if(Platform.OS_TYPE == Platform.OSType.ANDROID) { + Context ctx = StaticContext.getContext(); + if(null != ctx) { + final File td = ctx.getDir("temp", Context.MODE_WORLD_READABLE); + if(DEBUG) { + System.err.println("IOUtil.createTempFile(Android): ctx temp dir: "+td.getAbsolutePath()); + } + final File f = File.createTempFile( prefix, suffix, td ); + if(DEBUG) { + System.err.println("IOUtil.createTempFile(Android): temp file: "+f.getAbsolutePath()); + } + return f; + } + } + return File.createTempFile( prefix, suffix ); + } } |