pk.edu.niit.clarens
Class FileMethods

java.lang.Object
  extended bypk.edu.niit.clarens.FileMethods
All Implemented Interfaces:
org.apache.xmlrpc.AuthenticatedXmlRpcHandler

public class FileMethods
extends java.lang.Object
implements org.apache.xmlrpc.AuthenticatedXmlRpcHandler

Handler for xmlrpc "file" methods. Methods implemented include "size", "md5", "read", "stat", "ls", and "grep".


Constructor Summary
FileMethods()
          Trivial constructor.
 
Method Summary
protected  java.lang.Object execute(java.lang.String methodName, java.util.Vector parameters)
          Handle a xmlrpc request with no user information.
 java.lang.Object execute(java.lang.String methodName, java.util.Vector parameters, java.lang.String username, java.lang.String password)
          Handle a xmlrpc request.
 java.util.Vector grep(java.util.Vector arr, java.lang.String input)
          Search a list of files for lines matching a specific pattern.
 java.util.Vector ls(java.lang.String path, java.lang.String pattern)
          Get the contents of a directory.
 java.lang.String md5(java.lang.String fileName)
          Generate a md5 sum for a file.
 java.lang.String read(java.lang.String filename, int offset, int length)
          Read the contents of a file.
 java.lang.String size(java.lang.String filename)
          Get the size of the file.
 java.util.Vector stat(java.lang.String filename)
          Get information about a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileMethods

public FileMethods()
Trivial constructor.

Method Detail

execute

public java.lang.Object execute(java.lang.String methodName,
                                java.util.Vector parameters,
                                java.lang.String username,
                                java.lang.String password)
                         throws java.lang.Exception
Handle a xmlrpc request.

Specified by:
execute in interface org.apache.xmlrpc.AuthenticatedXmlRpcHandler
Parameters:
methodName - The name of the system method being executed.
parameters - The method parameters.
username - The identity of the user performing the execution.
password - The password/key for the user performing the execution.
Returns:
An Vector containing the result.
Throws:
java.lang.Exception - A generic exception is thrown for any errors.

execute

protected java.lang.Object execute(java.lang.String methodName,
                                   java.util.Vector parameters)
                            throws java.lang.Exception
Handle a xmlrpc request with no user information.

Parameters:
methodName - The name of the system method being executed.
parameters - The method parameters.
Returns:
An object containing the result.
Throws:
java.lang.Exception - A generic exception is thrown for any errors.

md5

public java.lang.String md5(java.lang.String fileName)
                     throws java.lang.Exception
Generate a md5 sum for a file.

Parameters:
fileName - The name of the file for which the md5 sum will be calculated.
Returns:
A string representation of the md5 sum.
Throws:
java.lang.Exception - A generic exception is thrown for any errors.

size

public java.lang.String size(java.lang.String filename)
                      throws java.lang.Exception
Get the size of the file.

Parameters:
filename - The name of the file for which the size will be returned.
Returns:
A String representation of the file size, in bytes, followed by the string " Bytes". Example: "1234 Bytes"
Throws:
java.lang.Exception - A generic exception is thrown for any errors.

read

public java.lang.String read(java.lang.String filename,
                             int offset,
                             int length)
                      throws java.lang.Exception
Read the contents of a file.

Parameters:
filename - The name of the file that will be read.
offset - The start offset for reading the file.
length - The number of bytes to read from the file.
Returns:
A String containing the bytes in the file.
Throws:
java.lang.Exception - A generic exception is thrown for any errors.

stat

public java.util.Vector stat(java.lang.String filename)
Get information about a file.

Parameters:
filename - The name of the file to inquiry.
Returns:
A Vector containing 3 values: The file type The file size (as an integer) The file modification date (in seconds)

ls

public java.util.Vector ls(java.lang.String path,
                           java.lang.String pattern)
Get the contents of a directory.

Parameters:
path - The name of the directory on which to perform the listing.
pattern - A glob pattern describing which files to return. An empty pattern is equivalent to the glob pattern "*".
Returns:
A Vector of file information. Each element of the Vector contains another Vector containing the file name, the file size, and the file modification date. The result vector only contains information about files; it will not contain any entries for directories.

grep

public java.util.Vector grep(java.util.Vector arr,
                             java.lang.String input)
Search a list of files for lines matching a specific pattern.

Parameters:
arr - The list of files to search.
input - The input string to search for.
Returns:
A Vector of lines containing the input pattern.