public static String resultToDelimitedString(SampleEvent event,
final String delimiter) {
StringQuoter text = new StringQuoter(delimiter.charAt(0));
SampleResult sample = event.getResult();
SampleSaveConfiguration saveConfig = sample.getSaveConfig();
if (saveConfig.saveTimestamp()) {
if (saveConfig.printMilliseconds()) {
text.append(sample.getTimeStamp());
} else if (saveConfig.formatter() != null) {
String stamp = saveConfig.formatter().format(
new Date(sample.getTimeStamp()));
text.append(stamp);
}
}
if (saveConfig.saveTime()) {
text.append(sample.getTime());
}
if (saveConfig.saveLabel()) {
text.append(sample.getSampleLabel());
}
if (saveConfig.saveCode()) {
text.append(sample.getResponseCode());
}
if (saveConfig.saveMessage()) {
text.append(sample.getResponseMessage());
}
if (saveConfig.saveThreadName()) {
text.append(sample.getThreadName());
}
if (saveConfig.saveDataType()) {
text.append(sample.getDataType());
}
if (saveConfig.saveSuccess()) {
text.append(sample.isSuccessful());
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
String message = null;
AssertionResult[] results = sample.getAssertionResults();
if (results != null) {
// Find the first non-null message
for (int i = 0; i < results.length; i++) {
message = results[i].getFailureMessage();
if (message != null) {
break;
}
}
}
if (message != null) {
text.append(message);
} else {
text.append(""); // Need to append something so delimiter is
// added
}
}
if (saveConfig.saveBytes()) {
text.append(sample.getBytes());
}
if (saveConfig.saveThreadCounts()) {
text.append(sample.getGroupThreads());
text.append(sample.getAllThreads());
}
if (saveConfig.saveUrl()) {
text.append(sample.getURL());
}
if (saveConfig.saveFileName()) {
text.append(sample.getResultFileName());
}
if (saveConfig.saveLatency()) {
text.append(sample.getLatency());
}
if (saveConfig.saveEncoding()) {
text.append(sample.getDataEncodingWithDefault());
}
if (saveConfig.saveSampleCount()) {
// Need both sample and error count to be any use
text.append(sample.getSampleCount());
text.append(sample.getErrorCount());
}
if (saveConfig.saveHostname()) {
text.append(event.getHostname());
}
if (saveConfig.saveIdleTime()) {
text.append(event.getResult().getIdleTime());
}
for (int i = 0; i < SampleEvent.getVarCount(); i++) {
text.append(event.getVarValue(i));