Package uk.ac.starlink.table
Class OnceRowPipe
java.lang.Object
uk.ac.starlink.table.OnceRowPipe
- All Implemented Interfaces:
Closeable
,AutoCloseable
,RowData
,RowPipe
,RowSequence
,TableSink
,uk.ac.starlink.util.Sequence
Streaming
RowPipe
implementation which provides a one-shot
table.
The returned table is unusual in that it
can only return a RowSequence
once.
This violates the normal rules of the StarTable
interface.
Any calls beyond the first to
waitForStarTable().getRowSequence()
will throw a UnrepeatableSequenceException
.- Since:
- 10 Feb 2005
- Author:
- Mark Taylor (Starlink)
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new streaming row store with a default buffer size.OnceRowPipe
(int queueSize) Constructs a new streaming row store with a given buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptMetadata
(StarTable meta) Takes delivery of a row-lessStarTable
object which defines the metadata of the table to be transmitted.void
Takes delivery of one row of data.void
close()
Indicates that this sequence will not be required any more.void
endRows()
Signals that there are no more rows to be transmitted.getCell
(int icol) Returns the contents of a cell in the current row.Object[]
getRow()
Returns the contents of the current table row, as an array with the same number of elements as there are columns in this table.boolean
next()
Attempts to advance the current row to the next one.void
setError
(IOException error) May be called by the writing stream to set an I/O error on the pipe.Returns a non-random table whose first call togetRowSequence
will return a sequence that steps through the same rows which are being written to this sink.
-
Constructor Details
-
OnceRowPipe
public OnceRowPipe()Constructs a new streaming row store with a default buffer size. -
OnceRowPipe
public OnceRowPipe(int queueSize) Constructs a new streaming row store with a given buffer size.- Parameters:
queueSize
- the maximum number of rows buffered between write and read beforeacceptRow
will block
-
-
Method Details
-
setError
Description copied from interface:RowPipe
May be called by the writing stream to set an I/O error on the pipe. This error should be passed on to the reading end by throwing an error withe
as its cause from one of the read methods. If an error has already been set by a previous call of this method, this has no effect (only the first error is set). -
acceptMetadata
Description copied from interface:TableSink
Takes delivery of a row-lessStarTable
object which defines the metadata of the table to be transmitted. If the number of rows that will be transmitted via subsequent calls toacceptRow
is known, this value should be made available as the row count ofmeta
(StarTable.getRowCount()
); if it is not known, the row count should be -1. However, this object should not attempt to read any ofmeta
's cell data.The data to be transmitted in subsequent calls of
acceptRow
must match the metadata transmitted in this call in the same way that rows of a StarTable must match its own metadata (number and content clases of columns etc). If this sink cannot dispose of a table corresponding tometa
then it may throw a TableFormatException - this may be the case if for instancemeta
has columns with types that this sink can't deal with.- Specified by:
acceptMetadata
in interfaceTableSink
- Parameters:
meta
- table metadata object
-
acceptRow
Description copied from interface:TableSink
Takes delivery of one row of data.row
is an array of objects comprising the contents of one row of the table being transmitted. The number and classes of the elements ofrow
are described by the metadata object previously accepted.- Specified by:
acceptRow
in interfaceTableSink
- Parameters:
row
- table data row- Throws:
IOException
-
endRows
public void endRows()Description copied from interface:TableSink
Signals that there are no more rows to be transmitted. -
waitForStarTable
Returns a non-random table whose first call togetRowSequence
will return a sequence that steps through the same rows which are being written to this sink. ThegetRowSequence
method can only be called once; any subsequent attempts to call it will result in aUnrepeatableSequenceException
. This method will block untilacceptMetadata(uk.ac.starlink.table.StarTable)
has been called.- Specified by:
waitForStarTable
in interfaceRowPipe
- Returns:
- one-shot streaming sequential table
- Throws:
IOException
- if one has previously been set usingsetError(java.io.IOException)
-
next
Description copied from interface:RowSequence
Attempts to advance the current row to the next one. Iftrue
is returned the attempt has been successful, and iffalse
is returned there are no more rows in this sequence. Since the initial position of a RowSequence is before the first row, this method must be called before current row data can be accessed using theRowSequence.getCell(int)
orRowSequence.getRow()
methods.- Specified by:
next
in interfaceRowSequence
- Specified by:
next
in interfaceuk.ac.starlink.util.Sequence
- Returns:
true
iff this sequence has been advanced to the next row- Throws:
IOException
- if there is some error
-
getRow
Description copied from interface:RowSequence
Returns the contents of the current table row, as an array with the same number of elements as there are columns in this table. An unchecked exception will be thrown if there is no current row (next
has not yet been called).- Specified by:
getRow
in interfaceRowData
- Specified by:
getRow
in interfaceRowSequence
- Returns:
- an array of the objects in each cell in row
irow
-
getCell
Description copied from interface:RowSequence
Returns the contents of a cell in the current row. The class of the returned object should be the same as, or a subclass of, the class returned bygetColumnInfo(icol).getContentClass()
. An unchecked exception will be thrown if there is no current row (next
has not yet been called).- Specified by:
getCell
in interfaceRowData
- Specified by:
getCell
in interfaceRowSequence
- Parameters:
icol
- column index- Returns:
- the contents of cell
icol
in the current row
-
close
public void close()Description copied from interface:RowSequence
Indicates that this sequence will not be required any more. This should release resources associated with this object. The effect of calling any of the other methods following aclose
is undefined.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceRowSequence
-