public abstract class DataInfo extends Info
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. |
Modifier | Constructor and Description |
---|---|
|
DataInfo(boolean close)
Creates a new
DataInfo with the given close flag and no compression flag. |
protected |
DataInfo(long timeout,
TimeUnit unit,
boolean close)
Creates a new
DataInfo with the given close flag and no compression flag. |
Modifier and Type | Method and Description |
---|---|
protected ByteBuffer |
allocate(int size) |
ByteBuffer |
asByteBuffer(boolean consume) |
byte[] |
asBytes(boolean consume) |
String |
asString(Charset charset,
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(byte[] bytes,
int offset,
int length)
Reads and consumes the content bytes of this
DataInfo into the given byte array,
starting from index offset for length bytes. |
int |
consumeInto(ByteBuffer output)
Reads and consumes the content bytes of this
DataInfo into the given ByteBuffer . |
byte |
getFlags() |
boolean |
isClose() |
abstract int |
length() |
abstract int |
readInto(byte[] bytes,
int offset,
int length)
Copies the content bytes of this
DataInfo into the given byte array. |
abstract int |
readInto(ByteBuffer output)
Copies the content bytes of this
DataInfo into the given ByteBuffer . |
void |
setClose(boolean close) |
String |
toString() |
getTimeout, getUnit
public static final byte FLAG_CLOSE
Flag that indicates that this DataInfo
is the last frame in the stream.
isClose()
,
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 boolean isClose()
setClose(boolean)
public void setClose(boolean close)
close
- the value of the close flagisClose()
public byte getFlags()
FLAG_CLOSE
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 the bytes intoavailable()
,
consumeInto(ByteBuffer)
public abstract int readInto(byte[] bytes, int offset, int length)
Copies the content bytes of this DataInfo
into the given byte array.
If the given byte array 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 byte array.
bytes
- the byte array to copy the bytes intooffset
- the index of the byte array to start copyinglength
- the number of bytes to copypublic 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 int consumeInto(byte[] bytes, int offset, int length)
Reads and consumes the content bytes of this DataInfo
into the given byte array,
starting from index offset
for length
bytes.
bytes
- the byte array to copy the bytes intooffset
- the offset of the byte array to start copyinglength
- the number of bytes to copypublic 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 String asString(Charset 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-2015 Webtide. All Rights Reserved.