public class StreamWrapper extends Stream
This is a generic interface "redirector" (from this instance to the
contained reference). Upon construction, the internal reference is
null
. Once an assign(com.goldencode.p2j.util.Stream)
call has occurred, any other
methods called on this class will succeed. They will be redirected to
the contained reference. To obtain the reference directly, call the
dereference()
method.
After close()
is called, the contained stream reference is
null
and subsequent usage will throw a
NullPointerException
.
Stream.PrintMode
Modifier and Type | Field and Description |
---|---|
private boolean |
inOk
Status var for input.
|
private boolean |
outOk
Status var for output.
|
private Stream |
stream
The backing construct for the stream.
|
binary, convert, CR, DELIM, doneIn, doneOut, EOF, increment, LF, MODE_EXPORT, MODE_PUT_CONTROL, MODE_PUT_NORMAL, MODE_PUT_UNFORMATTED, NEWLINE, NEWLINE_LEN, PAGED_DEFAULT, PIPE_BROKEN_MESSAGE, SET_PAGED_DEFAULT, sourceCp, targetCp
Constructor and Description |
---|
StreamWrapper()
Default constructor.
|
StreamWrapper(java.lang.String name)
Construct an instance associated with a specific legacy 4GL variable
name.
|
Modifier and Type | Method and Description |
---|---|
void |
advancePage()
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.
|
void |
assign(Stream s)
Assigns the internal stream reference to the given reference.
|
long |
available()
The number of bytes available to be immediately read without blocking.
|
protected void |
cleanup(boolean in,
boolean out)
Perform common close preprocessing for all streams.
|
void |
close()
Closes the stream and releases OS resources associated with it.
|
void |
closeIn()
Closes the input stream and releases OS resources associated with it.
|
void |
closeOut()
Closes the output stream and releases OS resources associated with it.
|
Stream |
dereference()
Access the wrapped stream directly.
|
void |
endOutput(boolean appendNewLine)
Write the current output buffer to the stream.
|
void |
flush()
Flushes the stream.
|
long |
getLen()
The length of the stream in bytes.
|
integer |
getNextLineNum()
Gets the current page's next logical line number.
|
long |
getPos()
The 0-based offset into the stream at which the next read or write will
occur.
|
boolean |
isIn()
State of the input side of the stream.
|
boolean |
isOut()
State of the output side of the stream.
|
boolean |
isSilent()
Check if stream is in silent mode.
|
boolean |
isTerm()
Check if current stream is terminal.
|
(package private) boolean |
needsPageBreak()
Detects when a page break is needed.
|
int |
peekCh()
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 |
putUnformatted(FieldEntry[] data)
Output a list of fields with default formatting to the stream.
|
void |
putWorker(FieldEntry[] data,
int mode,
char delim)
Output a list of fields to the stream.
|
(package private) int |
rawGetNextLineNum()
Gets the current page's next line number.
|
(package private) int |
rawGetPageNum()
Gets the current page number.
|
(package private) int |
rawGetPageSize()
Gets the current page size in lines.
|
(package private) void |
rawIncrementNextLineNum()
Increments the current page's next line number.
|
(package private) void |
rawIncrementPageNum()
Increments the current page number.
|
(package private) void |
rawResetNextLineNum()
Resets the current page's next line number to 1.
|
(package private) void |
rawSetPageSize(int sz)
Sets the current page size in lines.
|
int |
readCh()
Read a character from the current read position in the stream.
|
java.lang.String |
readLn()
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 . |
void |
setControl(boolean mode)
Sets the stream into control mode which ensures that subsequent
characters written to the stream will not affect line/page counters.
|
void |
setConvert(boolean convert)
Sets the stream's character conversion mode.
|
void |
setConvertSource(java.lang.String cp)
Sets the stream's source codepage and activates character conversion mode.
|
void |
setConvertTarget(java.lang.String cp)
Sets the stream's target codepage and activates character conversion mode.
|
void |
setDelimiter(char delim)
Sets the stream's delimiter character for import/export of fields.
|
void |
setDelimiter(java.lang.String delim)
Sets the stream's delimiter character for import/export of fields.
|
void |
setLen(long len)
Truncates or extends the stream to the specified length if this stream
supports such an operation.
|
void |
setPos(long pos)
Moves the current read/write position to the specified absolute 0-based
offset.
|
void |
setUnbuffered()
Makes the stream UNBUFFERED.
|
void |
write(byte[] data)
Write the given byte array to the output stream.
|
void |
write(java.lang.String data)
Write the given string to the output stream.
|
void |
writeByte(byte b)
Write the given byte to the output stream.
|
void |
writeCh(char ch)
Write the given character to the output stream.
|
afterWrite, deleted, deregisterFooter, deregisterHeader, endOutput, export, finished, flushControlled, flushData, forcePageBreak, forcePageBreak, generateStringFormat, getAvailableLines, getControl, getConvert, getDelimiter, getDisplayMode, getEcho, getEffectivePageSize, getLength, getName, getPageNum, getPageSize, getPendingRowCount, getPosition, getUnformatted, hasPageHeadersFooters, indexOfNewLine, isContiguous, isFreshPage, isSuppressFormFeed, isUnbuffered, isUnnamed, isValid, iterate, needsHeadersOutput, needsPageBreak, processFooters, processHeaders, processHeadersInt, processHeadersUncond, protectReads, protectWrites, pulseOutput, put, putControl, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putField, putLineEnd, putLineEnd, putNull, putNull, putSpace, putSpace, rawNextLineNum, rawPageSize, readBlock, readChar, readChar, readChunk, readField, readField, readField, readField, readFieldWorker, readLine, readLineCleanup, registerAdvanceListener, registerCloseListener, registerFlushListener, registerFooter, registerHeader, registerPageBreakListener, resetCurrentLine, retry, setAppend, setBinary, setContiguous, setConvertSource, setConvertTarget, setEcho, setLandscape, setName, setPageSize, setPageSize, setPageSize, setPendingRowCount, setPortrait, setPosition, setPosition, setUnformatted, setUnnamed, skipField, skipLoneHyphenInput, startOutput, writeBlock, writeControlled, writeControlledSpecial, writeField, writeField, writeField, writeField, writeField
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
initFailure
private Stream stream
private boolean inOk
private boolean outOk
public StreamWrapper()
public StreamWrapper(java.lang.String name)
name
- The legacy variable name.public long available() throws java.io.IOException
public long getPos() throws java.lang.UnsupportedOperationException, java.io.IOException
public void setPos(long pos) throws java.lang.UnsupportedOperationException, java.io.IOException
public long getLen() throws java.lang.UnsupportedOperationException, java.io.IOException
public void setLen(long len) throws java.lang.UnsupportedOperationException, java.io.IOException
public void writeCh(char ch) throws java.io.IOException
public void writeByte(byte b) throws java.io.IOException
public void write(java.lang.String data) throws java.io.IOException
public void write(byte[] data) throws java.io.IOException
public int peekCh()
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.
public int readCh()
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.
public java.lang.String readLn() 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.public void closeIn()
public void closeOut()
public void endOutput(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 class Stream
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 close()
assign(com.goldencode.p2j.util.Stream)
is used to "re-open" the stream. This is safe to
call when no stream is open (it will do nothing in that case).public void assign(Stream s) throws java.lang.UnsupportedOperationException
public boolean isTerm()
public void advancePage() throws ErrorConditionException
advancePage
in class Stream
ErrorConditionException
public Stream dereference()
Stream
abstract methods).null
if no stream has yet been opened (assigned
to this instance using assign(com.goldencode.p2j.util.Stream)
).public boolean isIn()
public boolean isOut()
public boolean isSilent()
public void putWorker(FieldEntry[] data, int mode, char delim) throws ErrorConditionException
putWorker
in class Stream
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 putUnformatted(FieldEntry[] data) throws ErrorConditionException
putUnformatted
in class Stream
data
- The list of fields to be output.ErrorConditionException
- On any error during I/O.public void setDelimiter(char delim)
setDelimiter
in class Stream
delim
- The current delimiter char
.public void setDelimiter(java.lang.String delim)
setDelimiter
in class Stream
delim
- The current delimiter char
(if this is not
a single character, only the first character will be used).
If null
or an empty string, the delimiter is
reset to the default of Stream.DELIM
.public void setControl(boolean mode)
Warning: in Progress this is described as ensuring that the "position" (presumably the write position) will not be changed when this option is enabled. However, this really does not make any sense in the case where output characters are used for control purposes. No support is provided for this case.
setControl
in class Stream
mode
- If true
, all output is emitted without
modification of line/page counters.public void setUnbuffered()
setUnbuffered
in class Stream
public void setConvert(boolean convert)
setConvert
in class Stream
convert
- The new character conversion mode. true
to
enable character conversion, false
to disable
conversion.public void setConvertSource(java.lang.String cp)
setConvertSource
in class Stream
cp
- The source codepage for character conversion mode.public void setConvertTarget(java.lang.String cp)
setConvertTarget
in class Stream
cp
- The target codepage for character conversion mode.protected void cleanup(boolean in, boolean out) throws java.io.IOException
boolean needsPageBreak()
needsPageBreak
in class Stream
true
if a page break should be output.int rawGetPageSize()
rawGetPageSize
in class Stream
void rawSetPageSize(int sz)
rawSetPageSize
in class Stream
sz
- The number of lines per page.int rawGetPageNum()
rawGetPageNum
in class Stream
void rawIncrementPageNum()
rawIncrementPageNum
in class Stream
int rawGetNextLineNum()
rawGetNextLineNum
in class Stream
public integer getNextLineNum()
getNextLineNum
in class Stream
void rawIncrementNextLineNum()
rawIncrementNextLineNum
in class Stream
void rawResetNextLineNum()
rawResetNextLineNum
in class Stream