Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.core
Class QBuffer

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.core.QIODevice
                      com.trolltech.qt.core.QBuffer

All Implemented Interfaces:
  QtJambiInterface

    public class QBuffer

extends QIODevice

The `QBuffer` class provides a `QIODevice` interface for a `QByteArray`.

`QBuffer` allows you to access a `QByteArray` using the `QIODevice` interface. The `QByteArray` is treated just as a standard random-accessed file. Example:

            QBuffer buffer;
            char ch;

            buffer.open(QBuffer::ReadWrite);
            buffer.write("Qt rocks!");
            buffer.seek(0);
            buffer.getChar(&ch);  // ch == 'Q'
            buffer.getChar(&ch);  // ch == 't'
            buffer.getChar(&ch);  // ch == ' '
            buffer.getChar(&ch);  // ch == 'r'

By default, an internal `QByteArray` buffer is created for you when you create a `QBuffer`. You can access this buffer directly by calling `buffer`. You can also use `QBuffer` with an existing `QByteArray` by calling setBuffer(), or by passing your array to `QBuffer`'s constructor.

Call `open` to open the buffer. Then call `write` or putChar() to write to the buffer, and `read`, `readLine`, `readAll`, or getChar() to read from it. `size` returns the current size of the buffer, and you can seek to arbitrary positions in the buffer by calling `seek`. When you are done with accessing the buffer, call `close`.

The following code snippet shows how to write data to a `QByteArray` using `QDataStream` and `QBuffer`:

            QByteArray byteArray;
            QBuffer buffer(&byteArray);
            buffer.open(QIODevice::WriteOnly);

            QDataStream out(&buffer);
            out << QApplication::palette();

Effectively, we convert the application's `QPalette` into a byte array. Here's how to read the data from the `QByteArray`:

            QPalette palette;
            QBuffer buffer(&byteArray);
            buffer.open(QIODevice::ReadOnly);

            QDataStream in(&buffer);
            in >> palette;

`QTextStream` and `QDataStream` also provide convenience constructors that take a `QByteArray` and that create a `QBuffer` behind the scenes.

`QBuffer` emits `readyRead` when new data has arrived in the buffer. By connecting to this signal, you can use `QBuffer` to store temporary data before processing it. For example, you can pass the buffer to `QFtp` when downloading a file from an FTP server. Whenever a new payload of data has been downloaded, `readyRead` is emitted, and you can process the data that just arrived. `QBuffer` also emits `bytesWritten` every time new data has been written to the buffer.

See Also:
  `QFile`, `QDataStream`, `QTextStream`, `QByteArray`

Nested Class Summary

Nested classes/interfaces inherited from class com.trolltech.qt.core.QIODevice
`QIODevice.OpenMode, QIODevice.OpenModeFlag`

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>`

Field Summary

Fields inherited from class com.trolltech.qt.core.QIODevice
`aboutToClose, bytesWritten, readyRead`

Constructor Summary
`QBuffer()` Equivalent to `QBuffer`(0).
`QBuffer(QByteArray byteArray)` Constructs a new QByteArray of which contents will be equal to `byteArray`.
`QBuffer(QByteArray byteArray, QObject parent)` Constructs a QBuffer that uses the QByteArray pointed to by `byteArray` as its internal buffer, and with the given `parent`.
`QBuffer(QObject parent)` Constructs an empty buffer with the given `parent`.

Method Summary
`boolean` | `atEnd()` This function is reimplemented for internal reasons.
`QByteArray` | `buffer()` This is the same as `data`.
`boolean` | `canReadLine()` This function is reimplemented for internal reasons.
`void` | `close()` This function is reimplemented for internal reasons.
`QByteArray` | `data()` Returns the data contained in the buffer.
`static QBuffer` | `fromNativePointer(QNativePointer nativePointer)` This function returns the QBuffer instance pointed to by nativePointer
`boolean` | `open(QIODevice.OpenMode openMode)` Opens the device and sets its OpenMode to `openMode`.
`long` | `pos()` This function is reimplemented for internal reasons.
`protected int` | `readData(byte[] data)` Equivalent to `readData`(`data`, ).
`boolean` | `seek(long off)` For random-access devices, this function sets the current position to `off`, returning true on success, or false if an error occurred.
`void` | `setBuffer(QByteArray byteArray)` Makes the QBuffer use the `byteArray` as its internal buffer.
`void` | `setData(byte[] data)` Sets the contents of the internal buffer to be `data`.
`void` | `setData(QByteArray data)` Sets the contents of the internal buffer to be `data`.
`long` | `size()` This function is reimplemented for internal reasons.
`protected int` | `writeData(byte[] data)` Equivalent to `writeData`(`data`, ).

Methods inherited from class com.trolltech.qt.core.QIODevice
`bytesAvailable, bytesToWrite, errorString, getByte, isOpen, isReadable, isSequential, isTextModeEnabled, isWritable, open, openMode, peek, peek, putByte, read, read, readAll, readLine, readLine, readLine, readLineData, reset, setErrorString, setOpenMode, setOpenMode, setTextModeEnabled, ungetByte, waitForBytesWritten, waitForReadyRead, write, write`

Methods inherited from class com.trolltech.qt.core.QObject
`blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`disconnect, disconnect, signalSender`

Methods inherited from class java.lang.Object
`clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Constructor Detail

### QBuffer

    public QBuffer()

  Equivalent to `QBuffer`(0).

### QBuffer

    public QBuffer(QObject parent)

  Constructs an empty buffer with the given `parent`. You can call `setData` to fill the buffer with data, or you can open it in write mode and use `write`.

  See Also:
    `open`

### QBuffer

    public QBuffer(QByteArray byteArray,
                   QObject parent)

  Constructs a QBuffer that uses the QByteArray pointed to by `byteArray` as its internal buffer, and with the given `parent`. The caller is responsible for ensuring that `byteArray` remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer doesn't take ownership of the QByteArray.

  If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, `byteArray` will be modified.

### QBuffer

    public QBuffer(QByteArray byteArray)

  Constructs a new QByteArray of which contents will be equal to `byteArray`.

Method Detail

### buffer

    public final QByteArray buffer()

  This is the same as `data`.

### data

    public final QByteArray data()

  Returns the data contained in the buffer.

  This is the same as `buffer`.

  See Also:
    `setData`, `setBuffer`

### setData

    public final void setData(QByteArray data)

  Sets the contents of the internal buffer to be `data`. This is the same as assigning `data` to `buffer`.

  Does nothing if `isOpen` is true.

  See Also:
    `data`, `setBuffer`

### atEnd

    public boolean atEnd()

  This function is reimplemented for internal reasons.

  Overrides:
    `atEnd` in class `QIODevice`
  See Also:
    `bytesAvailable`, `read`, `isSequential`

### canReadLine

    public boolean canReadLine()

  This function is reimplemented for internal reasons.

  Overrides:
    `canReadLine` in class `QIODevice`
  See Also:
    `readyRead`, `readLine`

### close

    public void close()

  This function is reimplemented for internal reasons.

  Overrides:
    `close` in class `QIODevice`
  See Also:
    `setOpenMode`, `OpenMode`

### open

    public boolean open(QIODevice.OpenMode openMode)

  Opens the device and sets its OpenMode to `openMode`. Returns true if successful; otherwise returns false.

  Overrides:
    `open` in class `QIODevice`
  See Also:
    `openMode`, `OpenMode`

### pos

    public long pos()

  This function is reimplemented for internal reasons.

  Overrides:
    `pos` in class `QIODevice`
  See Also:
    `isSequential`, `seek`

### readData

    protected int readData(byte[] data)

  Equivalent to `readData`(`data`, ).

  Specified by:
    `readData` in class `QIODevice`

### seek

    public boolean seek(long off)

  For random-access devices, this function sets the current position to `off`, returning true on success, or false if an error occurred. For sequential devices, the default behavior is to do nothing and return false.

  When subclassing `QIODevice`, you must call QIODevice::seek() at the start of your function to ensure integrity with `QIODevice`'s built-in buffer. The base implementation always returns true.

  Overrides:
    `seek` in class `QIODevice`
  See Also:
    `pos`, `isSequential`

### size

    public long size()

  This function is reimplemented for internal reasons.

  Overrides:
    `size` in class `QIODevice`
  See Also:
    `isSequential`, `pos`

### writeData

    protected int writeData(byte[] data)

  Equivalent to `writeData`(`data`, ).

  Specified by:
    `writeData` in class `QIODevice`

### fromNativePointer

    public static QBuffer fromNativePointer(QNativePointer nativePointer)

  This function returns the QBuffer instance pointed to by nativePointer

  Parameters:
    `nativePointer` - the QNativePointer of which object should be returned.

### setBuffer

    public void setBuffer(QByteArray byteArray)

  Makes the QBuffer use the `byteArray` as its internal buffer.

  Does nothing if isOpen() is true.

  If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, \a byteArray will be modified.

  If `byteArray` is null, the buffer creates its own internal QByteArray to work on. This byte array is initially empty.

### setData

    public final void setData(byte[] data)

  Sets the contents of the internal buffer to be `data`.

  Does nothing if isOpen() is true.

Overview | Package | Class | Tree | Deprecated | Index | Help
Qt Jambi Home |
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD