loci.formats.in

## Class TextReader

- java.lang.Object
- - loci.formats.FormatHandler
  - - loci.formats.FormatReader
    - - loci.formats.in.TextReader

- All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ICompressedTileReader, IFormatHandler, IFormatReader, IMetadataConfigurable, IPyramidHandler

      public class TextReader
      extends FormatReader

  Reader for text files containing tables of data. All image planes are stored in memory as 32-bit floats until the file is closed, so very large text documents will require commensurate available RAM. Text format is flexible, but assumed to be in tabular form with a consistent number of columns, and a labeled header line immediately preceding the data.
  Author:
    Curtis Rueden ctrueden at wisc.edu

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private java.lang.String[]` | `channels` List of channel labels.
    `private float[][]` | `data` Because we have no way of indexing into the text file efficiently in general, we cheat and store the entire file's data in a giant array.
    `private static java.lang.String` | `LABEL_X`
    `private static java.lang.String` | `LABEL_Y`
    `private static boolean` | `LITTLE_ENDIAN`
    `private int` | `row` Current row number.
    `private int` | `rowLength` Number of tokens per row.
    `private int` | `sizeX` Image width.
    `private int` | `sizeY` Image height.
    `private static long` | `TIME_OFFSET` How often to report progress during initialization, in milliseconds.
    `private int` | `xIndex` Column index for X coordinate.
    `private int` | `yIndex` Column index for Y coordinate.

    - ### Fields inherited from class loci.formats.FormatReader

      `core, coreIndex, datasetDescription, domains, fillColor, filterMetadata, flattenedResolutions, group, hasCompanionFiles, in, indexedAsRGB, metadata, metadataStore, normalizeData, resolution, saveOriginalMetadata, series, suffixNecessary, suffixSufficient, THUMBNAIL_DIMENSION`

    - ### Fields inherited from class loci.formats.FormatHandler

      `COMPRESSION_SUFFIXES, currentId, format, LOGGER, metadataOptions, suffixes`

    - ### Fields inherited from interface loci.formats.IFormatReader

      `CAN_GROUP, CANNOT_GROUP, MUST_GROUP`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextReader()` Constructs a new text reader.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `private void` | `assignValues(double[] rowData)` Assigns values from the given row into the data array.
    `private long` | `checkTime(long time, int no, long pos, long len)`
    `void` | `close(boolean fileOnly)` Closes the currently open file.
    `java.lang.String` | `getChannelLabel(int c)` Gets the label for the given channel.
    `java.lang.Class<?>` | `getNativeDataType()` Returns the native data type of image planes for this reader, as returned by `IFormatReader.openPlane(int, int, int, int, int)` or `IFormatWriter.savePlane(int, java.lang.Object)`.
    `private java.lang.String[]` | `getNextLine(java.util.List<java.lang.String> lines)`
    `private boolean` | `getRowData(java.lang.String[] tokens, double[] rowData)` Parses numerical row data from the given tokens.
    `private int` | `getX(double[] rowData)`
    `private int` | `getY(double[] rowData)`
    `protected void` | `initFile(java.lang.String id)` Initializes the given file (parsing header information, etc.).
    `boolean` | `isThisType(loci.common.RandomAccessInputStream stream)` Checks if the given stream is a valid stream for this file format.
    `byte[]` | `openBytes(int no, byte[] buf, int x, int y, int w, int h)` Obtains a sub-image of the specified image plane into a pre-allocated byte array.
    `java.lang.Object` | `openPlane(int no, int x, int y, int w, int h)` Obtains the specified image plane (or sub-image thereof) in the reader's native data structure.
    `private int` | `parseFileHeader(java.util.List<java.lang.String> lines)` Parses the file looking for the file header.
    `private void` | `parseHeaderRow(java.lang.String[] tokens)` Populates rowLength, xIndex, yIndex, and channels.
    `private void` | `parseTableData(java.util.List<java.lang.String> lines, int linesToSkip)` Reads the tabular data into the data array.
    `private void` | `populateCoreMetadata(int sizeX, int sizeY, int sizeZ, int sizeC, int sizeT)` Populates the `CoreMetadata` values.
    `private java.util.List<java.lang.String>` | `readFile(java.lang.String id)`

    - ### Methods inherited from class loci.formats.FormatReader

      `addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMeta, addGlobalMetaList, addMeta, addMetaList, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMeta, addSeriesMetaList, close, coreIndexToSeries, fileGroupOption, flattenHashtables, get16BitLookupTable, get8BitLookupTable, getAcquisitionMode, getAdvancedSeriesUsedFiles, getAdvancedUsedFiles, getArcType, getAvailableOptions, getBinning, getBitsPerPixel, getCompression, getContrastMethod, getCoreIndex, getCoreMetadataList, getCorrection, getCurrentCore, getCurrentFile, getDatasetStructureDescription, getDetectorType, getDimensionOrder, getDimensionOrder, getDomains, getEffectiveSizeC, getExperimentType, getFilamentType, getFillColor, getFillRule, getFilterType, getFontFamily, getFontStyle, getGlobalMeta, getGlobalMetadata, getIlluminationType, getImageCount, getImmersion, getIndex, getIndex, getLaserMedium, getLaserType, getMarker, getMedium, getMetadataStore, getMetadataStoreRoot, getMetadataValue, getMicrobeamManipulationType, getMicroscopeType, getModuloC, getModuloT, getModuloZ, getNamingConvention, getOptimalTileHeight, getOptimalTileWidth, getPixelType, getPixelType, getPossibleDomains, getPulse, getRequiredDirectories, getResolution, getResolutionCount, getRGBChannelCount, getRotationTransform, getSeries, getSeriesCount, getSeriesMeta, getSeriesMetadata, getSeriesMetadataValue, getSeriesUsedFiles, getSeriesUsedFiles, getSizeC, getSizeT, getSizeX, getSizeY, getSizeZ, getThumbSizeX, getThumbSizeY, getTileColumns, getTileRows, getUnderlyingReaders, getUsedFiles, getUsedFiles, getZCTCoords, getZCTModuloCoords, hasCompanionFiles, hasFlattenedResolutions, isFalseColor, isGroupFiles, isIndexed, isInterleaved, isInterleaved, isLittleEndian, isMetadataComplete, isMetadataFiltered, isNormalized, isOrderCertain, isOriginalMetadataPopulated, isRGB, isSingleFile, isThisType, isThisType, isThisType, isThumbnailSeries, isUsedFile, makeFilterMetadata, openBytes, openBytes, openBytes, openThumbBytes, readPlane, readPlane, readPlane, reopenFile, seriesToCoreIndex, setCoreIndex, setFillColor, setFlattenedResolutions, setGroupFiles, setId, setMetadataFiltered, setMetadataStore, setNormalized, setOriginalMetadataPopulated, setResolution, setSeries, updateMetadataLists`

    - ### Methods inherited from class loci.formats.FormatHandler

      `checkSuffix, checkSuffix, getFormat, getMetadataOptions, getSuffixes, getSupportedMetadataLevels, setMetadataOptions`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface loci.formats.IFormatHandler

      `getFormat, getSuffixes`

    - ### Methods inherited from interface loci.formats.IMetadataConfigurable

      `getMetadataOptions, getSupportedMetadataLevels, setMetadataOptions`

    - ### Methods inherited from interface loci.formats.ICompressedTileReader

      `getTileCodec, getTileCodecOptions, openCompressedBytes, openCompressedBytes`

- - ### Field Detail

    - #### LITTLE_ENDIAN

          private static final boolean LITTLE_ENDIAN

      See Also:
        Constant Field Values

    - #### LABEL_X

          private static final java.lang.String LABEL_X

      See Also:
        Constant Field Values

    - #### LABEL_Y

          private static final java.lang.String LABEL_Y

      See Also:
        Constant Field Values

    - #### TIME_OFFSET

          private static final long TIME_OFFSET

      How often to report progress during initialization, in milliseconds.
      See Also:
        Constant Field Values

    - #### data

          private float[][] data

      Because we have no way of indexing into the text file efficiently in general, we cheat and store the entire file's data in a giant array.

    - #### row

          private int row

      Current row number.

    - #### rowLength

          private int rowLength

      Number of tokens per row.

    - #### xIndex

          private int xIndex

      Column index for X coordinate.

    - #### yIndex

          private int yIndex

      Column index for Y coordinate.

    - #### channels

          private java.lang.String[] channels

      List of channel labels.

    - #### sizeX

          private int sizeX

      Image width.

    - #### sizeY

          private int sizeY

      Image height.

  - ### Constructor Detail

    - #### TextReader

          public TextReader()

      Constructs a new text reader.

  - ### Method Detail

    - #### getChannelLabel

          public java.lang.String getChannelLabel(int c)

      Gets the label for the given channel.

    - #### isThisType

          public boolean isThisType(loci.common.RandomAccessInputStream stream)
                             throws java.io.IOException

      Description copied from interface: `IFormatReader`
      Checks if the given stream is a valid stream for this file format. The number of bytes read is format-dependent.
      Specified by:
        `isThisType` in interface `IFormatReader`
      Overrides:
        `isThisType` in class `FormatReader`
      Parameters:
        `stream` - A RandomAccessInputStream representing the file to check. The first byte in the stream is assumed to be the first byte in the file.
      Returns:
        true if the file represented by the stream can be read by this reader; false otherwise.
      Throws:
        `java.io.IOException`

    - #### openBytes

          public byte[] openBytes(int no,
                                  byte[] buf,
                                  int x,
                                  int y,
                                  int w,
                                  int h)
                           throws FormatException,
                                  java.io.IOException

      Description copied from interface: `IFormatReader`
      Obtains a sub-image of the specified image plane into a pre-allocated byte array.
      Specified by:
        `openBytes` in interface `IFormatReader`
      Specified by:
        `openBytes` in class `FormatReader`
      Parameters:
        `no` - the plane index within the current series.
        `buf` - a pre-allocated buffer.
        `x` - X coordinate of the upper-left corner of the sub-image
        `y` - Y coordinate of the upper-left corner of the sub-image
        `w` - width of the sub-image
        `h` - height of the sub-image
      Returns:
        the pre-allocated buffer `buf` for convenience.
      Throws:
        `FormatException` - if there was a problem parsing the metadata of the file.
        `java.io.IOException` - if there was a problem reading the file.

    - #### openPlane

          public java.lang.Object openPlane(int no,
                                            int x,
                                            int y,
                                            int w,
                                            int h)
                                     throws FormatException,
                                            java.io.IOException

      Description copied from interface: `IFormatReader`
      Obtains the specified image plane (or sub-image thereof) in the reader's native data structure. For most readers this is a byte array; however, some readers call external APIs that work with other types such as `BufferedImage`. The openPlane method exists to maintain generality and efficiency while avoiding pollution of the API with AWT-specific logic.
      Specified by:
        `openPlane` in interface `IFormatReader`
      Overrides:
        `openPlane` in class `FormatReader`
      Throws:
        `FormatException`
        `java.io.IOException`
      See Also:
        `FormatReader`, `BufferedImageReader`

    - #### close

          public void close(boolean fileOnly)
                     throws java.io.IOException

      Description copied from interface: `IFormatReader`
      Closes the currently open file. If the flag is set, this is all that happens; if unset, it is equivalent to calling `Closeable.close()`.
      Specified by:
        `close` in interface `IFormatReader`
      Overrides:
        `close` in class `FormatReader`
      Throws:
        `java.io.IOException`

    - #### getNativeDataType

          public java.lang.Class<?> getNativeDataType()

      Description copied from interface: `IFormatHandler`
      Returns the native data type of image planes for this reader, as returned by `IFormatReader.openPlane(int, int, int, int, int)` or `IFormatWriter.savePlane(int, java.lang.Object)`. For most readers this type will be a byte array; however, some readers call external APIs that work with other types such as `BufferedImage`.
      Specified by:
        `getNativeDataType` in interface `IFormatHandler`
      Overrides:
        `getNativeDataType` in class `FormatHandler`

    - #### initFile

          protected void initFile(java.lang.String id)
                           throws FormatException,
                                  java.io.IOException

      Description copied from class: `FormatReader`
      Initializes the given file (parsing header information, etc.). Most subclasses should override this method to perform initialization operations such as parsing metadata.
      Overrides:
        `initFile` in class `FormatReader`
      Throws:
        `FormatException` - if a parsing error occurs processing the file.
        `java.io.IOException` - if an I/O error occurs processing the file

    - #### readFile

          private java.util.List<java.lang.String> readFile(java.lang.String id)
                                                     throws java.io.IOException

      Throws:
        `java.io.IOException`

    - #### parseFileHeader

          private int parseFileHeader(java.util.List<java.lang.String> lines)
                               throws FormatException

      Parses the file looking for the file header. Determines image extents (sets sizeX and sizeY). Determines channel names (populates channels array).
      Returns:
        number of rows in the header
      Throws:
        `FormatException`

    - #### parseTableData

          private void parseTableData(java.util.List<java.lang.String> lines,
                                      int linesToSkip)

      Reads the tabular data into the data array.

    - #### populateCoreMetadata

          private void populateCoreMetadata(int sizeX,
                                            int sizeY,
                                            int sizeZ,
                                            int sizeC,
                                            int sizeT)

      Populates the `CoreMetadata` values.

    - #### getRowData

          private boolean getRowData(java.lang.String[] tokens,
                                     double[] rowData)

      Parses numerical row data from the given tokens.
      Parameters:
        `tokens` - list of token strings to parse
        `rowData` - array to fill in with the data; length must match tokens
      Returns:
        true if the data could be parsed

    - #### parseHeaderRow

          private void parseHeaderRow(java.lang.String[] tokens)

      Populates rowLength, xIndex, yIndex, and channels.

    - #### assignValues

          private void assignValues(double[] rowData)

      Assigns values from the given row into the data array.

    - #### checkTime

          private long checkTime(long time,
                                 int no,
                                 long pos,
                                 long len)

    - #### getX

          private int getX(double[] rowData)

    - #### getY

          private int getY(double[] rowData)

    - #### getNextLine

          private java.lang.String[] getNextLine(java.util.List<java.lang.String> lines)

Copyright © 2026 Open Microscopy Environment