blob: 48362da5a5aade82c32d2899aeab8bc65fd2ef64 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.projectfloodlight.openflow.util;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.io.OutputStream;
6import java.nio.ByteBuffer;
7import java.nio.ByteOrder;
8import java.nio.channels.GatheringByteChannel;
9import java.nio.channels.ScatteringByteChannel;
10import java.nio.charset.Charset;
11
12import org.jboss.netty.buffer.ChannelBuffer;
13import org.jboss.netty.buffer.ChannelBufferFactory;
14import org.jboss.netty.buffer.ChannelBufferIndexFinder;
15
16public class LengthCountingPseudoChannelBuffer implements ChannelBuffer {
17
18 int writerIndex = 0;
19 private int markedWriterIndex;
20
21 @Override
22 public ChannelBufferFactory factory() {
23 return null;
24 }
25
26 @Override
27 public int capacity() {
28 return Integer.MAX_VALUE;
29 }
30
31 @Override
32 public ByteOrder order() {
33 return ByteOrder.BIG_ENDIAN;
34 }
35
36 @Override
37 public boolean isDirect() {
38 return true;
39 }
40
41 @Override
42 public int readerIndex() {
43 return 0;
44 }
45
46 @Override
47 public void readerIndex(int readerIndex) {
48 throw new UnsupportedOperationException();
49 }
50
51 @Override
52 public int writerIndex() {
53 return writerIndex;
54 }
55
56 @Override
57 public void writerIndex(int writerIndex) {
58 this.writerIndex = writerIndex;
59 }
60
61 @Override
62 public void setIndex(int readerIndex, int writerIndex) {
63 if(readerIndex != 0)
64 throw new UnsupportedOperationException();
65 this.writerIndex = writerIndex;
66 }
67
68 @Override
69 public int readableBytes() {
70 return writerIndex;
71 }
72
73 @Override
74 public int writableBytes() {
75 return Integer.MAX_VALUE - writerIndex;
76 }
77
78 @Override
79 public boolean readable() {
80 return writerIndex > 0;
81 }
82
83 @Override
84 public boolean writable() {
85 return writerIndex < Integer.MAX_VALUE;
86 }
87
88 @Override
89 public void clear() {
90 writerIndex = 0;
91
92 }
93
94 @Override
95 public void markReaderIndex() {
96 }
97
98 @Override
99 public void resetReaderIndex() {
100 }
101
102 @Override
103 public void markWriterIndex() {
104 markedWriterIndex = writerIndex;
105 }
106
107 @Override
108 public void resetWriterIndex() {
109 writerIndex = markedWriterIndex;
110 }
111
112 @Override
113 public void discardReadBytes() {
114 throw new UnsupportedOperationException();
115 }
116
117 @Override
118 public void ensureWritableBytes(int writableBytes) {
119 if(!((Integer.MAX_VALUE - writableBytes) > writerIndex))
120 throw new IllegalStateException();
121 }
122
123 @Override
124 public byte getByte(int index) {
125 throw new UnsupportedOperationException();
126 }
127
128 @Override
129 public short getUnsignedByte(int index) {
130 throw new UnsupportedOperationException();
131 }
132
133 @Override
134 public short getShort(int index) {
135 throw new UnsupportedOperationException();
136 }
137
138 @Override
139 public int getUnsignedShort(int index) {
140 throw new UnsupportedOperationException();
141 }
142
143 @Override
144 public int getMedium(int index) {
145 throw new UnsupportedOperationException();
146 }
147
148 @Override
149 public int getUnsignedMedium(int index) {
150 throw new UnsupportedOperationException();
151 }
152
153 @Override
154 public int getInt(int index) {
155 throw new UnsupportedOperationException();
156 }
157
158 @Override
159 public long getUnsignedInt(int index) {
160 throw new UnsupportedOperationException();
161 }
162
163 @Override
164 public long getLong(int index) {
165 throw new UnsupportedOperationException();
166 }
167
168 @Override
169 public char getChar(int index) {
170 throw new UnsupportedOperationException();
171 }
172
173 @Override
174 public float getFloat(int index) {
175 throw new UnsupportedOperationException();
176 }
177
178 @Override
179 public double getDouble(int index) {
180 throw new UnsupportedOperationException();
181 }
182
183 @Override
184 public void getBytes(int index, ChannelBuffer dst) {
185 throw new UnsupportedOperationException();
186 }
187
188 @Override
189 public void getBytes(int index, ChannelBuffer dst, int length) {
190 throw new UnsupportedOperationException();
191 }
192
193 @Override
194 public void getBytes(int index, ChannelBuffer dst, int dstIndex, int length) {
195 throw new UnsupportedOperationException();
196 }
197
198 @Override
199 public void getBytes(int index, byte[] dst) {
200 throw new UnsupportedOperationException();
201 }
202
203 @Override
204 public void getBytes(int index, byte[] dst, int dstIndex, int length) {
205 throw new UnsupportedOperationException();
206 }
207
208 @Override
209 public void getBytes(int index, ByteBuffer dst) {
210 throw new UnsupportedOperationException();
211 }
212
213 @Override
214 public void getBytes(int index, OutputStream out, int length)
215 throws IOException {
216 throw new UnsupportedOperationException();
217 }
218
219 @Override
220 public int getBytes(int index, GatheringByteChannel out, int length)
221 throws IOException {
222 throw new UnsupportedOperationException();
223 }
224
225 @Override
226 public void setByte(int index, int value) {
227 }
228
229 @Override
230 public void setShort(int index, int value) {
231 }
232
233 @Override
234 public void setMedium(int index, int value) {
235 }
236
237 @Override
238 public void setInt(int index, int value) {
239 }
240
241 @Override
242 public void setLong(int index, long value) {
243 }
244
245 @Override
246 public void setChar(int index, int value) {
247 }
248
249 @Override
250 public void setFloat(int index, float value) {
251 }
252
253 @Override
254 public void setDouble(int index, double value) {
255 }
256
257 @Override
258 public void setBytes(int index, ChannelBuffer src) {
259 }
260
261 @Override
262 public void setBytes(int index, ChannelBuffer src, int length) {
263 }
264
265 @Override
266 public void setBytes(int index, ChannelBuffer src, int srcIndex, int length) {
267 }
268
269 @Override
270 public void setBytes(int index, byte[] src) {
271 }
272
273 @Override
274 public void setBytes(int index, byte[] src, int srcIndex, int length) {
275 }
276
277 @Override
278 public void setBytes(int index, ByteBuffer src) {
279
280 }
281
282 @Override
283 public int setBytes(int index, InputStream in, int length)
284 throws IOException {
285 throw new UnsupportedOperationException();
286 }
287
288 @Override
289 public int setBytes(int index, ScatteringByteChannel in, int length)
290 throws IOException {
291 throw new UnsupportedOperationException();
292 }
293
294 @Override
295 public void setZero(int index, int length) {
296 }
297
298 @Override
299 public byte readByte() {
300 throw new UnsupportedOperationException();
301 }
302
303 @Override
304 public short readUnsignedByte() {
305 throw new UnsupportedOperationException();
306 }
307
308 @Override
309 public short readShort() {
310 throw new UnsupportedOperationException();
311 }
312
313 @Override
314 public int readUnsignedShort() {
315 throw new UnsupportedOperationException();
316 }
317
318 @Override
319 public int readMedium() {
320 throw new UnsupportedOperationException();
321 }
322
323 @Override
324 public int readUnsignedMedium() {
325 throw new UnsupportedOperationException();
326 }
327
328 @Override
329 public int readInt() {
330 throw new UnsupportedOperationException();
331 }
332
333 @Override
334 public long readUnsignedInt() {
335 throw new UnsupportedOperationException();
336 }
337
338 @Override
339 public long readLong() {
340 throw new UnsupportedOperationException();
341 }
342
343 @Override
344 public char readChar() {
345 throw new UnsupportedOperationException();
346 }
347
348 @Override
349 public float readFloat() {
350 throw new UnsupportedOperationException();
351 }
352
353 @Override
354 public double readDouble() {
355 throw new UnsupportedOperationException();
356 }
357
358 @Override
359 public ChannelBuffer readBytes(int length) {
360 throw new UnsupportedOperationException();
361 }
362
363 @Override
364 @Deprecated
365 public ChannelBuffer readBytes(ChannelBufferIndexFinder indexFinder) {
366 throw new UnsupportedOperationException();
367 }
368
369 @Override
370 public ChannelBuffer readSlice(int length) {
371 throw new UnsupportedOperationException();
372 }
373
374 @Override
375 @Deprecated
376 public
377 ChannelBuffer readSlice(ChannelBufferIndexFinder indexFinder) {
378 throw new UnsupportedOperationException();
379 }
380
381 @Override
382 public void readBytes(ChannelBuffer dst) {
383 throw new UnsupportedOperationException();
384 }
385
386 @Override
387 public void readBytes(ChannelBuffer dst, int length) {
388 throw new UnsupportedOperationException();
389 }
390
391 @Override
392 public void readBytes(ChannelBuffer dst, int dstIndex, int length) {
393 throw new UnsupportedOperationException();
394 }
395
396 @Override
397 public void readBytes(byte[] dst) {
398 throw new UnsupportedOperationException();
399 }
400
401 @Override
402 public void readBytes(byte[] dst, int dstIndex, int length) {
403 throw new UnsupportedOperationException();
404 }
405
406 @Override
407 public void readBytes(ByteBuffer dst) {
408 throw new UnsupportedOperationException();
409 }
410
411 @Override
412 public void readBytes(OutputStream out, int length) throws IOException {
413 throw new UnsupportedOperationException();
414 }
415
416 @Override
417 public int readBytes(GatheringByteChannel out, int length)
418 throws IOException {
419 throw new UnsupportedOperationException();
420 }
421
422 @Override
423 public void skipBytes(int length) {
424 throw new UnsupportedOperationException();
425 }
426
427 @Override
428 @Deprecated
429 public int skipBytes(ChannelBufferIndexFinder indexFinder) {
430 throw new UnsupportedOperationException();
431 }
432
433 @Override
434 public void writeByte(int value) {
435 writerIndex++;
436 }
437
438 @Override
439 public void writeShort(int value) {
440 writerIndex += 2;
441}
442
443@Override
444public void writeMedium(int value) {
445 writerIndex += 3;
446}
447
448@Override
449public void writeInt(int value) {
450 writerIndex += 4;
451}
452
453@Override
454public void writeLong(long value) {
455 writerIndex += 8;
456}
457
458
459 @Override
460 public void writeChar(int value) {
461 writeShort(value);
462 }
463
464 @Override
465 public void writeFloat(float value) {
466 writeInt(Float.floatToIntBits(value));
467 }
468
469 @Override
470 public void writeDouble(double value) {
471 writeLong(Double.doubleToLongBits(value));
472
473 }
474
475 @Override
476 public void writeBytes(ChannelBuffer src) {
477 writerIndex += src.readableBytes();
478
479 }
480
481 @Override
482 public void writeBytes(ChannelBuffer src, int length) {
483 writerIndex += src.readableBytes();
484
485 }
486
487 @Override
488 public void writeBytes(ChannelBuffer src, int srcIndex, int length) {
489 writerIndex += length;
490 }
491
492 @Override
493 public void writeBytes(byte[] src) {
494 writerIndex += src.length;
495
496 }
497
498 @Override
499 public void writeBytes(byte[] src, int srcIndex, int length) {
500 writerIndex += length;
501 }
502
503 @Override
504 public void writeBytes(ByteBuffer src) {
505 writerIndex += src.remaining();
506
507 }
508
509 @Override
510 public int writeBytes(InputStream in, int length) throws IOException {
511 writerIndex += length;
512 return length;
513 }
514
515 @Override
516 public int writeBytes(ScatteringByteChannel in, int length)
517 throws IOException {
518 writerIndex += length;
519 return length;
520 }
521
522 @Override
523 public void writeZero(int length) {
524 writerIndex += length;
525
526 }
527
528 @Override
529 public int indexOf(int fromIndex, int toIndex, byte value) {
530 throw new UnsupportedOperationException();
531 }
532
533 @Override
534 public int indexOf(int fromIndex, int toIndex,
535 ChannelBufferIndexFinder indexFinder) {
536 throw new UnsupportedOperationException();
537 }
538
539 @Override
540 public int bytesBefore(byte value) {
541 throw new UnsupportedOperationException();
542 }
543
544 @Override
545 public int bytesBefore(ChannelBufferIndexFinder indexFinder) {
546 throw new UnsupportedOperationException();
547 }
548
549 @Override
550 public int bytesBefore(int length, byte value) {
551 throw new UnsupportedOperationException();
552 }
553
554 @Override
555 public int bytesBefore(int length, ChannelBufferIndexFinder indexFinder) {
556 throw new UnsupportedOperationException();
557 }
558
559 @Override
560 public int bytesBefore(int index, int length, byte value) {
561 throw new UnsupportedOperationException();
562 }
563
564 @Override
565 public int bytesBefore(int index, int length,
566 ChannelBufferIndexFinder indexFinder) {
567 throw new UnsupportedOperationException();
568 }
569
570 @Override
571 public ChannelBuffer copy() {
572 throw new UnsupportedOperationException();
573 }
574
575 @Override
576 public ChannelBuffer copy(int index, int length) {
577 throw new UnsupportedOperationException();
578 }
579
580 @Override
581 public ChannelBuffer slice() {
582 throw new UnsupportedOperationException();
583 }
584
585 @Override
586 public ChannelBuffer slice(int index, int length) {
587 throw new UnsupportedOperationException();
588 }
589
590 @Override
591 public ChannelBuffer duplicate() {
592 throw new UnsupportedOperationException();
593 }
594
595 @Override
596 public ByteBuffer toByteBuffer() {
597 throw new UnsupportedOperationException();
598 }
599
600 @Override
601 public ByteBuffer toByteBuffer(int index, int length) {
602 throw new UnsupportedOperationException();
603 }
604
605 @Override
606 public ByteBuffer[] toByteBuffers() {
607 throw new UnsupportedOperationException();
608 }
609
610 @Override
611 public ByteBuffer[] toByteBuffers(int index, int length) {
612 throw new UnsupportedOperationException();
613 }
614
615 @Override
616 public boolean hasArray() {
617 throw new UnsupportedOperationException();
618 }
619
620 @Override
621 public byte[] array() {
622 throw new UnsupportedOperationException();
623 }
624
625 @Override
626 public int arrayOffset() {
627 throw new UnsupportedOperationException();
628 }
629
630 @Override
631 public String toString(Charset charset) {
632 return "LengthCountingPseudoChannelBuffer(length="+writerIndex+")";
633 }
634
635 @Override
636 public String toString(int index, int length, Charset charset) {
637 return toString();
638 }
639
640 @Override
641 @Deprecated
642 public String toString(String charsetName) {
643 return toString();
644 }
645
646 @Override
647 @Deprecated
648 public String toString(String charsetName,
649 ChannelBufferIndexFinder terminatorFinder) {
650 return toString();
651 }
652
653 @Override
654 @Deprecated
655 public String toString(int index, int length, String charsetName) {
656 return toString();
657 }
658
659 @Override
660 @Deprecated
661 public
662 String toString(int index, int length, String charsetName,
663 ChannelBufferIndexFinder terminatorFinder) {
664 return toString();
665 }
666
667 @Override
668 public int compareTo(ChannelBuffer buffer) {
669 throw new UnsupportedOperationException();
670
671 }
672
673}