Search in sources :

Example 1 with Visualizer

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");
    }
}
Also used : IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) JMeterError(org.apache.jorphan.util.JMeterError) BufferedInputStream(java.io.BufferedInputStream) BufferedReader(java.io.BufferedReader) Visualizer(org.apache.jmeter.visualizers.Visualizer) FileReader(java.io.FileReader) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 RandomAccessFile (java.io.RandomAccessFile)1 Visualizer (org.apache.jmeter.visualizers.Visualizer)1 JMeterError (org.apache.jorphan.util.JMeterError)1