Package org.apache.jmeter.save
Class CSVSaveService
java.lang.Object
org.apache.jmeter.save.CSVSaveService
This class provides a means for saving/reading test results as CSV files.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 linestatic String
Generates the field names for the output filestatic String
printableFieldNamesToString
(SampleSaveConfiguration saveConfig) Generates the field names for the output filestatic void
processSamples
(String filename, Visualizer visualizer, ResultCollector resultCollector) Read Samples from a file; handles quoted strings.static String
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
(List<?> data, FileWriter writer) Method will save aggregate statistics as CSV.static void
saveCSVStats
(List<?> data, FileWriter writer, String[] headers) Method will save aggregate statistics as CSV.static void
saveCSVStats
(DefaultTableModel model, FileWriter writer) Method saves aggregate statistics (with header names) as CSV from a table model.static void
saveCSVStats
(DefaultTableModel model, FileWriter writer, boolean saveHeaders) Method saves aggregate statistics as CSV from a table model.
-
Field Details
-
QUOTING_CHAR
public static final char QUOTING_CHAR- See Also:
-
-
Method Details
-
processSamples
public static void processSamples(String filename, Visualizer visualizer, ResultCollector resultCollector) throws IOException Read Samples from a file; handles quoted strings.- Parameters:
filename
- input filevisualizer
- where to send the resultsresultCollector
- the parent collector- Throws:
IOException
- when the file referenced byfilename
can't be read correctly
-
printableFieldNamesToString
Generates the field names for the output file- Returns:
- the field names as a string
-
printableFieldNamesToString
Generates the field names for the output file- Parameters:
saveConfig
- the configuration of what is to be saved- Returns:
- the field names as a string
-
getSampleSaveConfiguration
public static SampleSaveConfiguration getSampleSaveConfiguration(String headerLine, String filename) Parse a CSV header line- Parameters:
headerLine
- from CSV filefilename
- name of file (for log message only)- Returns:
- config corresponding to the header items found or null if not a header line
-
saveCSVStats
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
- List of data rowswriter
- output file- Throws:
IOException
- when writing towriter
fails
-
saveCSVStats
public static void saveCSVStats(List<?> data, FileWriter writer, String[] 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
- List of data rowswriter
- output fileheaders
- header names (if non-null)- Throws:
IOException
- when writing towriter
fails
-
saveCSVStats
Method saves aggregate statistics (with header names) as CSV from a table model. Same assaveCSVStats(List, FileWriter, String[])
except that there is no need to create a List containing the data.- Parameters:
model
- table model containing the datawriter
- output file- Throws:
IOException
- when writing towriter
fails
-
saveCSVStats
public static void saveCSVStats(DefaultTableModel model, FileWriter writer, boolean saveHeaders) throws IOException Method saves aggregate statistics as CSV from a table model. Same assaveCSVStats(List, FileWriter, String[])
except that there is no need to create a List containing the data.- Parameters:
model
- table model containing the datawriter
- output filesaveHeaders
- whether or not to save headers- Throws:
IOException
- when writing towriter
fails
-
resultToDelimitedString
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
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 converteddelimiter
- the separation string- Returns:
- the separated value representation of the result
-
csvReadFile
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.
A blank line - or a quoted blank line - both return an array containing a single empty String.
- Parameters:
infile
- input file - must support mark(1)delim
- delimiter (e.g. comma)- Returns:
- array of strings, will be empty if there is no data, i.e. if the input is at EOF.
- Throws:
IOException
- also for unexpected quote characters
-
csvSplitString
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 - notnull
delim
- delimiter (e.g. comma)- Returns:
- array of strings
- Throws:
IOException
- also for unexpected quote characters
-