Packages
 In this topic

*Overview of Classes

*Example

*Classes

*Hierarchy

 

Packages   PackagesNext
Package com.ms.io.clientstorage   Packages Next

 


About com.ms.io.clientstorage

The 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 Classes

The 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.

Flag Name Accessibility Type
STORE_FL_ROAMING The file is accessible to the user from any computer.
STORE_FL_LOCAL The file is found in a computer-specific local storage area.
OPEN_FL_SHARED The file is accessible to the user and to other authorized principals.
OPEN_FL_APPEND When writing to a file, append to the file if it exists; otherwise, open a new file for writing.
OPEN_FL_EXPENDABLE When the storage area is full, the file is automatically deleted if the deletion will help satisfy a new request.
OPEN_FL_WRITABLE The file is opened with write access.

Example

The 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

Class ClientStorageManager
This class manages the allocation of client stores.
Class ClientStore
This class helps manage client storage by enforcing storage limitations and providing access to client stores.
Class ClientStoreFile
This class manages and provides access to individual files within client stores.

Hierarchy

Object
  |
  +--ClientStorageManager
  |
  +--ClientStore

File
  |
  +--ClientStoreFile

upnrm.gif © 1998 Microsoft Corporation. All rights reserved. Terms of use.