public class Channel extends AstObject
This class is used for reading and writing AST objects from/to
external media. The Channel
class itself reads
from System.in
or another InputStream
and writes to System.out
or another
OutputStream
.
To perform I/O to some other object, extend this class and
override the source
and sink
methods.
AST__BAD, AST__TUNULL, pointer
Modifier | Constructor and Description |
---|---|
protected |
Channel()
This constructor does not do all the required construction to
create a valid Channel object, but is required for inheritance
by user subclasses of Channel.
|
protected |
Channel(Channel dummy)
This is a dummy constructor which does nothing at all.
|
|
Channel(InputStream in,
OutputStream out)
Creates a channel which reads from the given
InputStream
and writes to the given OutputStream . |
Modifier and Type | Method and Description |
---|---|
AstObject |
copy()
This method is currently unsupported for Channel and its subclasses
because of difficulties in its implementation, and because it is
probably not that useful.
|
protected void |
finalize()
Finalizes the object.
|
boolean |
getComment()
Get
include textual comments in output.
|
int |
getFull()
Get
set level of output detail.
|
int |
getReportLevel()
Get
determines which read/write conditions are reported.
|
boolean |
getSkip()
Get
skip irrelevant data.
|
boolean |
getStrict()
Get
report an error if any unexpeted data items are found.
|
AstObject |
read()
Reads an AST object from this channel.
|
void |
setComment(boolean comment)
Set
include textual comments in output.
|
void |
setFull(int full)
Set
set level of output detail.
|
void |
setReportLevel(int reportLevel)
Set
determines which read/write conditions are reported.
|
void |
setSkip(boolean skip)
Set
skip irrelevant data.
|
void |
setStrict(boolean strict)
Set
report an error if any unexpeted data items are found.
|
protected void |
sink(String line)
Writes a
String which forms one line of the textual
representation of an AST object to the channel's output stream. |
protected String |
source()
Reads a
String which forms one line of the textual
representation of an AST object from the channel's input stream. |
KeyMap |
warnings()
Returns any warnings issued by the previous read or write operation.
|
int |
write(AstObject obj)
Writes an AST object to this channel.
|
annul, clear, delete, equals, getAstConstantI, getB, getC, getD, getF, getI, getID, getIdent, getL, getNobject, getObjSize, getRefCount, hashCode, isThreaded, reportVersions, sameObject, set, setB, setC, setD, setF, setI, setID, setIdent, setL, show, test, tune
public Channel(InputStream in, OutputStream out)
InputStream
and writes to the given OutputStream
.in
- a stream to read AST objects from. If null
,
then System.in
is used.out
- a stream to write AST objects to. If null
,
then System.out
is used.protected Channel()
protected Channel(Channel dummy)
protected void finalize() throws Throwable
protected String source() throws IOException
String
which forms one line of the textual
representation of an AST object from the channel's input stream.
If the end of the stream is reached, null
is returned.
If an IOException
occurs during the reading,
it is thrown.
This method is called by the read
method.
To implement a channel which reads from a source other than
an InputStream
, override this method. The method
should return null
when there is no more input,
and may throw an IOException in case of error.
String
. If the end of the stream has been
reached, null
is returned.IOException
- if an I/O error occurs during readingprotected void sink(String line) throws IOException
String
which forms one line of the textual
representation of an AST object to the channel's output stream.
If an IOException
occurs during the writing,
it is thrown.
This method is called by the write
method.
To implement a channel which writes to a source other than
an OutputStream
, override this method. The method
can do anything it likes with its argument, and may throw
an exception in case of error.
line
- a String
which forms one line of the
textual description of an AST object which is being
written.IOException
- if an I/O error occurs during writing.public AstObject read() throws IOException
source
method is invoked to obtain the textual representation.AstObject
which has been read.
null
is returned, without error, if no
further objects remain to be read on the streamIOException
- if such an exception was generated by the
source
methodAstException
- if an error occurs in the AST librarypublic int write(AstObject obj) throws IOException
sink
method is invoked to send the textual representation.obj
- an AstObject
to be writtenIOException
- if such an exception was generated by the
sink
methodAstException
- if an error occurs in the AST librarypublic AstObject copy()
copy
in class AstObject
UnsupportedOperationException
- alwayspublic KeyMap warnings()
Such warnings are non-fatal and will not prevent the read or write operation succeeding. However, the converted object may not be identical to the original object in all respects. Differences which would usually be deemed as insignificant in most usual cases will generate a warning, whereas more significant differences will generate an error.
The "Strict" attribute allows this warning facility to be switched off, so that a fatal error is always reported for any conversion error.
AstException
- if an error occurred in the AST librarypublic boolean getComment()
If Comment is non-zero, then comments will be included. If it is zero, comments will be omitted.
public void setComment(boolean comment)
If Comment is non-zero, then comments will be included. If it is zero, comments will be omitted.
comment
- the Comment attribute of this objectpublic int getFull()
If Full is zero, then a modest amount of non-essential but useful information will be included in the output. If Full is negative, all non-essential information will be suppressed to minimise the amount of output, while if it is positive, the output will include the maximum amount of detailed information about the Object being written.
public void setFull(int full)
If Full is zero, then a modest amount of non-essential but useful information will be included in the output. If Full is negative, all non-essential information will be suppressed to minimise the amount of output, while if it is positive, the output will include the maximum amount of detailed information about the Object being written.
full
- the Full attribute of this objectpublic int getReportLevel()
0 - Do not report any conditions.
1 - Report only conditions where significant information content has been changed. For instance, an unsupported time-scale has been replaced by a supported near-equivalent time-scale. Another example is if a basic Channel unexpected encounters data items that may have been introduced by later versions of AST.
2 - Report the above, and in addition report significant default values. For instance, if no time-scale was specified when reading an Object from an external data source, report the default time-scale that is being used.
3 - Report the above, and in addition report any other potentially interesting conditions that have no significant effect on the conversion. For instance, report if a time-scale of "TT" (terrestrial time) is used in place of "ET" (ephemeris time). This change has no signficiant effect because ET is the predecessor of, and is continuous with, TT. Synonyms such as "IAT" and "TAI" are another example.
The default value is 1. Note, there are many other conditions that can occur whilst reading or writing an Object that completely prevent the conversion taking place. Such conditions will always generate errors, irrespective of the ReportLevel and Strict attributes.
public void setReportLevel(int reportLevel)
0 - Do not report any conditions.
1 - Report only conditions where significant information content has been changed. For instance, an unsupported time-scale has been replaced by a supported near-equivalent time-scale. Another example is if a basic Channel unexpected encounters data items that may have been introduced by later versions of AST.
2 - Report the above, and in addition report significant default values. For instance, if no time-scale was specified when reading an Object from an external data source, report the default time-scale that is being used.
3 - Report the above, and in addition report any other potentially interesting conditions that have no significant effect on the conversion. For instance, report if a time-scale of "TT" (terrestrial time) is used in place of "ET" (ephemeris time). This change has no signficiant effect because ET is the predecessor of, and is continuous with, TT. Synonyms such as "IAT" and "TAI" are another example.
The default value is 1. Note, there are many other conditions that can occur whilst reading or writing an Object that completely prevent the conversion taking place. Such conditions will always generate errors, irrespective of the ReportLevel and Strict attributes.
reportLevel
- the ReportLevel attribute of this objectpublic boolean getSkip()
If Skip is zero (the default), then the source of input data is expected to contain descriptions of AST Objects and comments and nothing else (if anything else is read, an error will result). If Skip is non-zero, then any non-Object data encountered between Objects will be ignored and simply skipped over in order to reach the next Object.
public void setSkip(boolean skip)
If Skip is zero (the default), then the source of input data is expected to contain descriptions of AST Objects and comments and nothing else (if anything else is read, an error will result). If Skip is non-zero, then any non-Object data encountered between Objects will be ignored and simply skipped over in order to reach the next Object.
skip
- the Skip attribute of this objectpublic boolean getStrict()
public void setStrict(boolean strict)
strict
- the Strict attribute of this objectCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.