Better choice for direct ByteBuffer size.

This commit is contained in:
Simone Bordet 2012-03-01 12:56:18 +01:00
parent f4e4effe50
commit 5f61ffc024
1 changed files with 5 additions and 1 deletions

View File

@ -25,7 +25,11 @@ public class DataFrameGenerator
{
public ByteBuffer generate(int streamId, int windowSize, DataInfo dataInfo)
{
ByteBuffer buffer = ByteBuffer.allocateDirect(DataFrame.HEADER_LENGTH + windowSize);
// TODO: use buffer pool
int size = dataInfo.length();
if (size > windowSize)
size = windowSize;
ByteBuffer buffer = ByteBuffer.allocateDirect(DataFrame.HEADER_LENGTH + size);
buffer.position(DataFrame.HEADER_LENGTH);
// Guaranteed to always be >= 0
int read = dataInfo.readInto(buffer);