directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r122709 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina: io/socket util
Date Sat, 18 Dec 2004 04:58:25 GMT
Author: trustin
Date: Fri Dec 17 20:58:24 2004
New Revision: 122709

URL: http://svn.apache.org/viewcvs?view=rev&rev=122709
Log:
 * Added: Pulled out some general ByteByteBuffer manipulation methods to AbstractReadBuffer
and AbstractWriteBuffer

Added:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractReadBuffer.java
  (contents, props changed)
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
  (contents, props changed)
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java?view=diff&rev=122709&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java&r1=122708&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java&r2=122709
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java
Fri Dec 17 20:58:24 2004
@@ -19,10 +19,9 @@
 package org.apache.mina.io.socket;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
 import org.apache.mina.io.ReadBuffer;
-import org.apache.mina.io.WriteBuffer;
+import org.apache.mina.util.AbstractReadBuffer;
 
 /**
  * TODO Document me.
@@ -30,218 +29,14 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$,
  */
-class TcpReadBuffer implements ReadBuffer
+class TcpReadBuffer extends AbstractReadBuffer implements ReadBuffer
 {
     private final TcpSession parent;
 
-    private final ByteBuffer buf;
-
-    private int baseIndex;
-
     TcpReadBuffer( TcpSession parent, ByteBuffer buf )
     {
+        super(buf);
         this.parent = parent;
-        this.buf = buf;
-    }
-
-    ByteBuffer buf()
-    {
-        return buf;
-    }
-
-    void markBaseIndex()
-    {
-        baseIndex = buf.position();
-    }
-
-    public ReadBuffer get( byte[] dst )
-    {
-        buf.get( dst );
-        return this;
-    }
-
-    public ReadBuffer get( byte[] dst, int offset, int length )
-    {
-        buf.get( dst, offset, length );
-        return this;
-    }
-
-    public ReadBuffer get( ByteBuffer buf )
-    {
-        buf.put( this.buf );
-        return this;
-    }
-
-    public ReadBuffer get( WriteBuffer buf )
-    {
-        buf.put( this.buf );
-        return this;
-    }
-
-    public int getAsPossible( ByteBuffer buf )
-    {
-        int length = Math.min( buf.remaining(), this.buf.remaining() );
-        if( length > 0 )
-        {
-            int oldLimit = buf.limit();
-            buf.limit( buf.position() + length );
-            buf.put( this.buf );
-            buf.limit( oldLimit );
-        }
-        return length;
-    }
-
-    public int getAsPossible( WriteBuffer buf )
-    {
-        return buf.putAsPossible( this );
-    }
-
-    public byte get()
-    {
-        return buf.get();
-    }
-
-    public char getChar()
-    {
-        char ret = buf.getChar();
-        return ret;
-    }
-
-    public double getDouble()
-    {
-        return buf.getDouble();
-    }
-
-    public float getFloat()
-    {
-        return buf.getFloat();
-    }
-
-    public int getInt()
-    {
-        return buf.getInt();
-    }
-
-    public long getLong()
-    {
-        return buf.getLong();
-    }
-
-    public short getShort()
-    {
-        return buf.getShort();
-    }
-
-    public byte get( int index )
-    {
-        checkIndex( index );
-        return buf.get( baseIndex + index );
-    }
-
-    public char getChar( int index )
-    {
-        checkIndex( index );
-        char ret = buf.getChar( baseIndex + index );
-        return ret;
-    }
-
-    public double getDouble( int index )
-    {
-        checkIndex( index );
-        return buf.getDouble( baseIndex + index );
-    }
-
-    public float getFloat( int index )
-    {
-        checkIndex( index );
-        return buf.getFloat( baseIndex + index );
-    }
-
-    public int getInt( int index )
-    {
-        checkIndex( index );
-        return buf.getInt( baseIndex + index );
-    }
-
-    public long getLong( int index )
-    {
-        checkIndex( index );
-        return buf.getLong( baseIndex + index );
-    }
-
-    public short getShort( int index )
-    {
-        checkIndex( index );
-        return buf.getShort( baseIndex + index );
-    }
-
-    public ByteOrder order()
-    {
-        return buf.order();
-    }
-
-    public ReadBuffer order( ByteOrder order )
-    {
-        buf.order( order );
-        return this;
-    }
-
-    public ByteBuffer asByteBuffer()
-    {
-        return buf.duplicate().asReadOnlyBuffer();
-    }
-
-    public boolean hasRemaining()
-    {
-        return buf.hasRemaining();
-    }
-
-    public int position()
-    {
-        return buf.position() - baseIndex;
-    }
-
-    public ReadBuffer position( int index )
-    {
-        checkIndex( index );
-        buf.position( baseIndex + index );
-        return this;
-    }
-
-    public ReadBuffer skip( int length )
-    {
-        int newIndex = buf.position() + length;
-        if( newIndex < baseIndex )
-            throw new IllegalArgumentException();
-        buf.position( buf.position() + length );
-        return this;
-    }
-
-    public ReadBuffer skipAll()
-    {
-        return skip( remaining() );
-    }
-
-    public int capacity()
-    {
-        return buf.capacity();
-    }
-
-    public int remaining()
-    {
-        return buf.remaining();
-    }
-
-    public ReadBuffer mark()
-    {
-        buf.mark();
-        return this;
-    }
-
-    public ReadBuffer reset()
-    {
-        buf.reset();
-        return this;
     }
 
     public ReadBuffer signal()
@@ -249,10 +44,15 @@
         TcpIoProcessor.getInstance().addReadableSession( parent );
         return this;
     }
+    
+    
+    protected ByteBuffer buf()
+    {
+        return super.buf();
+    }
 
-    private void checkIndex( int index )
+    protected void markBaseIndex()
     {
-        if( index < 0 )
-            throw new IllegalArgumentException();
+        super.markBaseIndex();
     }
 }

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java?view=diff&rev=122709&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java&r1=122708&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java&r2=122709
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java
Fri Dec 17 20:58:24 2004
@@ -19,10 +19,9 @@
 package org.apache.mina.io.socket;
 
 import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
 
-import org.apache.mina.io.ReadBuffer;
 import org.apache.mina.io.WriteBuffer;
+import org.apache.mina.util.AbstractWriteBuffer;
 import org.apache.mina.util.Queue;
 
 /**
@@ -31,191 +30,14 @@
  * @author Trustin Lee (trustin@apache.org)
  * @version $Rev$, $Date$,
  */
-class TcpWriteBuffer implements WriteBuffer
+class TcpWriteBuffer extends AbstractWriteBuffer implements WriteBuffer
 {
     private final TcpSession session;
 
-    private final ByteBuffer buf;
-
-    private final Queue markers = new Queue( 16 );
-
-    private int baseIndex;
-
     TcpWriteBuffer( TcpSession session, ByteBuffer buf )
     {
+        super(buf);
         this.session = session;
-        this.buf = buf;
-    }
-
-    ByteBuffer buf()
-    {
-        return buf;
-    }
-
-    void markBaseIndex()
-    {
-        baseIndex = buf.position();
-    }
-
-    public WriteBuffer put( byte[] src )
-    {
-        buf.put( src );
-        return this;
-    }
-
-    public WriteBuffer put( byte[] src, int offset, int length )
-    {
-        buf.put( src, offset, length );
-        return this;
-    }
-
-    public WriteBuffer put( ReadBuffer buf )
-    {
-        checkBufferCompatibility( buf );
-        this.buf.put( ( ( TcpReadBuffer ) buf ).buf() );
-        return this;
-    }
-
-    public WriteBuffer put( ByteBuffer buf )
-    {
-        this.buf.put( buf );
-        return this;
-    }
-
-    public int putAsPossible( ReadBuffer buf )
-    {
-        checkBufferCompatibility( buf );
-        return this.putAsPossible( ( ( TcpReadBuffer ) buf ).buf() );
-    }
-
-    public int putAsPossible( ByteBuffer buf )
-    {
-        int length = Math.min( buf.remaining(), this.buf.remaining() );
-        if( length > 0 )
-        {
-            int oldLimit = buf.limit();
-            buf.limit( buf.position() + length );
-            this.buf.put( buf );
-            buf.limit( oldLimit );
-        }
-
-        return length;
-    }
-
-    private void checkBufferCompatibility( ReadBuffer buf )
-    {
-        if( ! ( buf instanceof TcpReadBuffer ) )
-        {
-            throw new IllegalArgumentException( "Incompatible buffer type: "
-                                                + buf.getClass() );
-        }
-    }
-
-    public WriteBuffer put( byte b )
-    {
-        buf.put( b );
-        return this;
-    }
-
-    public WriteBuffer putChar( char c )
-    {
-        buf.putChar( c );
-        return this;
-    }
-
-    public WriteBuffer putDouble( double d )
-    {
-        buf.putDouble( d );
-        return this;
-    }
-
-    public WriteBuffer putFloat( float f )
-    {
-        buf.putFloat( f );
-        return this;
-    }
-
-    public WriteBuffer putInt( int i )
-    {
-        buf.putInt( i );
-        return this;
-    }
-
-    public WriteBuffer putLong( long l )
-    {
-        buf.putLong( l );
-        return this;
-    }
-
-    public WriteBuffer putShort( short s )
-    {
-        buf.putShort( s );
-        return this;
-    }
-
-    public WriteBuffer put( int index, byte b )
-    {
-        checkIndex( index );
-        buf.put( baseIndex + index, b );
-        return this;
-    }
-
-    public WriteBuffer putChar( int index, char c )
-    {
-        checkIndex( index );
-        buf.putChar( baseIndex + index, c );
-        return this;
-    }
-
-    public WriteBuffer putDouble( int index, double d )
-    {
-        checkIndex( index );
-        buf.putDouble( baseIndex + index, d );
-        return this;
-    }
-
-    public WriteBuffer putFloat( int index, float f )
-    {
-        checkIndex( index );
-        buf.putFloat( baseIndex + index, f );
-        return this;
-    }
-
-    public WriteBuffer putInt( int index, int i )
-    {
-        checkIndex( index );
-        buf.putInt( baseIndex + index, i );
-        return this;
-    }
-
-    public WriteBuffer putLong( int index, long l )
-    {
-        checkIndex( index );
-        buf.putLong( baseIndex + index, l );
-        return this;
-    }
-
-    public WriteBuffer putShort( int index, short s )
-    {
-        checkIndex( index );
-        buf.putShort( baseIndex + index, s );
-        return this;
-    }
-
-    public ByteOrder order()
-    {
-        return buf.order();
-    }
-
-    public WriteBuffer order( ByteOrder order )
-    {
-        buf.order( order );
-        return this;
-    }
-
-    public ByteBuffer asByteBuffer()
-    {
-        return buf.duplicate();
     }
 
     public WriteBuffer flush()
@@ -223,105 +45,19 @@
         session.flush();
         return this;
     }
-
-    public boolean hasRemaining()
+    
+    protected ByteBuffer buf()
     {
-        return buf.hasRemaining();
+        return super.buf();
     }
-
-    public int position()
+    
+    protected Queue getMarkers()
     {
-        return buf.position() - baseIndex;
-    }
-
-    public WriteBuffer position( int index )
-    {
-        checkIndex( index );
-        buf.position( baseIndex + index );
-        return this;
+        return super.getMarkers();
     }
-
-    public WriteBuffer clear()
-    {
-        buf.clear();
-        return this;
-    }
-
-    public int capacity()
-    {
-        return buf.capacity();
-    }
-
-    public int remaining()
-    {
-        return buf.remaining();
-    }
-
-    public WriteBuffer mark()
-    {
-        buf.mark();
-        return this;
-    }
-
-    public WriteBuffer reset()
-    {
-        buf.reset();
-        return this;
-    }
-
-    Queue getMarkers()
-    {
-        return markers;
-    }
-
-    public WriteBuffer putMarker( Object marker )
-    {
-        int bytesLeft;
-        if( markers.isEmpty() )
-        {
-            bytesLeft = buf.position();
-        }
-        else
-        {
-            bytesLeft = buf.position()
-                        - ( ( Marker ) markers.last() ).getBytesLeft();
-        }
-
-        markers.push( new Marker( marker, bytesLeft ) );
-        return this;
-    }
-
-    static class Marker
-    {
-        private final Object value;
-
-        private int bytesLeft;
-
-        private Marker( Object value, int bytesLeft )
-        {
-            this.value = value;
-            this.bytesLeft = bytesLeft;
-        }
-
-        public Object getValue()
-        {
-            return value;
-        }
-
-        public int getBytesLeft()
-        {
-            return bytesLeft;
-        }
-
-        public void setBytesLeft( int bytesLeft )
-        {
-            this.bytesLeft = bytesLeft;
-        }
-    }
-
-    private void checkIndex( int index )
+    
+    protected void markBaseIndex()
     {
-        if( index < 0 )
-            throw new IllegalArgumentException();
+        super.markBaseIndex();
     }
 }

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractReadBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractReadBuffer.java?view=auto&rev=122709
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractReadBuffer.java
Fri Dec 17 20:58:24 2004
@@ -0,0 +1,249 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.mina.io.ReadBuffer;
+import org.apache.mina.io.WriteBuffer;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$,
+ */
+public abstract class AbstractReadBuffer implements ReadBuffer
+{
+    protected final ByteBuffer buf;
+
+    private int baseIndex;
+
+    protected AbstractReadBuffer( ByteBuffer buf )
+    {
+        this.buf = buf;
+    }
+
+    protected ByteBuffer buf()
+    {
+        return buf;
+    }
+
+    protected void markBaseIndex()
+    {
+        baseIndex = buf.position();
+    }
+
+    public ReadBuffer get( byte[] dst )
+    {
+        buf.get( dst );
+        return this;
+    }
+
+    public ReadBuffer get( byte[] dst, int offset, int length )
+    {
+        buf.get( dst, offset, length );
+        return this;
+    }
+
+    public ReadBuffer get( ByteBuffer buf )
+    {
+        buf.put( this.buf );
+        return this;
+    }
+
+    public ReadBuffer get( WriteBuffer buf )
+    {
+        buf.put( this.buf );
+        return this;
+    }
+
+    public int getAsPossible( ByteBuffer buf )
+    {
+        int length = Math.min( buf.remaining(), this.buf.remaining() );
+        if( length > 0 )
+        {
+            int oldLimit = buf.limit();
+            buf.limit( buf.position() + length );
+            buf.put( this.buf );
+            buf.limit( oldLimit );
+        }
+        return length;
+    }
+
+    public int getAsPossible( WriteBuffer buf )
+    {
+        return buf.putAsPossible( this );
+    }
+
+    public byte get()
+    {
+        return buf.get();
+    }
+
+    public char getChar()
+    {
+        char ret = buf.getChar();
+        return ret;
+    }
+
+    public double getDouble()
+    {
+        return buf.getDouble();
+    }
+
+    public float getFloat()
+    {
+        return buf.getFloat();
+    }
+
+    public int getInt()
+    {
+        return buf.getInt();
+    }
+
+    public long getLong()
+    {
+        return buf.getLong();
+    }
+
+    public short getShort()
+    {
+        return buf.getShort();
+    }
+
+    public byte get( int index )
+    {
+        checkIndex( index );
+        return buf.get( baseIndex + index );
+    }
+
+    public char getChar( int index )
+    {
+        checkIndex( index );
+        char ret = buf.getChar( baseIndex + index );
+        return ret;
+    }
+
+    public double getDouble( int index )
+    {
+        checkIndex( index );
+        return buf.getDouble( baseIndex + index );
+    }
+
+    public float getFloat( int index )
+    {
+        checkIndex( index );
+        return buf.getFloat( baseIndex + index );
+    }
+
+    public int getInt( int index )
+    {
+        checkIndex( index );
+        return buf.getInt( baseIndex + index );
+    }
+
+    public long getLong( int index )
+    {
+        checkIndex( index );
+        return buf.getLong( baseIndex + index );
+    }
+
+    public short getShort( int index )
+    {
+        checkIndex( index );
+        return buf.getShort( baseIndex + index );
+    }
+
+    public ByteOrder order()
+    {
+        return buf.order();
+    }
+
+    public ReadBuffer order( ByteOrder order )
+    {
+        buf.order( order );
+        return this;
+    }
+
+    public ByteBuffer asByteBuffer()
+    {
+        return buf.duplicate().asReadOnlyBuffer();
+    }
+
+    public boolean hasRemaining()
+    {
+        return buf.hasRemaining();
+    }
+
+    public int position()
+    {
+        return buf.position() - baseIndex;
+    }
+
+    public ReadBuffer position( int index )
+    {
+        checkIndex( index );
+        buf.position( baseIndex + index );
+        return this;
+    }
+
+    public ReadBuffer skip( int length )
+    {
+        int newIndex = buf.position() + length;
+        if( newIndex < baseIndex )
+            throw new IllegalArgumentException();
+        buf.position( buf.position() + length );
+        return this;
+    }
+
+    public ReadBuffer skipAll()
+    {
+        return skip( remaining() );
+    }
+
+    public int capacity()
+    {
+        return buf.capacity();
+    }
+
+    public int remaining()
+    {
+        return buf.remaining();
+    }
+
+    public ReadBuffer mark()
+    {
+        buf.mark();
+        return this;
+    }
+
+    public ReadBuffer reset()
+    {
+        buf.reset();
+        return this;
+    }
+
+    private void checkIndex( int index )
+    {
+        if( index < 0 )
+            throw new IllegalArgumentException();
+    }
+}
\ No newline at end of file

Added: incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java?view=auto&rev=122709
==============================================================================
--- (empty file)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/util/AbstractWriteBuffer.java
Fri Dec 17 20:58:24 2004
@@ -0,0 +1,318 @@
+/*
+ *   @(#) $Id$
+ *
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.mina.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.mina.io.ReadBuffer;
+import org.apache.mina.io.WriteBuffer;
+import org.apache.mina.util.Queue;
+
+/**
+ * TODO Document me.
+ * 
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$,
+ */
+public abstract class AbstractWriteBuffer implements WriteBuffer
+{
+    protected final ByteBuffer buf;
+
+    protected final Queue markers = new Queue( 16 );
+
+    private int baseIndex;
+
+    protected AbstractWriteBuffer( ByteBuffer buf )
+    {
+        this.buf = buf;
+    }
+
+    protected ByteBuffer buf()
+    {
+        return buf;
+    }
+
+    protected void markBaseIndex()
+    {
+        baseIndex = buf.position();
+    }
+
+    public WriteBuffer put( byte[] src )
+    {
+        buf.put( src );
+        return this;
+    }
+
+    public WriteBuffer put( byte[] src, int offset, int length )
+    {
+        buf.put( src, offset, length );
+        return this;
+    }
+
+    public WriteBuffer put( ReadBuffer buf )
+    {
+        checkBufferCompatibility( buf );
+        this.buf.put( ( ( AbstractReadBuffer ) buf ).buf() );
+        return this;
+    }
+
+    public WriteBuffer put( ByteBuffer buf )
+    {
+        this.buf.put( buf );
+        return this;
+    }
+
+    public int putAsPossible( ReadBuffer buf )
+    {
+        checkBufferCompatibility( buf );
+        return this.putAsPossible( ( ( AbstractReadBuffer ) buf ).buf() );
+    }
+
+    public int putAsPossible( ByteBuffer buf )
+    {
+        int length = Math.min( buf.remaining(), this.buf.remaining() );
+        if( length > 0 )
+        {
+            int oldLimit = buf.limit();
+            buf.limit( buf.position() + length );
+            this.buf.put( buf );
+            buf.limit( oldLimit );
+        }
+
+        return length;
+    }
+
+    private void checkBufferCompatibility( ReadBuffer buf )
+    {
+        if( ! ( buf instanceof AbstractReadBuffer ) )
+        {
+            throw new IllegalArgumentException( "Incompatible buffer type: "
+                                                + buf.getClass() );
+        }
+    }
+
+    public WriteBuffer put( byte b )
+    {
+        buf.put( b );
+        return this;
+    }
+
+    public WriteBuffer putChar( char c )
+    {
+        buf.putChar( c );
+        return this;
+    }
+
+    public WriteBuffer putDouble( double d )
+    {
+        buf.putDouble( d );
+        return this;
+    }
+
+    public WriteBuffer putFloat( float f )
+    {
+        buf.putFloat( f );
+        return this;
+    }
+
+    public WriteBuffer putInt( int i )
+    {
+        buf.putInt( i );
+        return this;
+    }
+
+    public WriteBuffer putLong( long l )
+    {
+        buf.putLong( l );
+        return this;
+    }
+
+    public WriteBuffer putShort( short s )
+    {
+        buf.putShort( s );
+        return this;
+    }
+
+    public WriteBuffer put( int index, byte b )
+    {
+        checkIndex( index );
+        buf.put( baseIndex + index, b );
+        return this;
+    }
+
+    public WriteBuffer putChar( int index, char c )
+    {
+        checkIndex( index );
+        buf.putChar( baseIndex + index, c );
+        return this;
+    }
+
+    public WriteBuffer putDouble( int index, double d )
+    {
+        checkIndex( index );
+        buf.putDouble( baseIndex + index, d );
+        return this;
+    }
+
+    public WriteBuffer putFloat( int index, float f )
+    {
+        checkIndex( index );
+        buf.putFloat( baseIndex + index, f );
+        return this;
+    }
+
+    public WriteBuffer putInt( int index, int i )
+    {
+        checkIndex( index );
+        buf.putInt( baseIndex + index, i );
+        return this;
+    }
+
+    public WriteBuffer putLong( int index, long l )
+    {
+        checkIndex( index );
+        buf.putLong( baseIndex + index, l );
+        return this;
+    }
+
+    public WriteBuffer putShort( int index, short s )
+    {
+        checkIndex( index );
+        buf.putShort( baseIndex + index, s );
+        return this;
+    }
+
+    public ByteOrder order()
+    {
+        return buf.order();
+    }
+
+    public WriteBuffer order( ByteOrder order )
+    {
+        buf.order( order );
+        return this;
+    }
+
+    public ByteBuffer asByteBuffer()
+    {
+        return buf.duplicate();
+    }
+
+    public boolean hasRemaining()
+    {
+        return buf.hasRemaining();
+    }
+
+    public int position()
+    {
+        return buf.position() - baseIndex;
+    }
+
+    public WriteBuffer position( int index )
+    {
+        checkIndex( index );
+        buf.position( baseIndex + index );
+        return this;
+    }
+
+    public WriteBuffer clear()
+    {
+        buf.clear();
+        return this;
+    }
+
+    public int capacity()
+    {
+        return buf.capacity();
+    }
+
+    public int remaining()
+    {
+        return buf.remaining();
+    }
+
+    public WriteBuffer mark()
+    {
+        buf.mark();
+        return this;
+    }
+
+    public WriteBuffer reset()
+    {
+        buf.reset();
+        return this;
+    }
+
+    protected Queue getMarkers()
+    {
+        return markers;
+    }
+
+    public WriteBuffer putMarker( Object marker )
+    {
+        int bytesLeft;
+        if( markers.isEmpty() )
+        {
+            bytesLeft = buf.position();
+        }
+        else
+        {
+            bytesLeft = buf.position()
+                        - ( ( Marker ) markers.last() ).getBytesLeft();
+        }
+
+        markers.push( new Marker( marker, bytesLeft ) );
+        return this;
+    }
+
+    public static class Marker
+    {
+        private final Object value;
+
+        private int bytesLeft;
+
+        private Marker( Object value, int bytesLeft )
+        {
+            this.value = value;
+            this.bytesLeft = bytesLeft;
+        }
+
+        public Object getValue()
+        {
+            return value;
+        }
+
+        public int getBytesLeft()
+        {
+            return bytesLeft;
+        }
+
+        public void setBytesLeft( int bytesLeft )
+        {
+            this.bytesLeft = bytesLeft;
+        }
+    }
+
+    private void checkIndex( int index )
+    {
+        if( index < 0 )
+            throw new IllegalArgumentException();
+    }
+}
\ No newline at end of file

Mime
View raw message