1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.eclipse.jetty.spdy.generator;
18
19 import java.nio.ByteBuffer;
20
21 import org.eclipse.jetty.spdy.ByteBufferPool;
22 import org.eclipse.jetty.spdy.api.DataInfo;
23 import org.eclipse.jetty.spdy.frames.DataFrame;
24
25 public class DataFrameGenerator
26 {
27 private final ByteBufferPool bufferPool;
28
29 public DataFrameGenerator(ByteBufferPool bufferPool)
30 {
31 this.bufferPool = bufferPool;
32 }
33
34 public ByteBuffer generate(int streamId, int length, DataInfo dataInfo)
35 {
36 ByteBuffer buffer = bufferPool.acquire(DataFrame.HEADER_LENGTH + length, true);
37 buffer.position(DataFrame.HEADER_LENGTH);
38
39 int read = dataInfo.readInto(buffer);
40
41 buffer.putInt(0, streamId & 0x7F_FF_FF_FF);
42 buffer.putInt(4, read & 0x00_FF_FF_FF);
43
44 byte flags = dataInfo.getFlags();
45 if (dataInfo.available() > 0)
46 flags &= ~DataInfo.FLAG_CLOSE;
47 buffer.put(4, flags);
48
49 buffer.flip();
50 return buffer;
51 }
52 }