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.
| Modifier and Type | Class and Description |
|---|---|
private static class |
StreamWrapper.WorkArea
Context-local data.
|
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.
|
private static ContextLocal<StreamWrapper.WorkArea> |
work
Context-local data
|
_convert, binary, convert, convertCached, CR, CRLF, DELIM, doneIn, doneOut, EOF, increment, internalCp, isWindows, LF, mapEntryProtermcap, MODE_EXPORT, MODE_PUT_CONTROL, MODE_PUT_NORMAL, MODE_PUT_UNFORMATTED, NEW_LINES, NEWLINE, NEWLINE_LEN, noMap, PAGED_DEFAULT, PIPE_BROKEN_MESSAGE, SET_PAGED_DEFAULT, sourceCharset, sourceCp, streamCp, targetCharset, targetCp, UNKNOWN_VALUE| 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.
|
(package private) static int |
findRemoteStreamId(java.lang.String name)
Finds a stream by its name.
|
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.
|
static StreamWrapper |
getRemoteStreamRef(java.lang.String name)
Finds a stream by its name.
|
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.
|
protected int |
readBlockRemote(memptr var)
Read a block of data from the stream with the block size equal to the size of the binary data array in
the given
memptr variable. |
int |
readByte()
Read a single byte from the underlying stream.
|
byte[] |
readBytes(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. |
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 |
setFont(int num)
Sets the stream font number.
|
void |
setLandscape()
Set stream display mode to landscape
|
void |
setLen(long len)
Truncates or extends the stream to the specified length if this stream
supports such an operation.
|
void |
setLobDirectory(java.lang.String lobDir)
Sets the stream's lob directory located as a subdirectory for opened current file stream directory.
|
void |
setPortrait()
Set stream display mode to portrait
|
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(byte[] data,
int off,
int len)
Write the specified range of bytes from 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, assignDatum, deleted, deregisterFooter, deregisterHeader, endOutput, export, finished, flushControlled, flushData, forcePageBreak, forcePageBreak, generateStringFormat, getAvailableLines, getControl, getConvert, getDelimiter, getDisplayMode, getEcho, getEffectivePageSize, getLength, getName, getPageNum, getPageSize, getPendingRowCount, getPosition, getPulseOnClose, getUnformatted, hasPageHeadersFooters, indexOfNewLine, isContiguous, isFileResource, isFreshPage, isKeepMessages, isNewLine, 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, readBlockWorker, readChar, readChar, readChunk, readField, readField, readField, readField, readFieldWorker, readLine, readLine, readLine, readLine, readLineCleanup, registerAdvanceListener, registerCloseListener, registerFlushListener, registerFooter, registerHeader, registerPageBreakListener, resetCurrentLine, retry, setAppend, setBinary, setContiguous, setConvertSource, setConvertTarget, setEcho, setFlushBeforePut, setFont, setKeepMessages, setLobDirectory, setMap, setName, setNoMap, setPageSize, setPageSize, setPageSize, setPendingRowCount, setPosition, setPosition, setPulseOnClose, setUnformatted, setUnnamed, skipField, skipLoneHyphenInput, startOutput, writeBlob, writeBlock, writeClob, writeControlled, writeControlledSpecial, writeField, writeField, writeField, writeField, writeFieldclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitentry, initFailure, weightprivate Stream stream
private boolean inOk
private boolean outOk
private static final ContextLocal<StreamWrapper.WorkArea> work
public StreamWrapper()
public StreamWrapper(java.lang.String name)
name - The legacy variable name.static int findRemoteStreamId(java.lang.String name)
name - Stream name.public static StreamWrapper getRemoteStreamRef(java.lang.String name)
name - Stream name.null if no such stream exists.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 void write(byte[] data,
int off,
int len)
throws java.io.IOException
write in class Streamdata - The data to be written.off - Starting offset in data from which to read bytes to be written. Must be
non-negative and < data.length.len - 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()
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 int readByte()
public byte[] readBytes(int len)
throws java.io.IOException
EOF, whichever
comes first. The EOF character is not returned.readBytes in class Streamlen - 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 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 StreamappendNewLine - 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 StreamErrorConditionExceptionpublic 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 Streamdata - 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 Streamdata - The list of fields to be output.ErrorConditionException - On any error during I/O.public void setDelimiter(char delim)
setDelimiter in class Streamdelim - The current delimiter char.public void setDelimiter(java.lang.String delim)
setDelimiter in class Streamdelim - 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 Streammode - If true, all output is emitted without
modification of line/page counters.public void setUnbuffered()
setUnbuffered in class Streampublic void setConvert(boolean convert)
setConvert in class Streamconvert - The new character conversion mode. true to
enable character conversion, false to disable
conversion.public void setConvertSource(java.lang.String cp)
setConvertSource in class Streamcp - The source codepage for character conversion mode.public void setConvertTarget(java.lang.String cp)
setConvertTarget in class Streamcp - The target codepage for character conversion mode.public void setLobDirectory(java.lang.String lobDir)
setLobDirectory in class StreamlobDir - The name for subdirectory to store LOB files.public void setFont(int num)
public void setLandscape()
setLandscape in class Streampublic void setPortrait()
setPortrait in class Streamprotected void cleanup(boolean in,
boolean out)
throws java.io.IOException
boolean needsPageBreak()
needsPageBreak in class Streamtrue if a page break should be output.int rawGetPageSize()
rawGetPageSize in class Streamvoid rawSetPageSize(int sz)
rawSetPageSize in class Streamsz - The number of lines per page.int rawGetPageNum()
rawGetPageNum in class Streamvoid rawIncrementPageNum()
rawIncrementPageNum in class Streamint rawGetNextLineNum()
rawGetNextLineNum in class Streampublic integer getNextLineNum()
getNextLineNum in class Streamvoid rawIncrementNextLineNum()
rawIncrementNextLineNum in class Streamvoid rawResetNextLineNum()
rawResetNextLineNum in class Streamprotected int readBlockRemote(memptr var)
Streammemptr variable. The data will be written into the memptr starting at the first
byte in the array. The read data will be the smaller of the block size or the file size. Only an error
or end of file condition will cause this read to terminate before the block size has been read.readBlockRemote in class Streamvar - The variable to which the result is assigned.EOF.