|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecttcl.lang.channel.Channel
public abstract class Channel
The Channel class provides functionality that will be needed for any type of Tcl channel. It performs generic reads, writes, without specifying how a given channel is actually created. Each new channel type will need to extend the abstract Channel class and override any methods it needs to provide a specific implementation for.
Field Summary | |
---|---|
protected boolean |
blocking
Set to false when channel is in non-blocking mode. |
protected int |
buffering
Buffering (full,line, or none) |
protected int |
bufferSize
Buffer size, in bytes, allocated for channel to store input or output |
protected String |
encoding
Name of Java encoding for this Channel. |
protected tcl.lang.channel.EofInputFilter |
eofInputFilter
The EOF input filter for this channel, which translates the EOF character. |
protected tcl.lang.channel.EofOutputFilter |
eofOutputFilter
This OutputStream writes the EOF character, and prevents this Chanel's getOutputStream() from being closed by the chain. |
protected tcl.lang.channel.EolInputFilter |
eolInputFilter
The EOL input filter for this channel. |
protected tcl.lang.channel.EolOutputFilter |
eolOutputFilter
This Writer translates EOL characters on output, and performs BUFF_LINE flushes |
protected InputStream |
finalInputStream
This InputStream is the source of processed bytes for Channel.read() |
protected Reader |
finalReader
This Reader is the source of processed characters for Channel.read() |
protected OutputStream |
firstOutputStream
This OutputStream is the Channel's entry into the output chain for efficient byte writes |
protected Writer |
firstWriter
This Writer is the Channel's entry into the output chain |
protected tcl.lang.channel.InputBuffer |
inputBuffer
The input buffer for this channel. |
protected char |
inputEofChar
If nonzero, use this as a signal of EOF on input. |
protected int |
inputTranslation
Input translation mode for end-of-line character |
protected tcl.lang.channel.MarkableInputStream |
markableInputStream
Allows backtracking in the stream for this channel |
protected int |
mode
The read, write, append and create flags are set here. |
protected tcl.lang.channel.NonBlockingOutputStream |
nonBlockingOutputStream
This OutputStream prevents outputs from blocking on a non-blocking channel |
protected tcl.lang.channel.OutputBuffer |
outputBuffer
This OutputStream buffers output data for the Channel |
protected char |
outputEofChar
If nonzero, append this to a writeable channel on close. |
protected int |
outputTranslation
Output translation mode for end-of-line character |
protected InputStream |
rawInputStream
The underlying input stream offered by the implementation |
protected OutputStream |
rawOutputStream
The underlying output stream offered by the implementation |
static int |
READ_OWNERSHIP
Indicate that thread wants read ownership |
int |
refCount
How many interpreters hold references to this IO channel? |
protected tcl.lang.channel.UnicodeDecoder |
unicodeDecoder
The unicode decoder for reading characters on this channel |
protected tcl.lang.channel.UnicodeEncoder |
unicodeEncoder
This Writer translates Unicode to bytes for output |
static int |
WRITE_OWNERSHIP
Indicate tht thread wants write ownership |
Method Summary | |
---|---|
protected void |
checkRead(Interp interp)
Tests if this Channel was opened for reading |
protected void |
checkWrite(Interp interp)
Tests if this Channel was opened for writing |
void |
close()
Close the Channel. |
boolean |
eof()
Returns true if the last read reached the end of file. |
void |
flush(Interp interp)
Flush the Channel. |
boolean |
getBlocking()
|
int |
getBuffering()
|
int |
getBufferSize()
|
String |
getChanName()
Get the channel name |
String |
getEncoding()
Query this Channel's encoding |
char |
getInputEofChar()
|
protected abstract InputStream |
getInputStream()
This method should be overridden in the subclass to provide a channel specific InputStream object. |
int |
getInputTranslation()
|
char |
getOutputEofChar()
|
protected abstract OutputStream |
getOutputStream()
This method should be overridden in the subclass to provide a channel specific OutputStream object. |
int |
getOutputTranslation()
|
protected void |
initInput()
Setup the input stream chain on the first read |
protected void |
initOutput()
Setup output stream chain on the first write |
boolean |
isBlocked(Interp interp)
Tests if last read was incomplete due to a blocked channel |
boolean |
isClosed()
Returns true of close() has been called |
boolean |
isReadOnly()
|
boolean |
isReadWrite()
|
boolean |
isWriteOnly()
|
int |
read(Interp interp,
TclObject tobj,
int readType,
int numBytes)
Tcl_ReadChars -> read Read data from this Channel into the given TclObject. |
void |
seek(Interp interp,
long offset,
int mode)
Move the current file pointer. |
void |
setBlocking(boolean inBlocking)
Set blocking mode. |
void |
setBuffering(int inBuffering)
Set buffering mode |
void |
setBufferSize(int size)
Tcl_SetChannelBufferSize -> setBufferSize Sets the buffer size |
void |
setEncoding(String inEncoding)
Set new Java encoding. |
void |
setInputEofChar(char inEof)
Set new input eof character, if channel is readable |
void |
setInputTranslation(int translation)
Set new input translation if this channel is not write-only |
void |
setOutputEofChar(char outEof)
Set new output eof character if this channel is writeable |
void |
setOutputTranslation(int translation)
Set new output translation if this channel is writeable |
boolean |
setOwnership(boolean takeOwnership,
int type)
Ask for or give up ownership to channel |
boolean |
setOwnership(boolean takeOwnership,
int type,
long threadId)
Ask for or give up ownership to channel |
long |
tell()
|
void |
waitForOwnership(int type)
Block until ownership to this channel is granted to the current thread |
void |
write(Interp interp,
String outStr)
Tcl_WriteChars -> write Write string data to the Channel. |
void |
write(Interp interp,
TclObject outData)
Tcl_WriteObj -> write Write data to the Channel |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int mode
public int refCount
protected boolean blocking
protected tcl.lang.channel.InputBuffer inputBuffer
protected InputStream rawInputStream
protected OutputStream rawOutputStream
protected tcl.lang.channel.EolInputFilter eolInputFilter
protected tcl.lang.channel.EofInputFilter eofInputFilter
protected tcl.lang.channel.UnicodeDecoder unicodeDecoder
protected InputStream finalInputStream
protected tcl.lang.channel.MarkableInputStream markableInputStream
protected Reader finalReader
protected tcl.lang.channel.EolOutputFilter eolOutputFilter
protected tcl.lang.channel.UnicodeEncoder unicodeEncoder
protected tcl.lang.channel.OutputBuffer outputBuffer
protected tcl.lang.channel.EofOutputFilter eofOutputFilter
protected tcl.lang.channel.NonBlockingOutputStream nonBlockingOutputStream
protected Writer firstWriter
protected OutputStream firstOutputStream
protected int buffering
protected int bufferSize
protected String encoding
protected int inputTranslation
protected int outputTranslation
protected char inputEofChar
protected char outputEofChar
public static final int READ_OWNERSHIP
public static final int WRITE_OWNERSHIP
Method Detail |
---|
public int read(Interp interp, TclObject tobj, int readType, int numBytes) throws IOException, TclException
interp
- is used for TclExceptions.tobj
- the object that data will be added to.readType
- specifies if the read should read the entire input
(TclIO.READ_ALL), the next line without the end-of-line
character (TclIO.READ_LINE), or a specified number of bytes
(TclIO.READ_N_BYTES).numBytes
- the number of bytes/chars to read. Ignored unless readType is
TclIO.READ_N_BYTES.
TclException
- is thrown if read occurs on WRONLY channel.
IOException
- is thrown when an IO error occurs that was not correctly
tested for. Most cases should be caught.public void write(Interp interp, TclObject outData) throws IOException, TclException
interp
- is used for TclExceptions.outData
- the TclObject that holds the data to write.
IOException
TclException
public void write(Interp interp, String outStr) throws IOException, TclException
interp
- is used for TclExceptions.outStr
- the String object to write.
IOException
TclException
public boolean setOwnership(boolean takeOwnership, int type)
takeOwnership
- if true, give Channel ownership to the current thread if no
other thread owns it; otherwise, give up ownership if the
current thread owns ittype
- Either READ_OWNERSHIP or WRITE_OWNERSHIP
public boolean setOwnership(boolean takeOwnership, int type, long threadId)
takeOwnership
- if true, give Channel ownership to the current thread if no
other thread owns it; otherwise, give up ownership if the
current thread owns ittype
- Either READ_OWNERSHIP or WRITE_OWNERSHIPthreadId
- Thread.getId() of thread that should own the channel
public void waitForOwnership(int type) throws InterruptedException
type
- Either READ_OWNERSHIP or WRITE_OWNERSHIP
InterruptedException
public void close() throws IOException
IOException
public void flush(Interp interp) throws IOException, TclException
TclException
- when attempting to flush a read only channel.
IOException
- for all other flush errors.public void seek(Interp interp, long offset, int mode) throws IOException, TclException
interp
- currrent interpreter.offset
- The number of bytes to move the file pointer.mode
- where to begin incrementing the file pointer; beginning,
current, end.
TclException
- if channel does not support seek
IOException
public long tell() throws IOException
IOException
protected void initInput() throws IOException
IOException
protected void initOutput() throws IOException
IOException
public boolean eof()
public boolean isClosed()
protected abstract InputStream getInputStream() throws IOException
IOException
protected abstract OutputStream getOutputStream() throws IOException
IOException
public String getChanName()
public boolean isReadOnly()
public boolean isWriteOnly()
public boolean isReadWrite()
protected void checkRead(Interp interp) throws TclException
interp
- the current interpreter
TclException
- if this channel was not opened for readingprotected void checkWrite(Interp interp) throws TclException
interp
- the current interpreter
TclException
- if this Channel was not opened for writingpublic boolean getBlocking()
public void setBlocking(boolean inBlocking)
inBlocking
- True for blocking mode, false for non-blocking mode.public int getBuffering()
public void setBuffering(int inBuffering)
inBuffering
- One of TclIO.BUFF_FULL, TclIO.BUFF_LINE, or TclIO.BUFF_NONEpublic int getBufferSize()
public void setBufferSize(int size)
size
- new buffer size. Resize request is ignored if size < 1 or > 1
Mbytepublic boolean isBlocked(Interp interp) throws TclException
interp
- current interpreter
TclException
- if this channel is not opened for readingpublic String getEncoding()
public void setEncoding(String inEncoding)
inEncoding
- Java-style encoding stringpublic int getInputTranslation()
public void setInputTranslation(int translation)
translation
- one of the TclIO.TRANS_* constantspublic int getOutputTranslation()
public void setOutputTranslation(int translation)
translation
- one of the TclIO.TRANS_* constantspublic char getInputEofChar()
public void setInputEofChar(char inEof)
inEof
- new EOF character, or 0 if nonepublic char getOutputEofChar()
public void setOutputEofChar(char outEof)
outEof
- new EOF character, or 0 if none
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |