1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.dexterim.oscar;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
24
25 import net.sf.dexterim.oscar.entity.ByteBased;
26 import net.sf.dexterim.oscar.entity.DWord;
27 import net.sf.dexterim.oscar.entity.Word;
28
29
30 /***
31 * @author christoph
32 *
33 */
34 public class BufferArray extends OscarByteBuffer {
35
36 private List buffers;
37 private int position;
38
39 private BufferArray(List buffers) {
40 this.buffers = buffers;
41 this.position = 0;
42 }
43
44
45
46
47 public int position(int position) {
48 int current = 0;
49 int oldPosition = this.position;
50
51 for (Iterator iter = buffers.iterator(); iter.hasNext();) {
52 OscarByteBuffer element = (OscarByteBuffer) iter.next();
53
54 if (position < current) {
55 current += element.fill();
56 }
57 else {
58 this.position = position;
59 }
60 }
61
62 return oldPosition;
63 }
64
65
66
67
68 public int position() {
69 return position;
70 }
71
72
73
74
75 public int size() {
76 int size = 0;
77
78 for (Iterator iter = buffers.iterator(); iter.hasNext();) {
79 OscarByteBuffer element = (OscarByteBuffer) iter.next();
80
81 size += element.size();
82 }
83
84 return size;
85 }
86
87
88
89
90 public int fill() {
91 int fill = 0;
92
93 for (Iterator iter = buffers.iterator(); iter.hasNext();) {
94 OscarByteBuffer element = (OscarByteBuffer) iter.next();
95
96 fill += element.fill();
97 }
98
99 return fill;
100 }
101
102
103
104
105 public int strip() {
106 throw new UnsupportedOperationException("Method not implemented");
107 }
108
109
110
111
112 public Word getWord() {
113 throw new UnsupportedOperationException("Method not implemented");
114 }
115
116
117
118
119 public DWord getDWord() {
120 throw new UnsupportedOperationException("Method not implemented");
121 }
122
123
124
125
126 public int getByte() {
127 throw new UnsupportedOperationException("Method not implemented");
128 }
129
130
131
132
133 public OscarByteBuffer write(ByteBased source) {
134 throw new UnsupportedOperationException("Method not implemented");
135 }
136
137
138
139
140 public OscarByteBuffer write(byte source) {
141 throw new UnsupportedOperationException("Method not implemented");
142 }
143
144
145
146
147 public OscarByteBuffer write(OscarByteBuffer source) {
148 throw new UnsupportedOperationException("Method not implemented");
149 }
150
151
152
153
154 public byte[] array() {
155
156 return null;
157 }
158
159
160
161
162 public byte[] slice() {
163 byte[] slice = new byte[fill()];
164 int index = 0;
165
166 for (Iterator iter = buffers.iterator(); iter.hasNext();) {
167 OscarByteBuffer buffer = (OscarByteBuffer) iter.next();
168
169 byte[] bufferSlice = buffer.slice();
170
171 System.arraycopy(bufferSlice, 0, slice, index, bufferSlice.length);
172 index += bufferSlice.length;
173 }
174
175 return slice;
176 }
177
178 public static OscarByteBuffer createBufferArray(OscarByteBuffer first, OscarByteBuffer second) {
179 List buffers = new ArrayList(2);
180 buffers.add(first);
181 buffers.add(second);
182
183 return new BufferArray(buffers);
184 }
185
186 public static OscarByteBuffer createBufferArray(List buffers) {
187 return new BufferArray(buffers);
188 }
189 }