Search in sources :

Example 11 with UnicodeReader

use of uk.ac.sussex.gdsc.core.utils.UnicodeReader in project GDSC-SMLM by aherbert.

the class PeakResultsReader method readRapidStorm.

private MemoryPeakResults readRapidStorm() {
    final MemoryPeakResults results = createResults();
    results.setName(FileUtils.getName(filename));
    try (FileInputStream fis = new FileInputStream(filename);
        BufferedReader input = new BufferedReader(new UnicodeReader(fis, null))) {
        final ProgressReporter reporter = createProgressReporter(fis);
        String line;
        int errors = 0;
        // Skip the header
        while ((line = input.readLine()) != null) {
            if (line.isEmpty()) {
                continue;
            }
            if (line.charAt(0) != '#') {
                // This is the first record
                if (!addRapidStormResult(results, line)) {
                    errors = 1;
                }
                break;
            }
        }
        while ((line = input.readLine()) != null) {
            if (line.isEmpty() || line.charAt(0) == '#') {
                continue;
            }
            if (!addRapidStormResult(results, line) && ++errors >= 10) {
                break;
            }
            reporter.showProgress();
        }
    } catch (final IOException ex) {
        logError(ex);
    }
    return results;
}
Also used : BufferedReader(java.io.BufferedReader) UnicodeReader(uk.ac.sussex.gdsc.core.utils.UnicodeReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 12 with UnicodeReader

use of uk.ac.sussex.gdsc.core.utils.UnicodeReader in project GDSC-SMLM by aherbert.

the class PeakResultsReader method getHeader.

/**
 * Gets the header from the results file.
 *
 * @return The header from the results file
 */
public String getHeader() {
    if (header == null) {
        try (BufferedReader input = new BufferedReader(new UnicodeReader(new FileInputStream(filename), null))) {
            final StringBuilder sb = new StringBuilder();
            String line;
            int count = 0;
            while ((line = input.readLine()) != null) {
                count++;
                if (count == 1) {
                    // line
                    if (line.startsWith("Channel Name")) {
                        sb.append(line).append('\n');
                        break;
                    }
                    // User may try and load the text saved directly from the ImageJ Table Results
                    if (line.contains(IMAGEJ_TABLE_RESULTS_HEADER_V1_V2)) {
                        sb.append(line).append('\n');
                        break;
                    }
                }
                if (line.isEmpty()) {
                    continue;
                }
                if (line.charAt(0) == '#') {
                    sb.append(line).append('\n');
                } else {
                    break;
                }
            }
            header = sb.toString();
            version = getField("FileVersion");
            format = FileFormat.UNKNOWN;
            if (!guessFormatFromVersion()) {
                guessFormat(line);
            }
        } catch (final IOException ex) {
            logError(ex);
        }
    }
    return header;
}
Also used : BufferedReader(java.io.BufferedReader) UnicodeReader(uk.ac.sussex.gdsc.core.utils.UnicodeReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Aggregations

BufferedReader (java.io.BufferedReader)12 UnicodeReader (uk.ac.sussex.gdsc.core.utils.UnicodeReader)12 IOException (java.io.IOException)11 FileInputStream (java.io.FileInputStream)10 GenericDialog (ij.gui.GenericDialog)3 File (java.io.File)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Pattern (java.util.regex.Pattern)2 Nullable (uk.ac.sussex.gdsc.core.annotation.Nullable)2 CalibrationWriter (uk.ac.sussex.gdsc.smlm.data.config.CalibrationWriter)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 JsonFormat (com.google.protobuf.util.JsonFormat)1 NonBlockingGenericDialog (ij.gui.NonBlockingGenericDialog)1 Dimension (java.awt.Dimension)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 Panel (java.awt.Panel)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1