How do I use the scratch space area in Internet Explorer?

John Zukowski

One thing that IE does offer outside of the privilege model is scratch space. Your applets have access to temporary storage space on the client file system, enabling them to store state across multiple invocations, up to 1 MB of space. Also, the same applet loaded from multiple download sites has access to the same scratch space. Like Netscape's Capabilities API, scratch space works from unsigned applets for debugging. However, to be usable from a web server, the applet must be placed in a signed CAB file.

You must use the Microsoft Virtual Machine for Java, found in Internet Explorer 4.x/5.x to utilize these capabilities. However, you can still compile with the JDK compiler if you include Microsoft's classes.zip file after the JDK's classes.zip in your CLASSPATH. On a Windows NT machine, the file is probably located in C:WinNTJavaClasses.

The basis for using the scratch space is the ClientStore class, located in the com.ms.io.clientstorage package. You acquire access to the store from the ClientStoreManager by asking for it with getStore(). Once you have access to the ClientStore, you can get a readable file with openReadable() or a writable one with openWritable(), passing the filename string as its argument. The openWritable() method has a two-argument variety that accepts a boolean value as the second parameter, enabling append-mode when true.

// Assert permissions
// Get ClientStore from ClientStorageManager
ClientStore cs = ClientStorageManager.getStore();
// Create new file / overwrite
OutputStream os1 = cs.openWritable(filename);
// Open writable file in append mode
OutputStream os2 = cs.openWritable(filename, true);
// Get readable file from cache
InputStream is = cs.openReadable(filename);

So, where are the temporary files stored? They can be found in the Local Data directory, under the Java directory. There are protections in place so a temporary file cannot consume all available disk space. The Java directory is also where you will find the javalog.txt file that would contain any messages sent to the equivalent of Netscape's Java Console.

The use of a scratch space from core classes is only available with the Microsoft VM. If you wanted to do this with other runtimes like the Plug-in, you would have to implement this behavior yourself.