001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *
019: */
020: package org.apache.mina.common;
021:
022: import java.io.FilterOutputStream;
023: import java.io.InputStream;
024: import java.io.OutputStream;
025: import java.nio.ByteBuffer;
026: import java.nio.ByteOrder;
027: import java.nio.CharBuffer;
028: import java.nio.DoubleBuffer;
029: import java.nio.FloatBuffer;
030: import java.nio.IntBuffer;
031: import java.nio.LongBuffer;
032: import java.nio.ShortBuffer;
033: import java.nio.charset.CharacterCodingException;
034: import java.nio.charset.CharsetDecoder;
035: import java.nio.charset.CharsetEncoder;
036: import java.util.EnumSet;
037: import java.util.Set;
038:
039: /**
040: * A {@link IoBuffer} that wraps a buffer and proxies any operations to it.
041: * <p>
042: * You can think this class like a {@link FilterOutputStream}. All operations
043: * are proxied by default so that you can extend this class and override existing
044: * operations selectively. You can introduce new operations, too.
045: *
046: * @author The Apache MINA Project (dev@mina.apache.org)
047: * @version $Rev: 602109 $, $Date: 2007-12-07 07:40:41 -0700 (Fri, 07 Dec 2007) $
048: */
049: public class IoBufferWrapper extends IoBuffer {
050:
051: /**
052: * The buffer proxied by this proxy.
053: */
054: private final IoBuffer buf;
055:
056: /**
057: * Create a new instance.
058: * @param buf the buffer to be proxied
059: */
060: protected IoBufferWrapper(IoBuffer buf) {
061: if (buf == null) {
062: throw new NullPointerException("buf");
063: }
064: this .buf = buf;
065: }
066:
067: /**
068: * Returns the parent buffer that this buffer wrapped.
069: */
070: public IoBuffer getParentBuffer() {
071: return buf;
072: }
073:
074: @Override
075: public boolean isDirect() {
076: return buf.isDirect();
077: }
078:
079: @Override
080: public ByteBuffer buf() {
081: return buf.buf();
082: }
083:
084: @Override
085: public int capacity() {
086: return buf.capacity();
087: }
088:
089: @Override
090: public int position() {
091: return buf.position();
092: }
093:
094: @Override
095: public IoBuffer position(int newPosition) {
096: buf.position(newPosition);
097: return this ;
098: }
099:
100: @Override
101: public int limit() {
102: return buf.limit();
103: }
104:
105: @Override
106: public IoBuffer limit(int newLimit) {
107: buf.limit(newLimit);
108: return this ;
109: }
110:
111: @Override
112: public IoBuffer mark() {
113: buf.mark();
114: return this ;
115: }
116:
117: @Override
118: public IoBuffer reset() {
119: buf.reset();
120: return this ;
121: }
122:
123: @Override
124: public IoBuffer clear() {
125: buf.clear();
126: return this ;
127: }
128:
129: @Override
130: public IoBuffer sweep() {
131: buf.sweep();
132: return this ;
133: }
134:
135: @Override
136: public IoBuffer sweep(byte value) {
137: buf.sweep(value);
138: return this ;
139: }
140:
141: @Override
142: public IoBuffer flip() {
143: buf.flip();
144: return this ;
145: }
146:
147: @Override
148: public IoBuffer rewind() {
149: buf.rewind();
150: return this ;
151: }
152:
153: @Override
154: public int remaining() {
155: return buf.remaining();
156: }
157:
158: @Override
159: public boolean hasRemaining() {
160: return buf.hasRemaining();
161: }
162:
163: @Override
164: public byte get() {
165: return buf.get();
166: }
167:
168: @Override
169: public short getUnsigned() {
170: return buf.getUnsigned();
171: }
172:
173: @Override
174: public IoBuffer put(byte b) {
175: buf.put(b);
176: return this ;
177: }
178:
179: @Override
180: public byte get(int index) {
181: return buf.get(index);
182: }
183:
184: @Override
185: public short getUnsigned(int index) {
186: return buf.getUnsigned(index);
187: }
188:
189: @Override
190: public IoBuffer put(int index, byte b) {
191: buf.put(index, b);
192: return this ;
193: }
194:
195: @Override
196: public IoBuffer get(byte[] dst, int offset, int length) {
197: buf.get(dst, offset, length);
198: return this ;
199: }
200:
201: @Override
202: public IoBuffer getSlice(int index, int length) {
203: return buf.getSlice(index, length);
204: }
205:
206: @Override
207: public IoBuffer getSlice(int length) {
208: return buf.getSlice(length);
209: }
210:
211: @Override
212: public IoBuffer get(byte[] dst) {
213: buf.get(dst);
214: return this ;
215: }
216:
217: @Override
218: public IoBuffer put(IoBuffer src) {
219: buf.put(src);
220: return this ;
221: }
222:
223: @Override
224: public IoBuffer put(ByteBuffer src) {
225: buf.put(src);
226: return this ;
227: }
228:
229: @Override
230: public IoBuffer put(byte[] src, int offset, int length) {
231: buf.put(src, offset, length);
232: return this ;
233: }
234:
235: @Override
236: public IoBuffer put(byte[] src) {
237: buf.put(src);
238: return this ;
239: }
240:
241: @Override
242: public IoBuffer compact() {
243: buf.compact();
244: return this ;
245: }
246:
247: @Override
248: public String toString() {
249: return buf.toString();
250: }
251:
252: @Override
253: public int hashCode() {
254: return buf.hashCode();
255: }
256:
257: @Override
258: public boolean equals(Object ob) {
259: return buf.equals(ob);
260: }
261:
262: public int compareTo(IoBuffer that) {
263: return buf.compareTo(that);
264: }
265:
266: @Override
267: public ByteOrder order() {
268: return buf.order();
269: }
270:
271: @Override
272: public IoBuffer order(ByteOrder bo) {
273: buf.order(bo);
274: return this ;
275: }
276:
277: @Override
278: public char getChar() {
279: return buf.getChar();
280: }
281:
282: @Override
283: public IoBuffer putChar(char value) {
284: buf.putChar(value);
285: return this ;
286: }
287:
288: @Override
289: public char getChar(int index) {
290: return buf.getChar(index);
291: }
292:
293: @Override
294: public IoBuffer putChar(int index, char value) {
295: buf.putChar(index, value);
296: return this ;
297: }
298:
299: @Override
300: public CharBuffer asCharBuffer() {
301: return buf.asCharBuffer();
302: }
303:
304: @Override
305: public short getShort() {
306: return buf.getShort();
307: }
308:
309: @Override
310: public int getUnsignedShort() {
311: return buf.getUnsignedShort();
312: }
313:
314: @Override
315: public IoBuffer putShort(short value) {
316: buf.putShort(value);
317: return this ;
318: }
319:
320: @Override
321: public short getShort(int index) {
322: return buf.getShort(index);
323: }
324:
325: @Override
326: public int getUnsignedShort(int index) {
327: return buf.getUnsignedShort(index);
328: }
329:
330: @Override
331: public IoBuffer putShort(int index, short value) {
332: buf.putShort(index, value);
333: return this ;
334: }
335:
336: @Override
337: public ShortBuffer asShortBuffer() {
338: return buf.asShortBuffer();
339: }
340:
341: @Override
342: public int getInt() {
343: return buf.getInt();
344: }
345:
346: @Override
347: public long getUnsignedInt() {
348: return buf.getUnsignedInt();
349: }
350:
351: @Override
352: public IoBuffer putInt(int value) {
353: buf.putInt(value);
354: return this ;
355: }
356:
357: @Override
358: public int getInt(int index) {
359: return buf.getInt(index);
360: }
361:
362: @Override
363: public long getUnsignedInt(int index) {
364: return buf.getUnsignedInt(index);
365: }
366:
367: @Override
368: public IoBuffer putInt(int index, int value) {
369: buf.putInt(index, value);
370: return this ;
371: }
372:
373: @Override
374: public IntBuffer asIntBuffer() {
375: return buf.asIntBuffer();
376: }
377:
378: @Override
379: public long getLong() {
380: return buf.getLong();
381: }
382:
383: @Override
384: public IoBuffer putLong(long value) {
385: buf.putLong(value);
386: return this ;
387: }
388:
389: @Override
390: public long getLong(int index) {
391: return buf.getLong(index);
392: }
393:
394: @Override
395: public IoBuffer putLong(int index, long value) {
396: buf.putLong(index, value);
397: return this ;
398: }
399:
400: @Override
401: public LongBuffer asLongBuffer() {
402: return buf.asLongBuffer();
403: }
404:
405: @Override
406: public float getFloat() {
407: return buf.getFloat();
408: }
409:
410: @Override
411: public IoBuffer putFloat(float value) {
412: buf.putFloat(value);
413: return this ;
414: }
415:
416: @Override
417: public float getFloat(int index) {
418: return buf.getFloat(index);
419: }
420:
421: @Override
422: public IoBuffer putFloat(int index, float value) {
423: buf.putFloat(index, value);
424: return this ;
425: }
426:
427: @Override
428: public FloatBuffer asFloatBuffer() {
429: return buf.asFloatBuffer();
430: }
431:
432: @Override
433: public double getDouble() {
434: return buf.getDouble();
435: }
436:
437: @Override
438: public IoBuffer putDouble(double value) {
439: buf.putDouble(value);
440: return this ;
441: }
442:
443: @Override
444: public double getDouble(int index) {
445: return buf.getDouble(index);
446: }
447:
448: @Override
449: public IoBuffer putDouble(int index, double value) {
450: buf.putDouble(index, value);
451: return this ;
452: }
453:
454: @Override
455: public DoubleBuffer asDoubleBuffer() {
456: return buf.asDoubleBuffer();
457: }
458:
459: @Override
460: public String getHexDump() {
461: return buf.getHexDump();
462: }
463:
464: @Override
465: public String getString(int fieldSize, CharsetDecoder decoder)
466: throws CharacterCodingException {
467: return buf.getString(fieldSize, decoder);
468: }
469:
470: @Override
471: public String getString(CharsetDecoder decoder)
472: throws CharacterCodingException {
473: return buf.getString(decoder);
474: }
475:
476: @Override
477: public String getPrefixedString(CharsetDecoder decoder)
478: throws CharacterCodingException {
479: return buf.getPrefixedString(decoder);
480: }
481:
482: @Override
483: public String getPrefixedString(int prefixLength,
484: CharsetDecoder decoder) throws CharacterCodingException {
485: return buf.getPrefixedString(prefixLength, decoder);
486: }
487:
488: @Override
489: public IoBuffer putString(CharSequence in, int fieldSize,
490: CharsetEncoder encoder) throws CharacterCodingException {
491: buf.putString(in, fieldSize, encoder);
492: return this ;
493: }
494:
495: @Override
496: public IoBuffer putString(CharSequence in, CharsetEncoder encoder)
497: throws CharacterCodingException {
498: buf.putString(in, encoder);
499: return this ;
500: }
501:
502: @Override
503: public IoBuffer putPrefixedString(CharSequence in,
504: CharsetEncoder encoder) throws CharacterCodingException {
505: buf.putPrefixedString(in, encoder);
506: return this ;
507: }
508:
509: @Override
510: public IoBuffer putPrefixedString(CharSequence in,
511: int prefixLength, CharsetEncoder encoder)
512: throws CharacterCodingException {
513: buf.putPrefixedString(in, prefixLength, encoder);
514: return this ;
515: }
516:
517: @Override
518: public IoBuffer putPrefixedString(CharSequence in,
519: int prefixLength, int padding, CharsetEncoder encoder)
520: throws CharacterCodingException {
521: buf.putPrefixedString(in, prefixLength, padding, encoder);
522: return this ;
523: }
524:
525: @Override
526: public IoBuffer putPrefixedString(CharSequence in,
527: int prefixLength, int padding, byte padValue,
528: CharsetEncoder encoder) throws CharacterCodingException {
529: buf.putPrefixedString(in, prefixLength, padding, padValue,
530: encoder);
531: return this ;
532: }
533:
534: @Override
535: public IoBuffer skip(int size) {
536: buf.skip(size);
537: return this ;
538: }
539:
540: @Override
541: public IoBuffer fill(byte value, int size) {
542: buf.fill(value, size);
543: return this ;
544: }
545:
546: @Override
547: public IoBuffer fillAndReset(byte value, int size) {
548: buf.fillAndReset(value, size);
549: return this ;
550: }
551:
552: @Override
553: public IoBuffer fill(int size) {
554: buf.fill(size);
555: return this ;
556: }
557:
558: @Override
559: public IoBuffer fillAndReset(int size) {
560: buf.fillAndReset(size);
561: return this ;
562: }
563:
564: @Override
565: public boolean isAutoExpand() {
566: return buf.isAutoExpand();
567: }
568:
569: @Override
570: public IoBuffer setAutoExpand(boolean autoExpand) {
571: buf.setAutoExpand(autoExpand);
572: return this ;
573: }
574:
575: @Override
576: public IoBuffer expand(int pos, int expectedRemaining) {
577: buf.expand(pos, expectedRemaining);
578: return this ;
579: }
580:
581: @Override
582: public IoBuffer expand(int expectedRemaining) {
583: buf.expand(expectedRemaining);
584: return this ;
585: }
586:
587: @Override
588: public Object getObject() throws ClassNotFoundException {
589: return buf.getObject();
590: }
591:
592: @Override
593: public Object getObject(ClassLoader classLoader)
594: throws ClassNotFoundException {
595: return buf.getObject(classLoader);
596: }
597:
598: @Override
599: public IoBuffer putObject(Object o) {
600: buf.putObject(o);
601: return this ;
602: }
603:
604: @Override
605: public InputStream asInputStream() {
606: return buf.asInputStream();
607: }
608:
609: @Override
610: public OutputStream asOutputStream() {
611: return buf.asOutputStream();
612: }
613:
614: @Override
615: public IoBuffer duplicate() {
616: return buf.duplicate();
617: }
618:
619: @Override
620: public IoBuffer slice() {
621: return buf.slice();
622: }
623:
624: @Override
625: public IoBuffer asReadOnlyBuffer() {
626: return buf.asReadOnlyBuffer();
627: }
628:
629: @Override
630: public byte[] array() {
631: return buf.array();
632: }
633:
634: @Override
635: public int arrayOffset() {
636: return buf.arrayOffset();
637: }
638:
639: @Override
640: public int minimumCapacity() {
641: return buf.minimumCapacity();
642: }
643:
644: @Override
645: public IoBuffer minimumCapacity(int minimumCapacity) {
646: buf.minimumCapacity(minimumCapacity);
647: return this ;
648: }
649:
650: @Override
651: public IoBuffer capacity(int newCapacity) {
652: buf.capacity(newCapacity);
653: return this ;
654: }
655:
656: @Override
657: public boolean isReadOnly() {
658: return buf.isReadOnly();
659: }
660:
661: @Override
662: public int markValue() {
663: return buf.markValue();
664: }
665:
666: @Override
667: public boolean hasArray() {
668: return buf.hasArray();
669: }
670:
671: @Override
672: public void free() {
673: buf.free();
674: }
675:
676: @Override
677: public boolean isDerived() {
678: return buf.isDerived();
679: }
680:
681: @Override
682: public boolean isAutoShrink() {
683: return buf.isAutoShrink();
684: }
685:
686: @Override
687: public IoBuffer setAutoShrink(boolean autoShrink) {
688: buf.setAutoShrink(autoShrink);
689: return this ;
690: }
691:
692: @Override
693: public IoBuffer shrink() {
694: buf.shrink();
695: return this ;
696: }
697:
698: @Override
699: public int getMediumInt() {
700: return buf.getMediumInt();
701: }
702:
703: @Override
704: public int getUnsignedMediumInt() {
705: return buf.getUnsignedMediumInt();
706: }
707:
708: @Override
709: public int getMediumInt(int index) {
710: return buf.getMediumInt(index);
711: }
712:
713: @Override
714: public int getUnsignedMediumInt(int index) {
715: return buf.getUnsignedMediumInt(index);
716: }
717:
718: @Override
719: public IoBuffer putMediumInt(int value) {
720: buf.putMediumInt(value);
721: return this ;
722: }
723:
724: @Override
725: public IoBuffer putMediumInt(int index, int value) {
726: buf.putMediumInt(index, value);
727: return this ;
728: }
729:
730: @Override
731: public String getHexDump(int lengthLimit) {
732: return buf.getHexDump(lengthLimit);
733: }
734:
735: @Override
736: public boolean prefixedDataAvailable(int prefixLength) {
737: return buf.prefixedDataAvailable(prefixLength);
738: }
739:
740: @Override
741: public boolean prefixedDataAvailable(int prefixLength,
742: int maxDataLength) {
743: return buf.prefixedDataAvailable(prefixLength, maxDataLength);
744: }
745:
746: @Override
747: public int indexOf(byte b) {
748: return buf.indexOf(b);
749: }
750:
751: @Override
752: public <E extends Enum<E>> E getEnum(Class<E> enumClass) {
753: return buf.getEnum(enumClass);
754: }
755:
756: @Override
757: public <E extends Enum<E>> E getEnum(int index, Class<E> enumClass) {
758: return buf.getEnum(index, enumClass);
759: }
760:
761: @Override
762: public <E extends Enum<E>> E getEnumShort(Class<E> enumClass) {
763: return buf.getEnumShort(enumClass);
764: }
765:
766: @Override
767: public <E extends Enum<E>> E getEnumShort(int index,
768: Class<E> enumClass) {
769: return buf.getEnumShort(index, enumClass);
770: }
771:
772: @Override
773: public <E extends Enum<E>> E getEnumInt(Class<E> enumClass) {
774: return buf.getEnumInt(enumClass);
775: }
776:
777: @Override
778: public <E extends Enum<E>> E getEnumInt(int index,
779: Class<E> enumClass) {
780: return buf.getEnumInt(index, enumClass);
781: }
782:
783: @Override
784: public IoBuffer putEnum(Enum<?> e) {
785: buf.putEnum(e);
786: return this ;
787: }
788:
789: @Override
790: public IoBuffer putEnum(int index, Enum<?> e) {
791: buf.putEnum(index, e);
792: return this ;
793: }
794:
795: @Override
796: public IoBuffer putEnumShort(Enum<?> e) {
797: buf.putEnumShort(e);
798: return this ;
799: }
800:
801: @Override
802: public IoBuffer putEnumShort(int index, Enum<?> e) {
803: buf.putEnumShort(index, e);
804: return this ;
805: }
806:
807: @Override
808: public IoBuffer putEnumInt(Enum<?> e) {
809: buf.putEnumInt(e);
810: return this ;
811: }
812:
813: @Override
814: public IoBuffer putEnumInt(int index, Enum<?> e) {
815: buf.putEnumInt(index, e);
816: return this ;
817: }
818:
819: @Override
820: public <E extends Enum<E>> EnumSet<E> getEnumSet(Class<E> enumClass) {
821: return buf.getEnumSet(enumClass);
822: }
823:
824: @Override
825: public <E extends Enum<E>> EnumSet<E> getEnumSet(int index,
826: Class<E> enumClass) {
827: return buf.getEnumSet(index, enumClass);
828: }
829:
830: @Override
831: public <E extends Enum<E>> EnumSet<E> getEnumSetShort(
832: Class<E> enumClass) {
833: return buf.getEnumSetShort(enumClass);
834: }
835:
836: @Override
837: public <E extends Enum<E>> EnumSet<E> getEnumSetShort(int index,
838: Class<E> enumClass) {
839: return buf.getEnumSetShort(index, enumClass);
840: }
841:
842: @Override
843: public <E extends Enum<E>> EnumSet<E> getEnumSetInt(
844: Class<E> enumClass) {
845: return buf.getEnumSetInt(enumClass);
846: }
847:
848: @Override
849: public <E extends Enum<E>> EnumSet<E> getEnumSetInt(int index,
850: Class<E> enumClass) {
851: return buf.getEnumSetInt(index, enumClass);
852: }
853:
854: @Override
855: public <E extends Enum<E>> EnumSet<E> getEnumSetLong(
856: Class<E> enumClass) {
857: return buf.getEnumSetLong(enumClass);
858: }
859:
860: @Override
861: public <E extends Enum<E>> EnumSet<E> getEnumSetLong(int index,
862: Class<E> enumClass) {
863: return buf.getEnumSetLong(index, enumClass);
864: }
865:
866: @Override
867: public <E extends Enum<E>> IoBuffer putEnumSet(Set<E> set) {
868: buf.putEnumSet(set);
869: return this ;
870: }
871:
872: @Override
873: public <E extends Enum<E>> IoBuffer putEnumSet(int index, Set<E> set) {
874: buf.putEnumSet(index, set);
875: return this ;
876: }
877:
878: @Override
879: public <E extends Enum<E>> IoBuffer putEnumSetShort(Set<E> set) {
880: buf.putEnumSetShort(set);
881: return this ;
882: }
883:
884: @Override
885: public <E extends Enum<E>> IoBuffer putEnumSetShort(int index,
886: Set<E> set) {
887: buf.putEnumSetShort(index, set);
888: return this ;
889: }
890:
891: @Override
892: public <E extends Enum<E>> IoBuffer putEnumSetInt(Set<E> set) {
893: buf.putEnumSetInt(set);
894: return this ;
895: }
896:
897: @Override
898: public <E extends Enum<E>> IoBuffer putEnumSetInt(int index,
899: Set<E> set) {
900: buf.putEnumSetInt(index, set);
901: return this ;
902: }
903:
904: @Override
905: public <E extends Enum<E>> IoBuffer putEnumSetLong(Set<E> set) {
906: buf.putEnumSetLong(set);
907: return this ;
908: }
909:
910: @Override
911: public <E extends Enum<E>> IoBuffer putEnumSetLong(int index,
912: Set<E> set) {
913: buf.putEnumSetLong(index, set);
914: return this;
915: }
916: }
|