public abstract class DataInfo extends Object
A container for DATA frames metadata and content bytes.
Specialized subclasses (like StringDataInfo
) may be used by applications
to send specific types of content.
Applications may send multiple instances of DataInfo
, usually of the same
type, via Stream.data(DataInfo)
. The last instance must have the
close flag
set, so that the client knows that no more content is
expected.
Receivers of DataInfo
via StreamFrameListener.onData(Stream, DataInfo)
have two different APIs to read the data content bytes: a read
API that does not interact with flow control, and a drain
API that interacts with flow control.
Flow control is defined so that when the sender wants to sends a number of bytes larger
than the Settings.ID.INITIAL_WINDOW_SIZE
value, it will stop sending as soon as it
has sent a number of bytes equal to the window size. The receiver has to consume
the data bytes that it received in order to tell the sender to send more bytes.
Consuming the data bytes can be done only via consumeInto(ByteBuffer)
or by a combination
of readInto(ByteBuffer)
and consume(int)
(possibly at different times).
Modifier and Type | Field and Description |
---|---|
static byte |
FLAG_CLOSE
Flag that indicates that this
DataInfo is the last frame in the stream. |
static byte |
FLAG_COMPRESS
Flag that indicates that this
DataInfo 's data is compressed. |
Constructor and Description |
---|
DataInfo(boolean close)
Creates a new
DataInfo with the given close flag and no compression flag. |
DataInfo(boolean close,
boolean compress)
Creates a new
DataInfo with the given close flag and given compression flag. |
Modifier and Type | Method and Description |
---|---|
protected ByteBuffer |
allocate(int size) |
ByteBuffer |
asByteBuffer(boolean consume) |
byte[] |
asBytes(boolean consume) |
String |
asString(String charset,
boolean consume) |
abstract int |
available()
Returns the available content bytes that can be read via
readInto(ByteBuffer) . |
void |
consume(int delta)
Consumes the given number of bytes from this
DataInfo . |
int |
consumed() |
int |
consumeInto(ByteBuffer output)
Reads and consumes the content bytes of this
DataInfo into the given ByteBuffer . |
byte |
getFlags() |
boolean |
isClose() |
boolean |
isCompress() |
abstract int |
length() |
abstract int |
readInto(ByteBuffer output)
Copies the content bytes of this
DataInfo into the given ByteBuffer . |
void |
setClose(boolean close) |
void |
setCompress(boolean compress) |
String |
toString() |
public static final byte FLAG_CLOSE
Flag that indicates that this DataInfo
is the last frame in the stream.
isClose()
,
getFlags()
,
Constant Field Valuespublic static final byte FLAG_COMPRESS
Flag that indicates that this DataInfo
's data is compressed.
isCompress()
,
getFlags()
,
Constant Field Valuespublic DataInfo(boolean close)
Creates a new DataInfo
with the given close flag and no compression flag.
close
- the value of the close flagpublic DataInfo(boolean close, boolean compress)
Creates a new DataInfo
with the given close flag and given compression flag.
close
- the close flagcompress
- the compress flagpublic boolean isCompress()
setCompress(boolean)
public void setCompress(boolean compress)
compress
- the value of the compress flagisCompress()
public boolean isClose()
setClose(boolean)
public void setClose(boolean close)
close
- the value of the close flagisClose()
public byte getFlags()
FLAG_CLOSE
,
FLAG_COMPRESS
public abstract int length()
available()
public abstract int available()
Returns the available content bytes that can be read via readInto(ByteBuffer)
.
Each invocation to readInto(ByteBuffer)
modifies the value returned by this method,
until no more content bytes are available.
readInto(ByteBuffer)
public abstract int readInto(ByteBuffer output)
Copies the content bytes of this DataInfo
into the given ByteBuffer
.
If the given ByteBuffer
cannot contain the whole content of this DataInfo
then after the read available()
will return a positive value, and further content
may be retrieved by invoking again this method with a new output buffer.
output
- the ByteBuffer
to copy to bytes intoavailable()
,
consumeInto(ByteBuffer)
public int consumeInto(ByteBuffer output)
Reads and consumes the content bytes of this DataInfo
into the given ByteBuffer
.
output
- the ByteBuffer
to copy the bytes intoconsume(int)
public void consume(int delta)
Consumes the given number of bytes from this DataInfo
.
delta
- the number of bytes consumedpublic int consumed()
public String asString(String charset, boolean consume)
charset
- the charset used to convert the bytesconsume
- whether to consume the contentDataInfo
public byte[] asBytes(boolean consume)
consume
- whether to consume the contentDataInfo
public ByteBuffer asByteBuffer(boolean consume)
consume
- whether to consume the contentByteBuffer
with the content of this DataInfo
protected ByteBuffer allocate(int size)
Copyright © 1995-2013 Mort Bay Consulting. All Rights Reserved.