From 3b52b7adafeda64730fb0070ab16655aa706b254 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 28 Sep 2011 17:03:32 +0200 Subject: IOUtil/Android: Convenient createTempFile wrapper for Android, using the context's directory + '/temp' (if stored at StaticContext) --- src/java/com/jogamp/common/util/IOUtil.java | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/java/com') 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 ); + } } -- cgit v1.2.3