use of org.apache.jmeter.visualizers.Visualizer in project jmeter by apache.
the class ResultCollector method loadExistingFile.
/**
* Loads an existing sample data (JTL) file.
* This can be one of:
* <ul>
* <li>XStream format</li>
* <li>CSV format</li>
* </ul>
*
*/
public void loadExistingFile() {
final Visualizer visualizer = getVisualizer();
if (visualizer == null) {
// No point reading the file if there's no visualiser
return;
}
boolean parsedOK = false;
String filename = getFilename();
File file = new File(filename);
if (file.exists()) {
try (FileReader fr = new FileReader(file);
BufferedReader dataReader = new BufferedReader(fr, 300)) {
// Get the first line, and see if it is XML
String line = dataReader.readLine();
dataReader.close();
if (line == null) {
log.warn("{} is empty", filename);
} else {
if (!line.startsWith("<?xml ")) {
// No, must be CSV //$NON-NLS-1$
CSVSaveService.processSamples(filename, visualizer, this);
parsedOK = true;
} else {
// We are processing XML
try (FileInputStream fis = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(fis)) {
// Assume XStream
SaveService.loadTestResults(bufferedInputStream, new ResultCollectorHelper(this, visualizer));
parsedOK = true;
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Failed to load {} using XStream. Error was: {}", filename, e.toString());
}
}
}
}
} catch (IOException | JMeterError | RuntimeException | OutOfMemoryError e) {
// FIXME Why do we catch OOM ?
log.warn("Problem reading JTL file: {}", file);
} finally {
if (!parsedOK) {
GuiPackage.showErrorMessage("Error loading results file - see log file", "Result file loader");
}
}
} else {
GuiPackage.showErrorMessage("Error loading results file - could not open file", "Result file loader");
}
}
Aggregations