public class FileServer
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
closeFile(java.lang.String name) |
void |
closeFiles() |
java.lang.String |
getBaseDir() |
java.io.File |
getBaseDirRelative()
Calculates the relative path from DEFAULT_BASE to the current base,
which must be the same as or a child of the default.
|
static java.lang.String |
getDefaultBase() |
static FileServer |
getFileServer() |
java.lang.String[] |
getParsedLine(java.lang.String alias,
boolean recycle,
boolean ignoreFirstLine,
char delim) |
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.io.File |
getResolvedFile(java.lang.String path)
Get
File instance for provided file path,
resolve file location relative to base dir or script dir when needed |
java.lang.String |
getScriptName() |
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, first line is name to false
|
java.lang.String |
readLine(java.lang.String filename,
boolean recycle,
boolean ignoreFirstLine)
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.
|
java.lang.String |
reserveFile(java.lang.String filename,
java.lang.String charsetName,
java.lang.String alias,
boolean hasHeader)
Creates an association between a filename and a File inputOutputObject,
and stores it for later use - unless it is already stored.
|
void |
resetBase()
Resets the current base to DEFAULT_BASE.
|
static java.lang.String |
resolveBaseRelativeName(java.lang.String relativeName)
Resolve a file name that may be relative to the base directory.
|
void |
setBase(java.io.File jmxBase)
Sets the current base directory for relative file names.
|
void |
setBasedir(java.lang.String basedir)
Sets the current base directory for relative file names from the provided path.
|
void |
setBaseForScript(java.io.File scriptPath)
Sets the current base directory for relative file names from the provided script file.
|
void |
setScriptName(java.lang.String scriptName) |
void |
write(java.lang.String filename,
java.lang.String value) |
public static FileServer getFileServer()
public void resetBase()
public void setBasedir(java.lang.String basedir)
basedir
- the path to set, or null
if the GUI is being clearedjava.lang.IllegalStateException
- if files are still openpublic void setBaseForScript(java.io.File scriptPath)
scriptPath
- the path of the script file; must be not be null
java.lang.IllegalStateException
- if files are still openjava.lang.IllegalArgumentException
- if scriptPath parameter is nullpublic void setBase(java.io.File jmxBase)
jmxBase
- the path of the script file base directory, cannot be nulljava.lang.IllegalStateException
- if files are still openjava.lang.IllegalArgumentException
- if basepath
is nullpublic java.lang.String getBaseDir()
public static java.lang.String getDefaultBase()
public java.io.File getBaseDirRelative()
"."
if the path cannot be determinedpublic void reserveFile(java.lang.String filename)
filename
- - relative (to base) or absolute file name (must not be null)public void reserveFile(java.lang.String filename, java.lang.String charsetName)
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)public void reserveFile(java.lang.String filename, java.lang.String charsetName, java.lang.String alias)
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)public java.lang.String reserveFile(java.lang.String filename, java.lang.String charsetName, java.lang.String alias, boolean hasHeader)
filename
- - relative (to base) or absolute file name (must not be null or empty)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)hasHeader
- true if the file has a header line describing the contentsjava.lang.IllegalArgumentException
- if header could not be read or filename is null or emptypublic java.lang.String readLine(java.lang.String filename) throws java.io.IOException
filename
- the filename or alias that was used to reserve the filejava.io.IOException
- when reading of the file fails, or the file was not reserved properlypublic java.lang.String readLine(java.lang.String filename, boolean recycle) throws java.io.IOException
filename
- the filename or alias that was used to reserve the filerecycle
- - should file be restarted at EOF?java.io.IOException
- when reading of the file fails, or the file was not reserved properlypublic java.lang.String readLine(java.lang.String filename, boolean recycle, boolean ignoreFirstLine) throws java.io.IOException
filename
- the filename or alias that was used to reserve the filerecycle
- - should file be restarted at EOF?ignoreFirstLine
- - Ignore first linejava.io.IOException
- when reading of the file fails, or the file was not reserved properlypublic java.lang.String[] getParsedLine(java.lang.String alias, boolean recycle, boolean ignoreFirstLine, char delim) throws java.io.IOException
alias
- the file name or aliasrecycle
- whether the file should be re-started on EOFignoreFirstLine
- whether the file contains a file header which will be ignoreddelim
- the delimiter to use for parsingjava.io.IOException
- when reading of the aliased file fails, or the file was not reserved properlypublic void write(java.lang.String filename, java.lang.String value) throws java.io.IOException
java.io.IOException
public void closeFiles() throws java.io.IOException
java.io.IOException
public void closeFile(java.lang.String name) throws java.io.IOException
name
- the name or alias of the file to be closedjava.io.IOException
- when closing of the aliased file failspublic java.io.File getRandomFile(java.lang.String basedir, java.lang.String[] extensions)
TODO hey, not sure this method belongs here. FileServer is for thread safe File access relative to current test's base directory.
basedir
- name of the directory in which the files can be foundextensions
- array of allowed extensions, if null
is given,
any file be allowedbasedir
that matches one of
the extensionspublic java.io.File getResolvedFile(java.lang.String path)
File
instance for provided file path,
resolve file location relative to base dir or script dir when neededpath
- original path to file, maybe relativeFile
instancepublic static java.lang.String resolveBaseRelativeName(java.lang.String relativeName)
relativeName
- filename that should be checked for
jmeter.save.saveservice.base_prefix
public java.lang.String getScriptName()
public void setScriptName(java.lang.String scriptName)
scriptName
- Script nameCopyright © 1998-2019 Apache Software Foundation. All Rights Reserved.