|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.core.QIODevice
com.trolltech.qt.core.QBuffer
public class QBuffer
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 = new QBuffer(); int b; buffer.open(QIODevice.OpenModeFlag.ReadWrite); buffer.write(new QByteArray("Qt rocks!")); buffer.seek(0); b = buffer.getByte(); // b == 'Q' b = buffer.getByte(); // b == 't' b = buffer.getByte(); // b == ' ' b = buffer.getByte(); // b == '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 = new QByteArray(); QBuffer buffer = new QBuffer(byteArray); buffer.open(QIODevice.OpenModeFlag.WriteOnly); QDataStream out = new QDataStream(buffer); out.writeString("Any string will do.");Effectively, we convert the application's
QPalette
into a byte array. Here's how to read the data from the QByteArray
: String string = ""; QBuffer buffer = new QBuffer(byteArray); buffer.open(QIODevice.OpenModeFlag.ReadOnly); QDataStream in = new QDataStream(buffer); string = in.readString();
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.
QFile
, QDataStream
, QTextStream
, and 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, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal |
Field Summary |
---|
Fields inherited from class com.trolltech.qt.core.QIODevice |
---|
aboutToClose, bytesWritten, readChannelFinished, readyRead |
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
currentSender |
Constructor Summary | |
---|---|
QBuffer()
Constructs an empty buffer with the given parent. |
|
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 | |
---|---|
QByteArray |
buffer()
Returns a reference to the QBuffer 's internal buffer. |
QByteArray |
data()
Returns the data contained in the buffer. |
void |
setBuffer(QByteArray byteArray)
Makes the QBuffer use the byteArray as its internal buffer. |
void |
setData(byte[] data)
Sets the contents of this QBuffer to data |
void |
setData(QByteArray data)
Sets the contents of the internal buffer to be data. |
Methods inherited from class com.trolltech.qt.core.QIODevice |
---|
atEnd, bytesAvailable, bytesToWrite, canReadLine, close, errorString, getByte, isOpen, isReadable, isSequential, isTextModeEnabled, isWritable, open, open, openMode, peek, peek, pos, putByte, read, read, readAll, readData, readLine, readLine, readLine, readLineData, reset, seek, setErrorString, setOpenMode, setOpenMode, setTextModeEnabled, size, ungetByte, waitForBytesWritten, waitForReadyRead, write, write, writeData |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal |
---|
__qt_signalInitialization |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QBuffer()
setData()
to fill the buffer with data, or you can open it in write mode and use write()
. open()
.
public QBuffer(QObject parent)
setData()
to fill the buffer with data, or you can open it in write mode and use write()
. open()
.
public QBuffer(QByteArray byteArray, QObject parent)
If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, byteArray will be modified.
public QBuffer(QByteArray byteArray)
Method Detail |
---|
public final QByteArray buffer()
QBuffer
's internal buffer. You can use it to modify the QByteArray
behind the QBuffer
's back. setBuffer()
, and data()
.
public final QByteArray data()
This is the same as buffer()
.
setData()
, and setBuffer()
.
public final void setData(QByteArray data)
buffer()
. Does nothing if isOpen()
is true.
data()
, and setBuffer()
.
public final void setBuffer(QByteArray byteArray)
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.
public final void setData(byte[] data)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |