View Javadoc

1   /*
2    *   @(#) $Id: ByteBufferProxy.java 355016 2005-12-08 07:00:30Z trustin $
3    *
4    *   Copyright 2004 The Apache Software Foundation
5    *
6    *   Licensed under the Apache License, Version 2.0 (the "License");
7    *   you may not use this file except in compliance with the License.
8    *   You may obtain a copy of the License at
9    *
10   *       http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing, software
13   *   distributed under the License is distributed on an "AS IS" BASIS,
14   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   *   See the License for the specific language governing permissions and
16   *   limitations under the License.
17   *
18   */package org/apache/mina/common/package-summary.html">class="comment"> */package org.apache.mina.common;
19  
20  import java.io.FilterOutputStream;
21  import java.io.InputStream;
22  import java.io.OutputStream;
23  import java.nio.ByteOrder;
24  import java.nio.CharBuffer;
25  import java.nio.DoubleBuffer;
26  import java.nio.FloatBuffer;
27  import java.nio.IntBuffer;
28  import java.nio.LongBuffer;
29  import java.nio.ShortBuffer;
30  import java.nio.charset.CharacterCodingException;
31  import java.nio.charset.CharsetDecoder;
32  import java.nio.charset.CharsetEncoder;
33  
34  /***
35   * A {@link ByteBuffer} that wraps a buffer and proxies any operations to it.
36   * <p>
37   * You can think this class like a {@link FilterOutputStream}.  All operations
38   * are proxied by default so that you can extend this class and override existing
39   * operations selectively.  You can introduce new operations, too.
40   * 
41   * @author The Apache Directory Project (dev@directory.apache.org)
42   * @version $Rev: 355016 $, $Date: 2005-12-08 16:00:30 +0900 (Thu, 08 Dec 2005) $
43   */
44  public class ByteBufferProxy extends ByteBuffer
45  {
46  
47      /***
48       * The buffer proxied by this proxy.
49       */
50      protected ByteBuffer buf;
51  
52      /***
53       * Create a new instance.
54       * @param buf the buffer to be proxied
55       */
56      protected ByteBufferProxy( ByteBuffer buf )
57      {
58          if( buf == null )
59          {
60              throw new NullPointerException( "buf" );
61          }
62          this.buf = buf;
63      }
64  
65      public void acquire()
66      {
67          buf.acquire();
68      }
69  
70      public void release()
71      {
72          buf.release();
73      }
74  
75      public boolean isDirect()
76      {
77          return buf.isDirect();
78      }
79  
80      public java.nio.ByteBuffer buf()
81      {
82          return buf.buf();
83      }
84  
85      public int capacity()
86      {
87          return buf.capacity();
88      }
89  
90      public int position()
91      {
92          return buf.position();
93      }
94  
95      public ByteBuffer position( int newPosition )
96      {
97          buf.position( newPosition );
98          return this;
99      }
100 
101     public int limit()
102     {
103         return buf.limit();
104     }
105 
106     public ByteBuffer limit( int newLimit )
107     {
108         buf.limit( newLimit );
109         return this;
110     }
111 
112     public ByteBuffer mark()
113     {
114         buf.mark();
115         return this;
116     }
117 
118     public ByteBuffer reset()
119     {
120         buf.reset();
121         return this;
122     }
123 
124     public ByteBuffer clear()
125     {
126         buf.clear();
127         return this;
128     }
129 
130     public ByteBuffer sweep()
131     {
132         buf.sweep();
133         return this;
134     }
135     
136     public ByteBuffer sweep( byte value )
137     {
138         buf.sweep( value );
139         return this;
140     }
141 
142     public ByteBuffer flip()
143     {
144         buf.flip();
145         return this;
146     }
147 
148     public ByteBuffer rewind()
149     {
150         buf.rewind();
151         return this;
152     }
153 
154     public int remaining()
155     {
156         return buf.remaining();
157     }
158 
159     public boolean hasRemaining()
160     {
161         return buf.hasRemaining();
162     }
163 
164     public byte get()
165     {
166         return buf.get();
167     }
168 
169     public short getUnsigned()
170     {
171         return buf.getUnsigned();
172     }
173 
174     public ByteBuffer put( byte b )
175     {
176         buf.put( b );
177         return this;
178     }
179 
180     public byte get( int index )
181     {
182         return buf.get( index );
183     }
184 
185     public short getUnsigned( int index )
186     {
187         return buf.getUnsigned( index );
188     }
189 
190     public ByteBuffer put( int index, byte b )
191     {
192         buf.put( index, b );
193         return this;
194     }
195 
196     public ByteBuffer get( byte[] dst, int offset, int length )
197     {
198         buf.get( dst, offset, length );
199         return this;
200     }
201 
202     public ByteBuffer get( byte[] dst )
203     {
204         buf.get( dst );
205         return this;
206     }
207 
208     public ByteBuffer put( ByteBuffer src )
209     {
210         buf.put( src );
211         return this;
212     }
213 
214     public ByteBuffer put( java.nio.ByteBuffer src )
215     {
216         buf.put( src );
217         return this;
218     }
219 
220     public ByteBuffer put( byte[] src, int offset, int length )
221     {
222         buf.put( src, offset, length );
223         return this;
224     }
225 
226     public ByteBuffer put( byte[] src )
227     {
228         buf.put( src );
229         return this;
230     }
231 
232     public ByteBuffer compact()
233     {
234         buf.compact();
235         return this;
236     }
237 
238     public String toString()
239     {
240         return buf.toString();
241     }
242 
243     public int hashCode()
244     {
245         return buf.hashCode();
246     }
247 
248     public boolean equals( Object ob )
249     {
250         return buf.equals( ob );
251     }
252 
253     public int compareTo( Object o )
254     {
255         return buf.compareTo( o );
256     }
257 
258     public ByteOrder order()
259     {
260         return buf.order();
261     }
262 
263     public ByteBuffer order( ByteOrder bo )
264     {
265         buf.order( bo );
266         return this;
267     }
268 
269     public char getChar()
270     {
271         return buf.getChar();
272     }
273 
274     public ByteBuffer putChar( char value )
275     {
276         buf.putChar( value );
277         return this;
278     }
279 
280     public char getChar( int index )
281     {
282         return buf.getChar( index );
283     }
284 
285     public ByteBuffer putChar( int index, char value )
286     {
287         buf.putChar( index, value );
288         return this;
289     }
290 
291     public CharBuffer asCharBuffer()
292     {
293         return buf.asCharBuffer();
294     }
295 
296     public short getShort()
297     {
298         return buf.getShort();
299     }
300 
301     public int getUnsignedShort()
302     {
303         return buf.getUnsignedShort();
304     }
305 
306     public ByteBuffer putShort( short value )
307     {
308         buf.putShort( value );
309         return this;
310     }
311 
312     public short getShort( int index )
313     {
314         return buf.getShort( index );
315     }
316 
317     public int getUnsignedShort( int index )
318     {
319         return buf.getUnsignedShort( index );
320     }
321 
322     public ByteBuffer putShort( int index, short value )
323     {
324         buf.putShort( index, value );
325         return this;
326     }
327 
328     public ShortBuffer asShortBuffer()
329     {
330         return buf.asShortBuffer();
331     }
332 
333     public int getInt()
334     {
335         return buf.getInt();
336     }
337 
338     public long getUnsignedInt()
339     {
340         return buf.getUnsignedInt();
341     }
342 
343     public ByteBuffer putInt( int value )
344     {
345         buf.putInt( value );
346         return this;
347     }
348 
349     public int getInt( int index )
350     {
351         return buf.getInt( index );
352     }
353 
354     public long getUnsignedInt( int index )
355     {
356         return buf.getUnsignedInt( index );
357     }
358 
359     public ByteBuffer putInt( int index, int value )
360     {
361         buf.putInt( index, value );
362         return this;
363     }
364 
365     public IntBuffer asIntBuffer()
366     {
367         return buf.asIntBuffer();
368     }
369 
370     public long getLong()
371     {
372         return buf.getLong();
373     }
374 
375     public ByteBuffer putLong( long value )
376     {
377         buf.putLong( value );
378         return this;
379     }
380 
381     public long getLong( int index )
382     {
383         return buf.getLong( index );
384     }
385 
386     public ByteBuffer putLong( int index, long value )
387     {
388         buf.putLong( index, value );
389         return this;
390     }
391 
392     public LongBuffer asLongBuffer()
393     {
394         return buf.asLongBuffer();
395     }
396 
397     public float getFloat()
398     {
399         return buf.getFloat();
400     }
401 
402     public ByteBuffer putFloat( float value )
403     {
404         buf.putFloat( value );
405         return this;
406     }
407 
408     public float getFloat( int index )
409     {
410         return buf.getFloat( index );
411     }
412 
413     public ByteBuffer putFloat( int index, float value )
414     {
415         buf.putFloat( index, value );
416         return this;
417     }
418 
419     public FloatBuffer asFloatBuffer()
420     {
421         return buf.asFloatBuffer();
422     }
423 
424     public double getDouble()
425     {
426         return buf.getDouble();
427     }
428 
429     public ByteBuffer putDouble( double value )
430     {
431         buf.putDouble( value );
432         return this;
433     }
434 
435     public double getDouble( int index )
436     {
437         return buf.getDouble( index );
438     }
439 
440     public ByteBuffer putDouble( int index, double value )
441     {
442         buf.putDouble( index, value );
443         return this;
444     }
445 
446     public DoubleBuffer asDoubleBuffer()
447     {
448         return buf.asDoubleBuffer();
449     }
450 
451     public String getHexDump()
452     {
453         return buf.getHexDump();
454     }
455 
456     public String getString( int fieldSize, CharsetDecoder decoder )
457             throws CharacterCodingException
458     {
459         return buf.getString( fieldSize, decoder );
460     }
461 
462     public String getString( CharsetDecoder decoder )
463             throws CharacterCodingException
464     {
465         return buf.getString( decoder );
466     }
467     
468     public String getPrefixedString( CharsetDecoder decoder )
469             throws CharacterCodingException
470     {
471         return buf.getPrefixedString( decoder );
472     }
473 
474     public String getPrefixedString( int prefixLength, CharsetDecoder decoder )
475             throws CharacterCodingException
476     {
477         return buf.getPrefixedString( prefixLength, decoder );
478     }
479 
480     public ByteBuffer putString( CharSequence in, int fieldSize,
481                                 CharsetEncoder encoder )
482             throws CharacterCodingException
483     {
484         buf.putString( in, fieldSize, encoder );
485         return this;
486     }
487 
488     public ByteBuffer putString( CharSequence in, CharsetEncoder encoder )
489             throws CharacterCodingException
490     {
491         buf.putString( in, encoder );
492         return this;
493     }
494     
495     public ByteBuffer putPrefixedString( CharSequence in, CharsetEncoder encoder )
496             throws CharacterCodingException
497     {
498         buf.putPrefixedString( in, encoder );
499         return this;
500     }
501 
502     public ByteBuffer putPrefixedString( CharSequence in, int prefixLength, CharsetEncoder encoder ) throws CharacterCodingException
503     {
504         buf.putPrefixedString( in, prefixLength, encoder );
505         return this;
506     }
507 
508     public ByteBuffer putPrefixedString( CharSequence in, int prefixLength, int padding, CharsetEncoder encoder )
509             throws CharacterCodingException
510     {
511         buf.putPrefixedString( in, prefixLength, padding, encoder );
512         return this;
513     }
514 
515     public ByteBuffer putPrefixedString( CharSequence in, int prefixLength, int padding, byte padValue, CharsetEncoder encoder )
516             throws CharacterCodingException
517     {
518         buf.putPrefixedString( in, prefixLength, padding, padValue, encoder );
519         return this;
520     }
521 
522     public ByteBuffer skip( int size )
523     {
524         buf.skip( size );
525         return this;
526     }
527 
528     public ByteBuffer fill( byte value, int size )
529     {
530         buf.fill( value, size );
531         return this;
532     }
533 
534     public ByteBuffer fillAndReset( byte value, int size )
535     {
536         buf.fillAndReset( value, size );
537         return this;
538     }
539 
540     public ByteBuffer fill( int size )
541     {
542         buf.fill( size );
543         return this;
544     }
545 
546     public ByteBuffer fillAndReset( int size )
547     {
548         buf.fillAndReset( size );
549         return this;
550     }
551 
552     public boolean isAutoExpand()
553     {
554         return buf.isAutoExpand();
555     }
556 
557     public ByteBuffer setAutoExpand( boolean autoExpand )
558     {
559         buf.setAutoExpand( autoExpand );
560         return this;
561     }
562     
563     public ByteBuffer expand( int pos, int expectedRemaining )
564     {
565         buf.expand( pos, expectedRemaining );
566         return this;
567     }
568 
569     public ByteBuffer expand( int expectedRemaining )
570     {
571         buf.expand( expectedRemaining );
572         return this;
573     }
574 
575     public boolean isPooled()
576     {
577         return buf.isPooled();
578     }
579     
580     public void setPooled( boolean pooled )
581     {
582         buf.setPooled( pooled );
583     }
584     
585     public Object getObject() throws ClassNotFoundException
586     {
587         return buf.getObject();
588     }
589 
590     public Object getObject( ClassLoader classLoader ) throws ClassNotFoundException
591     {
592         return buf.getObject( classLoader );
593     }
594 
595     public ByteBuffer putObject( Object o )
596     {
597         buf.putObject( o );
598         return this;
599     }
600     
601     public InputStream asInputStream()
602     {
603         return buf.asInputStream();
604     }
605     
606     public OutputStream asOutputStream()
607     {
608         return buf.asOutputStream();
609     }
610 }