Apache JMeter

org.apache.jmeter.services
Class FileServer

java.lang.Object
  extended by org.apache.jmeter.services.FileServer

public class FileServer
extends java.lang.Object

The point of this class is to provide thread-safe access to files, and to provide some simplifying assumptions about where to find files and how to name them. For instance, putting supporting files in the same directory as the saved test plan file allows users to refer to the file with just it's name - this FileServer class will find the file without a problem. Eventually, I want all in-test file access to be done through here, with the goal of packaging up entire test plans as a directory structure that can be sent via rmi to remote servers (currently, one must make sure the remote server has all support files in a relative-same location) and to package up test plans to execute on unknown boxes that only have Java installed.


Method Summary
 void closeFile(java.lang.String name)
           
 void closeFiles()
           
protected  boolean filesOpen()
           
 java.lang.String getBaseDir()
           
static FileServer getFileServer()
           
 java.io.File getRandomFile(java.lang.String basedir, java.lang.String[] extensions)
          Method will get a random file in a base directory TODO hey, not sure this method belongs here.
 java.lang.String readLine(java.lang.String filename)
          Get the next line of the named file, recycle by default.
 java.lang.String readLine(java.lang.String filename, boolean recycle)
          Get the next line of the named file.
 void reserveFile(java.lang.String filename)
          Creates an association between a filename and a File inputOutputObject, and stores it for later use - unless it is already stored.
 void reserveFile(java.lang.String filename, java.lang.String charsetName)
          Creates an association between a filename and a File inputOutputObject, and stores it for later use - unless it is already stored.
 void reserveFile(java.lang.String filename, java.lang.String charsetName, java.lang.String alias)
          Creates an association between a filename and a File inputOutputObject, and stores it for later use - unless it is already stored.
 void resetBase()
           
 void setBasedir(java.lang.String basedir)
           
 void write(java.lang.String filename, java.lang.String value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFileServer

public static FileServer getFileServer()

resetBase

public void resetBase()
               throws java.io.IOException
Throws:
java.io.IOException

setBasedir

public void setBasedir(java.lang.String basedir)
                throws java.io.IOException
Throws:
java.io.IOException

getBaseDir

public java.lang.String getBaseDir()

reserveFile

public void reserveFile(java.lang.String filename)
Creates an association between a filename and a File inputOutputObject, and stores it for later use - unless it is already stored.

Parameters:
filename - - relative (to base) or absolute file name (must not be null)

reserveFile

public void reserveFile(java.lang.String filename,
                        java.lang.String charsetName)
Creates an association between a filename and a File inputOutputObject, and stores it for later use - unless it is already stored.

Parameters:
filename - - relative (to base) or absolute file name (must not be null)
charsetName - - the character set encoding to use for the file (may be null)

reserveFile

public void reserveFile(java.lang.String filename,
                        java.lang.String charsetName,
                        java.lang.String alias)
Creates an association between a filename and a File inputOutputObject, and stores it for later use - unless it is already stored.

Parameters:
filename - - relative (to base) or absolute file name (must not be null)
charsetName - - the character set encoding to use for the file (may be null)
alias - - the name to be used to access the object (must not be null)

readLine

public java.lang.String readLine(java.lang.String filename)
                          throws java.io.IOException
Get the next line of the named file, recycle by default.

Parameters:
filename -
Returns:
String containing the next line in the file
Throws:
java.io.IOException

readLine

public java.lang.String readLine(java.lang.String filename,
                                 boolean recycle)
                          throws java.io.IOException
Get the next line of the named file.

Parameters:
filename -
recycle - - should file be restarted at EOF?
Returns:
String containing the next line in the file (null if EOF reached and not recycle)
Throws:
java.io.IOException

write

public void write(java.lang.String filename,
                  java.lang.String value)
           throws java.io.IOException
Throws:
java.io.IOException

closeFiles

public void closeFiles()
                throws java.io.IOException
Throws:
java.io.IOException

closeFile

public void closeFile(java.lang.String name)
               throws java.io.IOException
Parameters:
name -
Throws:
java.io.IOException

filesOpen

protected boolean filesOpen()

getRandomFile

public java.io.File getRandomFile(java.lang.String basedir,
                                  java.lang.String[] extensions)
Method will get a random file in a base directory TODO hey, not sure this method belongs here. FileServer is for threadsafe File access relative to current test's base directory.

Parameters:
basedir -
Returns:
a random File from the basedir that matches one of the extensions

Apache JMeter

Copyright © 1998-2010 Apache Software Foundation. All Rights Reserved.