1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.spdy.api;
20
21 import java.nio.ByteBuffer;
22
23
24
25
26 public class BytesDataInfo extends DataInfo
27 {
28 private final byte[] bytes;
29 private final int offset;
30 private final int length;
31 private int index;
32
33 public BytesDataInfo(byte[] bytes, boolean close)
34 {
35 this(bytes, 0, bytes.length, close);
36 }
37
38 public BytesDataInfo(byte[] bytes, int offset, int length, boolean close)
39 {
40 super(close, false);
41 this.bytes = bytes;
42 this.offset = offset;
43 this.length = length;
44 this.index = offset;
45 }
46
47 @Override
48 public int length()
49 {
50 return length;
51 }
52
53 @Override
54 public int available()
55 {
56 return length - index + offset;
57 }
58
59 @Override
60 public int readInto(ByteBuffer output)
61 {
62 int space = output.remaining();
63 int chunk = Math.min(available(), space);
64 output.put(bytes, index, chunk);
65 index += chunk;
66 return chunk;
67 }
68 }