Project JXTA

net.jxta.impl.cm
Class Cm

java.lang.Object
  |
  +--net.jxta.impl.cm.Cm

public final class Cm
extends java.lang.Object

This class implements a limited document storing mechanism intended to provide a mean for DiscoveryService, ResolverService, PipeResolver and Cache services to search and exchange documents over the group. Only Core Services are intended to use this mechanism, the security relies on the generic PeerGroup security service. XXX: this need to be optimized


Field Summary
static boolean debug
           
static java.lang.String PrivateDirName
           
static java.lang.String PublicDirName
           
static java.lang.String RootDirBase
           
static java.lang.String TmpDirName
           
 
Constructor Summary
Cm()
          Makes a temporary storage area with a unique name.
Cm(java.lang.String areaName)
           
 
Method Summary
 void cleanupFolder(java.lang.String dn)
          Returns true if the directory exists
 void createFolder(java.lang.String f)
          Creates a new folder.
static java.lang.String createTmpName()
          Generates a random file name
static java.lang.String createTmpName(net.jxta.document.StructuredDocument doc)
          Generates a random file name using doc hashcode
 boolean exists(java.lang.String dn, java.lang.String fn)
          Tests if a file does exist
 java.lang.String[] getFileNames(java.lang.String dn)
          Gets the list of all the files into the given folder
 java.io.FileInputStream getInputStream(java.lang.String dn, java.lang.String fn)
           
 java.lang.String getOldestFile(java.lang.String dn)
          Returns the name of the oldest file in a given directory
 boolean isFolder(java.lang.String dn)
          Returns true if the directory exists
 void publish(net.jxta.document.StructuredDocument doc)
          Publish a document that can be searched by other peers.
 void publish(net.jxta.document.StructuredDocument doc, java.lang.String fn)
           
 void remove(java.lang.String dn, java.lang.String fn)
          Remove a file
 net.jxta.document.StructuredDocument restore(java.lang.String dn, java.lang.String fn)
          Restore a saved file
 byte[] restoreBytes(java.lang.String dn, java.lang.String fn)
           
 void save(java.lang.String dn, java.lang.String fn, net.jxta.document.StructuredDocument doc)
          Saves a StructuredDocument into a folder
 void saveBytes(java.lang.String dn, java.lang.String fn, byte[] buffer)
           
 java.util.Enumeration search(java.lang.String dn, java.lang.String tag, java.lang.String value)
          Search and recovers documents that contains at least a mathing pair of tag/value.
 java.util.Enumeration searchLocal(java.lang.String dn, java.lang.String tag, java.lang.String value)
          Search and recovers documents that contains at least a mathing pair of tag/value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug

RootDirBase

public static final java.lang.String RootDirBase

PublicDirName

public static final java.lang.String PublicDirName

PrivateDirName

public static final java.lang.String PrivateDirName

TmpDirName

public static final java.lang.String TmpDirName
Constructor Detail

Cm

public Cm()
Makes a temporary storage area with a unique name.

Cm

public Cm(java.lang.String areaName)
Method Detail

createFolder

public void createFolder(java.lang.String f)
                  throws java.io.IOException
Creates a new folder. Note that this function is idempotent.
Parameters:
f - contains the name of the new folder
Throws:
java.io.IOException - when the folder creation failed.

createTmpName

public static java.lang.String createTmpName()
Generates a random file name
Returns:
String a random file name

createTmpName

public static java.lang.String createTmpName(net.jxta.document.StructuredDocument doc)
Generates a random file name using doc hashcode
Parameters:
doc - to hash to generate a unique name
Returns:
String a random file name

remove

public void remove(java.lang.String dn,
                   java.lang.String fn)
            throws java.io.IOException
Remove a file
Parameters:
dn - contains the name of the folder
fn - contains the name of the file
Throws:
java.io.IOException - when removing failed

exists

public boolean exists(java.lang.String dn,
                      java.lang.String fn)
               throws java.io.IOException
Tests if a file does exist
Parameters:
dn - contains the name of the folder
fn - contains the name of the file
Throws:
java.io.IOException - when removing failed

restore

public net.jxta.document.StructuredDocument restore(java.lang.String dn,
                                                    java.lang.String fn)
                                             throws java.io.IOException
Restore a saved file
Parameters:
dn - contains the name of the folder
fn - contains the name of the file
Returns:
StructuredDocument containing the file
Throws:
java.io.IOException - when reading was not possible

restoreBytes

public byte[] restoreBytes(java.lang.String dn,
                           java.lang.String fn)
                    throws java.io.IOException

save

public void save(java.lang.String dn,
                 java.lang.String fn,
                 net.jxta.document.StructuredDocument doc)
          throws java.io.IOException
Saves a StructuredDocument into a folder
Parameters:
dn - contains the name of the folder
fn - contains the name of the file
doc - contains the StructuredDocument to save
Throws:
java.io.IOException - when saving failed.

saveBytes

public void saveBytes(java.lang.String dn,
                      java.lang.String fn,
                      byte[] buffer)
               throws java.io.IOException

getFileNames

public java.lang.String[] getFileNames(java.lang.String dn)
Gets the list of all the files into the given folder
Parameters:
dn - contains the name of the folder
Returns:
String[] an array of Strings containing the name of the files

getOldestFile

public java.lang.String getOldestFile(java.lang.String dn)
Returns the name of the oldest file in a given directory
Parameters:
dn - contains the name of the folder
Returns:
String returns the name of the oldest file

isFolder

public boolean isFolder(java.lang.String dn)
Returns true if the directory exists
Parameters:
dn - contains the name of the folder
Returns:
boolean

cleanupFolder

public void cleanupFolder(java.lang.String dn)
                   throws java.io.IOException
Returns true if the directory exists
Parameters:
dn - contains the name of the folder
Returns:
boolean

search

public java.util.Enumeration search(java.lang.String dn,
                                    java.lang.String tag,
                                    java.lang.String value)
Search and recovers documents that contains at least a mathing pair of tag/value.
Parameters:
dn - contains the name of the folder on which to perform the search
tag - contains the name of the tag on which to search on
value - contains the value to search on.
Returns:
Enumeration an enumeration of all the documents that have been found.

publish

public void publish(net.jxta.document.StructuredDocument doc)
Publish a document that can be searched by other peers.
Parameters:
doc - is a StructuredDocument to be published

publish

public void publish(net.jxta.document.StructuredDocument doc,
                    java.lang.String fn)

searchLocal

public java.util.Enumeration searchLocal(java.lang.String dn,
                                         java.lang.String tag,
                                         java.lang.String value)
Search and recovers documents that contains at least a mathing pair of tag/value.
Parameters:
tag - contains the name of the tag on which to search on
value - contains the value to search on.
Returns:
Enumeration an enumeration of all the documents that have been found.

getInputStream

public java.io.FileInputStream getInputStream(java.lang.String dn,
                                              java.lang.String fn)
                                       throws java.io.IOException

Project JXTA