org.apache.jmeter.save

Class CSVSaveService


public final class CSVSaveService
extends Object

This class provides a means for saving/reading test results as CSV files.

Field Summary

static char
QUOTING_CHAR

Method Summary

static String[]
csvReadFile(BufferedReader infile, char delim)
Reads from file and splits input into strings according to the delimiter, taking note of quoted strings.
static String[]
csvSplitString(String line, char delim)
Reads from String and splits into strings according to the delimiter, taking note of quoted strings.
static SampleSaveConfiguration
getSampleSaveConfiguration(String headerLine, String filename)
Parse a CSV header line
static SampleEvent
makeResultFromDelimitedString(String inputLine, SampleSaveConfiguration saveConfig, long lineNumber)
Deprecated. Does not handle quoted strings; use processSamples(String,Visualizer,ResultCollector) instead
static String
printableFieldNamesToString()
Generates the field names for the output file
static String
printableFieldNamesToString(SampleSaveConfiguration saveConfig)
Generates the field names for the output file
static void
processSamples(String filename, Visualizer visualizer, ResultCollector resultCollector)
Read Samples from a file; handles quoted strings.
static String
resultToDelimitedString(SampleEvent event)
Convert a result into a string, where the fields of the result are separated by the default delimiter.
static String
resultToDelimitedString(SampleEvent event, String delimiter)
Convert a result into a string, where the fields of the result are separated by a specified String.
static void
saveCSVStats(DefaultTableModel model, FileWriter writer)
Method saves aggregate statistics as CSV from a table model.
static void
saveCSVStats(Vector data, FileWriter writer)
Method will save aggregate statistics as CSV.
static void
saveCSVStats(Vector data, FileWriter writer, headers[] )
Method will save aggregate statistics as CSV.

Field Details

QUOTING_CHAR

public static final char QUOTING_CHAR
Field Value:
'\"'

Method Details

csvReadFile

public static String[] csvReadFile(BufferedReader infile,
                                   char delim)
            throws IOException
Reads from file and splits input into strings according to the delimiter, taking note of quoted strings.

Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally.

N.B. a blank line is returned as a zero length array, whereas "" is returned as an empty string. This is inconsistent.

Parameters:
infile - input file - must support mark(1)
delim - delimiter (e.g. comma)
Returns:
array of strings

csvSplitString

public static String[] csvSplitString(String line,
                                      char delim)
            throws IOException
Reads from String and splits into strings according to the delimiter, taking note of quoted strings. Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally.
Parameters:
line - input line
delim - delimiter (e.g. comma)
Returns:
array of strings

getSampleSaveConfiguration

public static SampleSaveConfiguration getSampleSaveConfiguration(String headerLine,
                                                                 String filename)
Parse a CSV header line
Parameters:
headerLine - from CSV file
filename - name of file (for log message only)
Returns:
config corresponding to the header items found or null if not a header line

makeResultFromDelimitedString

public static SampleEvent makeResultFromDelimitedString(String inputLine,
                                                        SampleSaveConfiguration saveConfig,
                                                        long lineNumber)

Deprecated. Does not handle quoted strings; use processSamples(String,Visualizer,ResultCollector) instead

Make a SampleResult given a delimited string.
Parameters:
inputLine - - line from CSV file
saveConfig - - configuration
lineNumber - - line number for error reporting
Returns:
SampleResult

printableFieldNamesToString

public static String printableFieldNamesToString()
Generates the field names for the output file
Returns:
the field names as a string

printableFieldNamesToString

public static String printableFieldNamesToString(SampleSaveConfiguration saveConfig)
Generates the field names for the output file
Returns:
the field names as a string

processSamples

public static void processSamples(String filename,
                                  Visualizer visualizer,
                                  ResultCollector resultCollector)
            throws IOException
Read Samples from a file; handles quoted strings.
Parameters:
filename - input file
visualizer - where to send the results
resultCollector - the parent collector

resultToDelimitedString

public static String resultToDelimitedString(SampleEvent event)
Convert a result into a string, where the fields of the result are separated by the default delimiter.
Parameters:
event - the sample event to be converted
Returns:
the separated value representation of the result

resultToDelimitedString

public static String resultToDelimitedString(SampleEvent event,
                                             String delimiter)
Convert a result into a string, where the fields of the result are separated by a specified String.
Parameters:
event - the sample event to be converted
delimiter - the separation string
Returns:
the separated value representation of the result

saveCSVStats

public static void saveCSVStats(DefaultTableModel model,
                                FileWriter writer)
            throws IOException
Method saves aggregate statistics as CSV from a table model. Same as saveCSVStats(Vector, FileWriter, String[]) except that there is no need to create a Vector containing the data.
Parameters:
model - table model containing the data
writer - output file

saveCSVStats

public static void saveCSVStats(Vector data,
                                FileWriter writer)
            throws IOException
Method will save aggregate statistics as CSV. For now I put it here. Not sure if it should go in the newer SaveService instead of here. if we ever decide to get rid of this class, we'll need to move this method to the new save service.
Parameters:
data - vector of data rows
writer - output file

saveCSVStats

public static void saveCSVStats(Vector data,
                                FileWriter writer,
                                headers[] )
            throws IOException
Method will save aggregate statistics as CSV. For now I put it here. Not sure if it should go in the newer SaveService instead of here. if we ever decide to get rid of this class, we'll need to move this method to the new save service.
Parameters:
data - vector of data rows
writer - output file

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