1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http2.parser;
20
21 import java.nio.ByteBuffer;
22
23 import org.eclipse.jetty.http2.frames.PriorityFrame;
24
25 public class HeaderBlockFragments
26 {
27 private PriorityFrame priorityFrame;
28 private boolean endStream;
29 private int streamId;
30 private ByteBuffer storage;
31
32 public void storeFragment(ByteBuffer fragment, int length, boolean last)
33 {
34 if (storage == null)
35 {
36 int space = last ? length : length * 2;
37 storage = ByteBuffer.allocate(space);
38 }
39
40
41 if (storage.remaining() < length)
42 {
43 int space = last ? length : length * 2;
44 int capacity = storage.position() + space;
45 ByteBuffer newStorage = ByteBuffer.allocate(capacity);
46 storage.flip();
47 newStorage.put(storage);
48 storage = newStorage;
49 }
50
51
52 int limit = fragment.limit();
53 fragment.limit(fragment.position() + length);
54 storage.put(fragment);
55 fragment.limit(limit);
56 }
57
58 public PriorityFrame getPriorityFrame()
59 {
60 return priorityFrame;
61 }
62
63 public void setPriorityFrame(PriorityFrame priorityFrame)
64 {
65 this.priorityFrame = priorityFrame;
66 }
67
68 public boolean isEndStream()
69 {
70 return endStream;
71 }
72
73 public void setEndStream(boolean endStream)
74 {
75 this.endStream = endStream;
76 }
77
78 public ByteBuffer complete()
79 {
80 ByteBuffer result = storage;
81 storage = null;
82 result.flip();
83 return result;
84 }
85
86 public int getStreamId()
87 {
88 return streamId;
89 }
90
91 public void setStreamId(int streamId)
92 {
93 this.streamId = streamId;
94 }
95 }