|
|
||||||||||||||
About com.ms.io.clientstorageThe com.ms.io.clientstorage package contains classes that manage and enforce storage limitations for principals. The three classes in this package work together to keep track of the available storage, allocate storage, and allow information about the files to be retrieved. These classes can be used to allocate scratch space for an applet on the client's computer. Scratch space is unshared persistent storage that is available only to the signer of the applet that created the storage. If an applet is unsigned, it can obtain and use scratch space if it runs from the class path or from a fully trusted zone. The amount of scratch space and its location on the client computer is managed by the Microsoft Win32 VM for Java so that it cannot be used maliciously. Scratch space is sometimes used to store configuration information for applets that are re-used. Overview of ClassesThe ClientStorageManager class keeps track of all client stores. You can use the ClientStorageManager class to obtain the store for a specified principal, open a shared store, or get the store for the currently executing principal. You can open a file for reading or writing with a specified type of accessibility. This is the class that you use to obtain scratch space for your applet. The ClientStore class provides access to individual client stores and enforces storage limitations. This class includes methods that allow you to delete a file, create directories, rename a file, get the length of a file, list the files in a directory, and determine whether a file exists. You can also use the ClientStore class to open a file for reading or writing (as you can with the ClientStorageManager class). The methods in this class allow you to create files and directories and obtain other information about files within your applet's scratch space. The ClientStoreFile class manages individual files within client stores. Using the methods in this class, you can delete a file, rename it, make a directory for it, determine whether you can read from the file, get the absolute or canonical path for the file, and retrieve other information about a file. This class provides methods for manipulating an individual file within your applet's scratch space. The following table describes the accessibility flags used to open files in the com.ms.io.clientstorage package.
ExampleThe following example uses the com.ms.io.clientstorage package to create a client store (scratch space) for an applet, write to a file called myFile.txt, and print a list of files in the current directory. import com.ms.io.clientstorage.*; import java.io.OutputStream; import java.io.IOException; import java.applet.*; public class MySample extends Applet{ public void outputToScratch() throws IOException { ClientStore s = ClientStorageManager.getStore(); s.createDirectory("myDirectory"); ClientStoreFile oneFile = new ClientStoreFile(s,"MyFile.txt"); long x = oneFile.length(); OutputStream stream1 = oneFile.openOutputStream(); byte buffer1[] = {1,2,3,4,5}; stream1.write(buffer1); stream1.close(); OutputStream appendStream = s.openWritable("myFile.txt",true); byte buffer2[] = {11,12,13,14,15}; appendStream.write(buffer2); appendStream.close(); String fileList[] = s.listFiles(".", ClientStore.LIST_FL_RECURSE); for (int i = 0; i < fileList.length; i++) { System.out.println(fileList[i]); } s.deleteFile("secondFile.txt"); } } After compiling the MySample applet, you would place the compiled file into a cabinet file. You would then sign the file using the signcode tool, specifying a level of security that permits access to client storage. Classes
HierarchyObject | +--ClientStorageManager | +--ClientStore File | +--ClientStoreFile
|
© 1998 Microsoft Corporation. All rights reserved. Terms of use. |