Class DoubleMatrixFile.Reader
- Enclosing class:
DoubleMatrixFile
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 TypeMethodDescriptionvoid
close()
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()
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
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
readSegmentColSlice
(Range theColRange) 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
readSegmentRowSlice
(Range theRowRange) Read the next matrix element segment from the input stream, storing only the matrix elements in the given row slice.
-
Method Details
-
read
Read all matrix element segments from the input stream. If some segments have already been read, theread()
method reads all remaining segments. If there are no more segments, theread()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, theread()
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
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, thereadRowSlice()
method reads all remaining segments. If there are no more segments, thereadRowSlice()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadRowSlice()
method allocates the necessary storage.- Parameters:
theRowRange
- Row range.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheRowRange
is null.IllegalArgumentException
- (unchecked exception) Thrown iftheRowRange
's stride is greater than 1.IndexOutOfBoundsException
- (unchecked exception) Thrown if any index intheRowRange
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
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, thereadColSlice()
method reads all remaining segments. If there are no more segments, thereadColSlice()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadColSlice()
method allocates the necessary storage.- Parameters:
theColRange
- Column range.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheColRange
is null.IllegalArgumentException
- (unchecked exception) Thrown iftheColRange
's stride is greater than 1.IndexOutOfBoundsException
- (unchecked exception) Thrown if any index intheColRange
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
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, thereadPatch()
method reads all remaining segments. If there are no more segments, thereadPatch()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadPatch()
method allocates the necessary storage.- Parameters:
theRowRange
- Row range.theColRange
- Column range.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheRowRange
is null. Thrown iftheColRange
is null.IllegalArgumentException
- (unchecked exception) Thrown iftheRowRange
's stride is greater than 1. Thrown iftheColRange
's stride is greater than 1.IndexOutOfBoundsException
- (unchecked exception) Thrown if any index intheRowRange
is outside the range 0 .. R-1. Thrown if any index intheColRange
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
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
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
Read the next matrix element segment from the input stream. If there are no more segments, thereadSegment()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadSegment()
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
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, thereadSegmentRowSlice()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadSegmentRowSlice()
method allocates the necessary storage.- Parameters:
theRowRange
- Row range.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheRowRange
is null.IllegalArgumentException
- (unchecked exception) Thrown iftheRowRange
's stride is greater than 1.IndexOutOfBoundsException
- (unchecked exception) Thrown if any index intheRowRange
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
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, thereadSegmentRowSlice()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadSegmentRowSlice()
method allocates the necessary storage.- Parameters:
theColRange
- Column range.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheColRange
is null.IllegalArgumentException
- (unchecked exception) Thrown iftheColRange
's stride is greater than 1.IndexOutOfBoundsException
- (unchecked exception) Thrown if any index intheColRange
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
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, thereadSegmentPatch()
method does nothing. If storage is not already allocated in the underlying matrix for the matrix elements, thereadSegmentPatch()
method allocates the necessary storage.- Parameters:
theRowRange
- Row range.theColRange
- Column range.- Throws:
NullPointerException
- (unchecked exception) Thrown iftheRowRange
is null. Thrown iftheColRange
is null.IllegalArgumentException
- (unchecked exception) Thrown iftheRowRange
's stride is greater than 1. Thrown iftheColRange
's stride is greater than 1.IndexOutOfBoundsException
- (unchecked exception) Thrown if any index intheRowRange
is outside the range 0 .. R-1. Thrown if any index intheColRange
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
Close the input stream.- Throws:
IOException
- Thrown if an I/O error occurred.
-