public class StreamDaemon extends java.lang.Object implements StreamBuilder, LowLevelStream
Modifier and Type | Field and Description |
---|---|
private java.util.Map<Stream,java.lang.Integer> |
ids
Same list but for reverse lookups of ID by stream
|
private static java.lang.Object |
modToken
Token used to authenticate with the dispatcher when registering APIs.
|
private int |
next
Next id to attempt to allocate.
|
private java.util.Map<java.lang.Integer,Stream> |
streams
Stores the list of active streams, keyed by integral stream id.
|
private ThinClient |
terminal
Represents the terminal.
|
Constructor and Description |
---|
StreamDaemon(ThinClient terminal,
boolean single)
Create an instance and export its API to the network.
|
Modifier and Type | Method and Description |
---|---|
void |
advancePage(int id)
Inserts a page break if the stream is paged and if the next write
position is not on the first line of a new page.
|
long |
available(int id)
The number of bytes available to be immediately read without blocking.
|
private void |
cleanupMaps(Stream s,
int id)
Removes the traces of the specified stream from the lookup maps.
|
void |
close(int id)
Closes the stream and releases OS resources associated with it.
|
void |
closeIn(int id)
Closes the input stream and releases OS resources associated with it.
|
void |
closeOut(int id)
Closes the output stream and releases OS resources associated with it.
|
void |
endOutput(int id,
boolean appendNewLine)
Write the current output buffer to the stream.
|
void |
flush(int id)
Flushes the stream.
|
long |
getLen(int id)
The length of the stream in bytes.
|
int |
getNextLineNum(int id)
Gets the current page's next logical line number.
|
long |
getPos(int id)
The 0-based offset into the stream at which the next read or write will
occur.
|
int |
idFromStream(Stream s)
Returns the stream ID associated with a given stream.
|
boolean |
isIn(int id)
State of the input side of the stream.
|
boolean |
isOut(int id)
State of the output side of the stream.
|
private Stream |
lookup(int id,
int num,
java.lang.String msg)
Accesses the stream in the map using the given id.
|
boolean |
needsPageBreak(int id)
Detects when a page break is needed.
|
int |
openClipboardStream()
Constructs the output stream into the client's system clipboard.
|
int |
openDirStream(java.lang.String dir,
boolean noAttrList)
Constructs a remote stream instance representing the OsDirStream result of the INPUT
THROUGH OS-DIR (dir-name) statement.
|
int |
openFileStream(java.lang.String filename,
boolean write,
boolean append)
Constructs a remote stream instance representing a file using a filename, this file or
device will be opened for reading or writing based on the given
write flag. |
int |
openPrinterStream(java.lang.String name,
PrintOptions options)
Constructs a remote printer stream instance.
|
int |
openProcessStream()
Constructs a remote stream instance representing a process' standard I/O.
|
int |
openTerminalStream()
Constructs a remote stream instance representing the terminal.
|
int |
peekCh(int id)
Peeks at the character from the current read position in the stream (reads a character from
the current read position in the stream without incrementing stream read position.
|
void |
processCleanup(int id,
boolean in,
boolean out)
Perform common close preprocessing for all streams.
|
void |
putWorker(int id,
FieldEntry[] data,
int mode,
char delim)
Output a list of fields to the stream.
|
int |
rawGetNextLineNum(int id)
Gets the current page's next line number.
|
int |
rawGetPageNum(int id)
Gets the current page number.
|
int |
rawGetPageSize(int id)
Gets the current page size in lines.
|
void |
rawIncrementNextLineNum(int id)
Increments the current page's next line number.
|
void |
rawIncrementPageNum(int id)
Increments the current page number.
|
void |
rawResetNextLineNum(int id)
Resets the current page's next line number to 1.
|
void |
rawSetPageSize(int id,
int sz)
Sets the current page size in lines.
|
int |
readCh(int id)
Read a character from the current read position in the stream.
|
byte[] |
readChunk(int id,
int len)
Read a chunk of bytes from the current read position in the stream to the
offset calculated by given length or to the
EOF , whichever
comes first. |
java.lang.String |
readLn(int id)
Read all characters from the current read position in the stream to the
next line separator (as determined by the
File.separator
or to the EOF . |
private java.lang.String |
resolvePathName(java.lang.String path,
boolean isDirectory)
Tries to resolve the given legacy path name into its host path name, fix it according to
the environment file separator and applies case insensitive search if the legacy file system
is case insensitive.
|
private int |
reverseLookup(Stream s,
int num,
java.lang.String msg)
Accesses the stream ID in the map using the given stream.
|
void |
setBinary(int id)
Sets the stream into binary mode which disables character translations during I/O
operations.
|
void |
setConvert(int id,
boolean convert)
Sets the stream's character conversion mode.
|
void |
setConvertSource(int id,
java.lang.String cp)
Sets the stream's source codepage and activates character conversion mode.
|
void |
setConvertTarget(int id,
java.lang.String cp)
Sets the stream's target codepage and activates character conversion mode.
|
void |
setFont(int id,
int num)
Sets the stream font number.
|
void |
setLandscape(int id)
Set stream display mode to landscape
|
void |
setLen(int id,
long len)
Truncates or extends the stream to the specified length if this stream
supports such an operation.
|
void |
setPortrait(int id)
Set stream display mode to portrait
|
void |
setPos(int id,
long pos)
Moves the current read/write position to the specified absolute 0-based
offset.
|
void |
setUnbuffered(int id)
Set the the stream UNBUFFERED.
|
void |
setUnnamed(int id,
boolean unnamed)
Set the unnamed field for the stream.
|
(package private) int |
store(Stream s)
Assign a new stream id and store the given stream reference using the
id as a key.
|
Stream |
streamFromId(int id)
Returns the stream associated with a given id.
|
void |
write(int id,
byte[] data)
Write the given byte array to the output stream.
|
void |
write(int id,
byte[] data,
int offset,
int length)
Write the specified range of bytes from the given byte array to the output stream.
|
void |
write(int id,
java.lang.String data)
Write the given string to the output stream.
|
void |
writeByte(int id,
byte b)
Write the given byte to the output stream.
|
void |
writeCh(int id,
char ch)
Write the given character to the output stream.
|
private static java.lang.Object modToken
private ThinClient terminal
private java.util.Map<java.lang.Integer,Stream> streams
private java.util.Map<Stream,java.lang.Integer> ids
private int next
public StreamDaemon(ThinClient terminal, boolean single)
terminal
- Provides access to terminal features and helpers.single
- true
to startup within the server process which
must bypass the shared infrastructure initialization. Use
false
for the normal client JVM startup.public int openFileStream(java.lang.String filename, boolean write, boolean append) throws ErrorConditionException
write
flag.
The current read/write position will be at offset 0 unless in write
mode and
the append
flag is on (in which case the write position will be at the end of
the file).
This stream will NOT have paging active.
openFileStream
in interface StreamBuilder
filename
- The name of the file or device to open. Must not be null
.write
- If true
, open in write mode, otherwise open the file for reading.append
- In write
mode, if true
, the current file pointer is
set to the end of the file. Otherwise if in write
mode, the file
is truncated to 0 length. This value is ignored in read
mode.ErrorConditionException
- If the file does not exist OR if the current user does not have the proper rights
to open the file or device.public int openProcessStream()
openProcessStream
in interface StreamBuilder
public int openDirStream(java.lang.String dir, boolean noAttrList)
This will take the directory and export the list of files, directory and device names and properties.
openDirStream
in interface StreamBuilder
dir
- The String
path to the directory on which OS-DIR will be applied.noAttrList
- true
if property indexes will be added to the results.public int openTerminalStream()
openTerminalStream
in interface StreamBuilder
public int openClipboardStream()
openClipboardStream
in interface StreamBuilder
public int openPrinterStream(java.lang.String name, PrintOptions options)
openPrinterStream
in interface StreamBuilder
name
- The name of the target printer. May be null
.options
- Print options.public long available(int id) throws java.io.IOException
available
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.java.io.IOException
public boolean isIn(int id)
isIn
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.true
if the input side of the stream is active.public boolean isOut(int id)
isOut
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.true
if the output side of the stream is active.public void advancePage(int id) throws ErrorConditionException
advancePage
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.ErrorConditionException
public void flush(int id)
flush
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public long getPos(int id) throws java.lang.UnsupportedOperationException, java.io.IOException
getPos
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.java.io.IOException
java.lang.UnsupportedOperationException
public void setPos(int id, long pos) throws java.lang.UnsupportedOperationException, java.io.IOException
setPos
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.pos
- The new read/write position in the stream.java.io.IOException
java.lang.UnsupportedOperationException
public long getLen(int id) throws java.lang.UnsupportedOperationException, java.io.IOException
getLen
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.java.io.IOException
java.lang.UnsupportedOperationException
public int getNextLineNum(int id)
getNextLineNum
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void setLen(int id, long len) throws java.lang.UnsupportedOperationException, java.io.IOException
setLen
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.len
- The new length of the file.java.io.IOException
java.lang.UnsupportedOperationException
public void writeCh(int id, char ch) throws java.io.IOException
writeCh
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.ch
- The character to be written.java.io.IOException
public void writeByte(int id, byte b) throws java.io.IOException
writeByte
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.b
- The byte to be written.java.io.IOException
public void write(int id, java.lang.String data) throws java.io.IOException
write
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.data
- The data to be written.java.io.IOException
public void write(int id, byte[] data) throws java.io.IOException
write
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.data
- The data to be written.java.io.IOException
- If an I/O error occurs.public void write(int id, byte[] data, int offset, int length) throws java.io.IOException
write
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.data
- The data to be written.offset
- Starting offset in data from which to read bytes to be written. Must be
non-negative and < data.length
.length
- Length of data to be written. Must be non-negative and <= (data.length
- offset)
.java.io.IOException
- If an I/O error occurs.public int peekCh(int id)
peekCh()
and readCh()
will return the same value).
The underlying stream subclass determines the content of the result. Byte oriented streams such as pipes or files will return a byte while streams that generate keystrokes or characters may return a DBCS or Unicode character.
peekCh
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.EOF
.public int readCh(int id)
The underlying stream subclass determines the content of the result. Byte oriented streams such as pipes or files will return a byte while streams that generate keystrokes or characters may return a DBCS or Unicode character.
readCh
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.EOF
.public java.lang.String readLn(int id) throws java.io.EOFException, java.io.IOException, java.lang.InterruptedException
File.separator
or to the EOF
. Any line separator character(s) and the
EOF
character are not returned.readLn
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.java.io.EOFException
java.io.IOException
java.lang.InterruptedException
public byte[] readChunk(int id, int len) throws java.io.IOException
EOF
, whichever
comes first. The EOF
character is not returned.readChunk
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.len
- The number of bytes to read.null
if there
is nothing to read (the EOF
has been reached). The
length of the returned array will be the smaller of the
len
parameter or the actual bytes left before the
EOF
.java.io.IOException
- If an I/O error occurs.public void closeIn(int id)
closeIn
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void closeOut(int id)
closeOut
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void close(int id)
assign
is used to "re-open" the stream. This is safe to
call when no stream is open (it will do nothing in that case).close
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public boolean needsPageBreak(int id)
needsPageBreak
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.true
if a page break should be output.public int rawGetPageSize(int id)
rawGetPageSize
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void rawSetPageSize(int id, int sz)
rawSetPageSize
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.sz
- The number of lines per page.public int rawGetPageNum(int id)
rawGetPageNum
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void rawIncrementPageNum(int id)
rawIncrementPageNum
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public int rawGetNextLineNum(int id)
rawGetNextLineNum
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void rawIncrementNextLineNum(int id)
rawIncrementNextLineNum
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void rawResetNextLineNum(int id)
rawResetNextLineNum
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void processCleanup(int id, boolean in, boolean out) throws java.io.IOException
processCleanup
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.in
- true
if this was triggered during a call to
closeIn(int)
or close(int)
. Input resources are
to be cleaned up.out
- true
if this was triggered during a call to
closeOut(int)
or close(int)
. Output resources are
to be cleaned up.java.io.IOException
public Stream streamFromId(int id)
id
- Specifies the stream on which this operation is to execute.null
if no stream is associated
with the given id.public int idFromStream(Stream s)
s
- stream to operate on-1
if no stream ID is associated
with the given stream.public void endOutput(int id, boolean appendNewLine) throws ErrorConditionException, StopConditionException
Stream.putField(int)
, Stream.putSpace()
,
Stream.putLineEnd()
and Stream.writeField(int)
methods to the
stream. This method also resets the current delimiter to the default.
This method does nothing if the stream is in control
mode.
endOutput
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.appendNewLine
- Automatically add new line at the end of output.ErrorConditionException
- On any error during I/O.StopConditionException
- If any interruption occurs during I/O processing.public void putWorker(int id, FieldEntry[] data, int mode, char delim) throws ErrorConditionException
putWorker
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.data
- The list of fields to be output.mode
- MODE_PUT_NORMAL
, MODE_PUT_CONTROL
,
MODE_PUT_UNFORMATTED
or MODE_EXPORT
.delim
- The delimiter to use in EXPORT mode.ErrorConditionException
- On any error during I/O.public void setUnnamed(int id, boolean unnamed)
setUnnamed
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.unnamed
- true
if it is an unnamed stream.public void setUnbuffered(int id)
setUnbuffered
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void setConvert(int id, boolean convert)
setConvert
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.convert
- The new character conversion mode. true
to
enable character conversion, false
to disable
conversion.public void setConvertSource(int id, java.lang.String cp)
setConvertSource
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.cp
- The source codepage for character conversion mode.public void setConvertTarget(int id, java.lang.String cp)
setConvertTarget
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.cp
- The target codepage for character conversion mode.public void setBinary(int id)
import
,
set
, update
prompt-for
and import
unformatted
) are unaffected by this setting (this is based on Progress testcases).setBinary
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void setFont(int id, int num)
setFont
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.num
- Font number.public void setLandscape(int id)
setLandscape
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.public void setPortrait(int id)
setPortrait
in interface LowLevelStream
id
- Specifies the stream on which this operation is to execute.int store(Stream s)
s
- The stream to store.null
.private java.lang.String resolvePathName(java.lang.String path, boolean isDirectory)
path
- The given legacy path nameisDirectory
- True iff the given path name represents a directoryprivate Stream lookup(int id, int num, java.lang.String msg)
id
- Specifies the stream on which this operation is to execute.num
- Error number to use on failure.msg
- Error text to insert into a standardized message starting
with "Attempt to" and ending with "closed stream ###" where
the ### represents the stream's id.private int reverseLookup(Stream s, int num, java.lang.String msg)
s
- Specifies the stream on which this operation is to execute.num
- Error number to use on failure.msg
- Error text to insert into a standardized message starting
with "Attempt to" and ending with "closed stream".private void cleanupMaps(Stream s, int id)
s
- Specifies the stream on which this operation is to execute.id
- Specified the stream's ID.