org.kde.koala

Class KBufferedIO

public class KBufferedIO extends KAsyncIO

This abstract class implements basic functionality for buffered input/output. Through the available methods, you can find out how many bytes are available for reading, how many are still unsent and you can peek at the buffered data. This class was intentionally written to resemble QSocket, because KExtendedSocket is a subclass of this one. This is so that applications written using QSocket's buffering characteristics will be more easily ported to the more powerful KExtendedSocket class. KBufferedIO already provides a powerful internal buffering algorithm. However, this does not include the I/O itself, which must be implemented in derived classes. Thus, to implement a class that does some I/O, you must override, in addition to the pure QIODevice methods, these two:
  • closeNow()
  • waitForMore()
  • If your derived class reimplements the buffering algorithm, you must then decide which buffering functions to override. For instance, you may want to change the protected functions like feedReadBuffer() and consumeReadBuffer(). See KBufferedIOSignals for signals emitted by KBufferedIO

    Author: Thiago Macieira

    UNKNOWN: Buffered I/O.

    Field Summary
    static intavailRead
    The modes for closed() signal
    static intclosedNow
    static intdelayed
    static intdirtyWrite
    static intinvoluntary
    Constructor Summary
    protected KBufferedIO(Class dummy)
    Method Summary
    intbytesAvailable()
    Returns the number of bytes available for reading in the read buffer
    intbytesToWrite()
    Returns the number of bytes yet to write, still in the write buffer
    booleancanReadLine()
    Checks whether there is enough data in the buffer to read a line The default implementation reads directly from inBuf, so if your implementation changes the meaning of that member, then you must override this function.
    StringclassName()
    voidcloseNow()
    Closes the stream now, discarding the contents of the write buffer.
    QMetaObjectmetaObject()
    intpeekBlock(String data, int maxlen)
    Reads into the user buffer at most maxlen bytes, but does not consume that data from the read buffer.
    booleansetBufferSize(int rsize, int wsize)
    Sets the internal buffer size to value.
    booleansetBufferSize(int rsize)
    intunreadBlock(String data, int len)
    Unreads some data.
    intwaitForMore(int msec)
    Waits for more data to be available and returns the amount of available data then.

    Field Detail

    availRead

    public static final int availRead
    The modes for closed() signal

    UNKNOWN: The modes for closed() signal

    closedNow

    public static final int closedNow

    delayed

    public static final int delayed

    dirtyWrite

    public static final int dirtyWrite

    involuntary

    public static final int involuntary

    Constructor Detail

    KBufferedIO

    protected KBufferedIO(Class dummy)

    Method Detail

    bytesAvailable

    public int bytesAvailable()
    Returns the number of bytes available for reading in the read buffer

    Returns: the number of bytes available for reading

    UNKNOWN: Returns the number of bytes available for reading in the read buffer

    bytesToWrite

    public int bytesToWrite()
    Returns the number of bytes yet to write, still in the write buffer

    Returns: the number of unwritten bytes in the write buffer

    UNKNOWN: Returns the number of bytes yet to write, still in the write buffer

    canReadLine

    public boolean canReadLine()
    Checks whether there is enough data in the buffer to read a line The default implementation reads directly from inBuf, so if your implementation changes the meaning of that member, then you must override this function.

    Returns: true when there is enough data in the buffer to read a line

    UNKNOWN: Checks whether there is enough data in the buffer to read a line

    className

    public String className()

    closeNow

    public void closeNow()
    Closes the stream now, discarding the contents of the write buffer. That is, we won't try to flush that buffer before closing. If you want that buffer to be flushed, you can call QIODevice.flush(), which is blocking, and then closeNow, or you can call QIODevice.close() for a delayed close.

    UNKNOWN: Closes the stream now, discarding the contents of the write buffer.

    metaObject

    public QMetaObject metaObject()

    peekBlock

    public int peekBlock(String data, int maxlen)
    Reads into the user buffer at most maxlen bytes, but does not consume that data from the read buffer. This is useful to check whether we already have the needed data to process something. This function may want to try and read more data from the system provided it won't block.

    Parameters: data the user buffer pointer, at least maxlen bytes long maxlen the maximum length to be peeked

    Returns: the number of bytes actually copied.

    UNKNOWN: Reads into the user buffer at most maxlen bytes, but does not consume that data from the read buffer.

    setBufferSize

    public boolean setBufferSize(int rsize, int wsize)
    Sets the internal buffer size to value. Not all implementations support this. The parameters may be 0 to make the class unbuffered or -1 to let the class choose the size (which may be unlimited) or -2 to leave the buffer size untouched. Note that setting the write buffer size to any value smaller than the current size of the buffer will force it to flush first, which can make this call blocking. The default implementation does not support setting the buffer sizes. You can only call this function with values -1 for "don't care" or -2 for "unchanged"

    Parameters: rsize the size of the read buffer wsize the size of the write buffer

    Returns: true if setting both was ok. If false is returned, the buffers were left unchanged.

    UNKNOWN: Sets the internal buffer size to value.

    setBufferSize

    public boolean setBufferSize(int rsize)

    unreadBlock

    public int unreadBlock(String data, int len)
    Unreads some data. That is, write the data to the beginning of the read buffer, so that next calls to readBlock or peekBlock will see this data instead. Note not all devices implement this since this could mean a semantic problem. For instance, sockets are sequential devices, so they won't accept unreading.

    Parameters: data the data to be unread len the size of the data

    Returns: the number of bytes actually unread

    UNKNOWN: Unreads some data.

    waitForMore

    public int waitForMore(int msec)
    Waits for more data to be available and returns the amount of available data then.

    Parameters: msec number of milliseconds to wait, -1 to wait forever

    Returns: -1 if we cannot wait (e.g., that doesn't make sense in this stream)

    UNKNOWN: Waits for more data to be available and returns the amount of available data then.