Package edu.rit.io

Class DoubleMatrixFile.Reader

java.lang.Object
edu.rit.io.DoubleMatrixFile.Reader
Enclosing class:
DoubleMatrixFile

public class DoubleMatrixFile.Reader extends Object
Class DoubleMatrixFile.Reader provides an object with which to read a DoubleMatrixFile from an input stream.

When a reader is created, the number of rows and number of columns are read from the input stream. If the matrix file object is uninitialized, it becomes initialized with the given number of rows and columns, and storage is allocated for the underlying matrix's row references. If the matrix file object is already initialized, the number of rows and columns read from the input stream must match those of the matrix file object, otherwise an exception is thrown.

To read the matrix element segments one at a time, first call the getRowRange() and getColRange() methods to obtain the range of rows and columns in the next segment. At this point, allocate storage for the rows and columns in the underlying matrix if necessary. Then call the readSegment() method to read the actual matrix elements. Repeat these steps if there are additional segments.

To read all the matrix element segments (or all the remaining segments), call the read() method.

Methods are also provided to read the current segment, or all the remaining segments, through a filter. As the segment(s) are read, only those matrix elements within a given row range, a given column range, or a given row and column range are actually stored in the underlying matrix.

When finished, call the close() method.

Note: Class DoubleMatrixFile.Reader is not multiple thread safe.

Version:
07-Jan-2008
Author:
Alan Kaminsky
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Close the input stream.
    Obtain the column range of the next matrix element segment in the input stream.
    Obtain the row range of the next matrix element segment in the input stream.
    void
    Read all matrix element segments from the input stream.
    void
    readColSlice(Range theColRange)
    Read all matrix element segments from the input stream, storing only the matrix elements in the given column slice.
    void
    readPatch(Range theRowRange, Range theColRange)
    Read all matrix element segments from the input stream, storing only the matrix elements in the given patch.
    void
    readRowSlice(Range theRowRange)
    Read all matrix element segments from the input stream, storing only the matrix elements in the given row slice.
    void
    Read the next matrix element segment from the input stream.
    void
    Read the next matrix element segment from the input stream, storing only the matrix elements in the given column slice.
    void
    readSegmentPatch(Range theRowRange, Range theColRange)
    Read the next matrix element segment from the input stream, storing only the matrix elements in the given patch.
    void
    Read the next matrix element segment from the input stream, storing only the matrix elements in the given row slice.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • read

      public void read() throws IOException
      Read all matrix element segments from the input stream. If some segments have already been read, the read() method reads all remaining segments. If there are no more segments, the read() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the read() method allocates the necessary storage.
      Throws:
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • readRowSlice

      public void readRowSlice(Range theRowRange) throws IOException
      Read all matrix element segments from the input stream, storing only the matrix elements in the given row slice. If some segments have already been read, the readRowSlice() method reads all remaining segments. If there are no more segments, the readRowSlice() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readRowSlice() method allocates the necessary storage.
      Parameters:
      theRowRange - Row range.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theRowRange is null.
      IllegalArgumentException - (unchecked exception) Thrown if theRowRange's stride is greater than 1.
      IndexOutOfBoundsException - (unchecked exception) Thrown if any index in theRowRange is outside the range 0 .. R-1.
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • readColSlice

      public void readColSlice(Range theColRange) throws IOException
      Read all matrix element segments from the input stream, storing only the matrix elements in the given column slice. If some segments have already been read, the readColSlice() method reads all remaining segments. If there are no more segments, the readColSlice() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readColSlice() method allocates the necessary storage.
      Parameters:
      theColRange - Column range.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theColRange is null.
      IllegalArgumentException - (unchecked exception) Thrown if theColRange's stride is greater than 1.
      IndexOutOfBoundsException - (unchecked exception) Thrown if any index in theColRange is outside the range 0 .. C-1.
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • readPatch

      public void readPatch(Range theRowRange, Range theColRange) throws IOException
      Read all matrix element segments from the input stream, storing only the matrix elements in the given patch. If some segments have already been read, the readPatch() method reads all remaining segments. If there are no more segments, the readPatch() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readPatch() method allocates the necessary storage.
      Parameters:
      theRowRange - Row range.
      theColRange - Column range.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theRowRange is null. Thrown if theColRange is null.
      IllegalArgumentException - (unchecked exception) Thrown if theRowRange's stride is greater than 1. Thrown if theColRange's stride is greater than 1.
      IndexOutOfBoundsException - (unchecked exception) Thrown if any index in theRowRange is outside the range 0 .. R-1. Thrown if any index in theColRange is outside the range 0 .. C-1.
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • getRowRange

      public Range getRowRange()
      Obtain the row range of the next matrix element segment in the input stream. If there are no more segments, null is returned.
      Returns:
      Row range, or null.
    • getColRange

      public Range getColRange()
      Obtain the column range of the next matrix element segment in the input stream. If there are no more segments, null is returned.
      Returns:
      Column range, or null.
    • readSegment

      public void readSegment() throws IOException
      Read the next matrix element segment from the input stream. If there are no more segments, the readSegment() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readSegment() method allocates the necessary storage.
      Throws:
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • readSegmentRowSlice

      public void readSegmentRowSlice(Range theRowRange) throws IOException
      Read the next matrix element segment from the input stream, storing only the matrix elements in the given row slice. If there are no more segments, the readSegmentRowSlice() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readSegmentRowSlice() method allocates the necessary storage.
      Parameters:
      theRowRange - Row range.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theRowRange is null.
      IllegalArgumentException - (unchecked exception) Thrown if theRowRange's stride is greater than 1.
      IndexOutOfBoundsException - (unchecked exception) Thrown if any index in theRowRange is outside the range 0 .. R-1.
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • readSegmentColSlice

      public void readSegmentColSlice(Range theColRange) throws IOException
      Read the next matrix element segment from the input stream, storing only the matrix elements in the given column slice. If there are no more segments, the readSegmentRowSlice() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readSegmentRowSlice() method allocates the necessary storage.
      Parameters:
      theColRange - Column range.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theColRange is null.
      IllegalArgumentException - (unchecked exception) Thrown if theColRange's stride is greater than 1.
      IndexOutOfBoundsException - (unchecked exception) Thrown if any index in theColRange is outside the range 0 .. C-1.
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • readSegmentPatch

      public void readSegmentPatch(Range theRowRange, Range theColRange) throws IOException
      Read the next matrix element segment from the input stream, storing only the matrix elements in the given patch. If there are no more segments, the readSegmentPatch() method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, the readSegmentPatch() method allocates the necessary storage.
      Parameters:
      theRowRange - Row range.
      theColRange - Column range.
      Throws:
      NullPointerException - (unchecked exception) Thrown if theRowRange is null. Thrown if theColRange is null.
      IllegalArgumentException - (unchecked exception) Thrown if theRowRange's stride is greater than 1. Thrown if theColRange's stride is greater than 1.
      IndexOutOfBoundsException - (unchecked exception) Thrown if any index in theRowRange is outside the range 0 .. R-1. Thrown if any index in theColRange is outside the range 0 .. C-1.
      IOException - Thrown if an I/O error occurred.
      InvalidMatrixFileException - (subclass of IOException) Thrown if the input stream's contents were invalid.
    • close

      public void close() throws IOException
      Close the input stream.
      Throws:
      IOException - Thrown if an I/O error occurred.