Class CSVSaveService
-
- All Implemented Interfaces:
public final class CSVSaveService
This class provides a means for saving/reading test results as CSV files.
-
-
Field Summary
Fields Modifier and Type Field Description public final static String
DATA_TYPE
public final static String
FAILURE_MESSAGE
public final static String
LABEL
public final static String
RESPONSE_CODE
public final static String
RESPONSE_MESSAGE
public final static String
SUCCESSFUL
public final static String
THREAD_NAME
public final static String
TIME_STAMP
public final static String
CSV_ELAPSED
public final static String
CSV_BYTES
public final static String
CSV_SENT_BYTES
public final static String
CSV_THREAD_COUNT1
public final static String
CSV_THREAD_COUNT2
public final static String
CSV_SAMPLE_COUNT
public final static String
CSV_ERROR_COUNT
public final static String
CSV_URL
public final static String
CSV_FILENAME
public final static String
CSV_LATENCY
public final static String
CSV_CONNECT_TIME
public final static String
CSV_ENCODING
public final static String
CSV_HOSTNAME
public final static String
CSV_IDLETIME
public final static String
VARIABLE_NAME_QUOTE_CHAR
public final static char
QUOTING_CHAR
-
Method Summary
Modifier and Type Method Description static void
processSamples(String filename, Visualizer visualizer, ResultCollector resultCollector)
Read Samples from a file; handles quoted strings. 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 SampleSaveConfiguration
getSampleSaveConfiguration(String headerLine, String filename)
Parse a CSV header line static void
saveCSVStats(List<out Object> data, Writer writer)
Method will save aggregate statistics as CSV. static void
saveCSVStats(List<out Object> data, Writer writer, Array<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. 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 String
resultToDelimitedString(SampleEvent event, SampleResult sample, SampleSaveConfiguration saveConfig, String delimiter)
Convert a result into a string, where the fields of the result are separated by a specified String. static String
quoteDelimiters(String input, Array<char> specialChars)
Returns a String
value for a character-delimited column value enclosed in the quote character, if required.static Array<String>
csvReadFile(BufferedReader infile, char delim)
Reads from file and splits input into strings according to the delimiter, taking note of quoted strings. static Array<String>
csvSplitString(String line, char delim)
Reads from String and splits into strings according to the delimiter, taking note of quoted strings. static void
saveSampleResult(SampleEvent event, PrintWriter out)
-
-
Method Detail
-
processSamples
static void processSamples(String filename, Visualizer visualizer, ResultCollector resultCollector)
Read Samples from a file; handles quoted strings.
- Parameters:
filename
- input filevisualizer
- where to send the resultsresultCollector
- the parent collector
-
printableFieldNamesToString
static String printableFieldNamesToString()
Generates the field names for the output file
- Returns:
the field names as a string
-
printableFieldNamesToString
static String printableFieldNamesToString(SampleSaveConfiguration saveConfig)
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
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
static void saveCSVStats(List<out Object> data, Writer writer)
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 writer
-
saveCSVStats
static void saveCSVStats(List<out Object> data, Writer writer, Array<String> headers)
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)
-
saveCSVStats
static void saveCSVStats(DefaultTableModel model, FileWriter writer)
Method saves aggregate statistics (with header names) as CSV from a table model. Same as saveCSVStats except that there is no need to create a List containing the data.
- Parameters:
model
- table model containing the datawriter
- output file
-
saveCSVStats
static void saveCSVStats(DefaultTableModel model, FileWriter writer, boolean saveHeaders)
Method saves aggregate statistics as CSV from a table model. Same as saveCSVStats 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
-
resultToDelimitedString
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
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 converteddelimiter
- the separation string- Returns:
the separated value representation of the result
-
resultToDelimitedString
static String resultToDelimitedString(SampleEvent event, SampleResult sample, SampleSaveConfiguration saveConfig, 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 convertedsample
- SampleResult to logsaveConfig
- SampleSaveConfiguration to use for loggingdelimiter
- the separation string- Returns:
the separated value representation of the result
-
quoteDelimiters
static String quoteDelimiters(String input, Array<char> specialChars)
Returns a
String
value for a character-delimited column value enclosed in the quote character, if required.If the value contains a special character, then the String value is returned enclosed in the quote character.
Any quote characters in the value are doubled up.
If the value does not contain any special characters, then the String value is returned unchanged.
N.B. The list of special characters includes the quote character.
- Parameters:
input
- the input column String, may be null (without enclosing delimiters)specialChars
- special characters; second one must be the quote character- Returns:
the input String, enclosed in quote characters if the value contains a special character,
null
for null string input
-
csvReadFile
static Array<String> csvReadFile(BufferedReader infile, char delim)
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.- Returns:
array of strings, will be empty if there is no data, i.e. if the input is at EOF.
-
csvSplitString
static Array<String> csvSplitString(String line, char delim)
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.- Returns:
array of strings
-
saveSampleResult
static void saveSampleResult(SampleEvent event, PrintWriter out)
- Parameters:
event
- SampleEventout
- PrintWriter to which samples will be written
-
-
-
-