directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r122635 - in incubator/directory/network/trunk/mina/src/java/org/apache/mina/io: . socket
Date Fri, 17 Dec 2004 11:05:53 GMT
Author: trustin
Date: Fri Dec 17 03:05:52 2004
New Revision: 122635

URL: http://svn.apache.org/viewcvs?view=rev&rev=122635
Log:
 * Added safe random access methods to Read/WriteBuffer.
Modified:
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ReadBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java
   incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
   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/ReadBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ReadBuffer.java?view=diff&rev=122635&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ReadBuffer.java&r1=122634&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ReadBuffer.java&r2=122635
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ReadBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/ReadBuffer.java	Fri
Dec 17 03:05:52 2004
@@ -31,10 +31,6 @@
 {
     boolean hasRemaining();
 
-    ReadBuffer skip( int length );
-
-    ReadBuffer skipAll();
-
     int capacity();
 
     int remaining();
@@ -43,14 +39,22 @@
 
     ReadBuffer reset();
 
-    ReadBuffer signal();
+    int position();
 
-    byte get();
+    ReadBuffer position( int index );
+
+    ReadBuffer skip( int length );
+
+    ReadBuffer skipAll();
+
+    ReadBuffer signal();
 
     ReadBuffer get( byte[] dst );
 
     ReadBuffer get( byte[] dst, int offset, int length );
 
+    byte get();
+
     char getChar();
 
     double getDouble();
@@ -62,6 +66,20 @@
     long getLong();
 
     short getShort();
+
+    byte get( int index );
+
+    char getChar( int index );
+
+    double getDouble( int index );
+
+    float getFloat( int index );
+
+    int getInt( int index );
+
+    long getLong( int index );
+
+    short getShort( int index );
 
     ByteOrder order();
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java?view=diff&rev=122635&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java&r1=122634&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java&r2=122635
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java	(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/WriteBuffer.java	Fri
Dec 17 03:05:52 2004
@@ -37,12 +37,14 @@
 
     int remaining();
 
+    int position();
+
+    WriteBuffer position( int index );
+
     WriteBuffer mark();
 
     WriteBuffer reset();
 
-    WriteBuffer put( byte b );
-
     WriteBuffer put( byte[] src );
 
     WriteBuffer put( byte[] src, int offset, int length );
@@ -51,6 +53,8 @@
 
     WriteBuffer put( ReadBuffer buf );
 
+    WriteBuffer put( byte b );
+
     WriteBuffer putChar( char c );
 
     WriteBuffer putDouble( double d );
@@ -62,6 +66,20 @@
     WriteBuffer putLong( long l );
 
     WriteBuffer putShort( short s );
+
+    WriteBuffer put( int index, byte b );
+
+    WriteBuffer putChar( int index, char c );
+
+    WriteBuffer putDouble( int index, double d );
+
+    WriteBuffer putFloat( int index, float f );
+
+    WriteBuffer putInt( int index, int i );
+
+    WriteBuffer putLong( int index, long l );
+
+    WriteBuffer putShort( int index, short s );
 
     ByteOrder order();
 

Modified: incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Url: http://svn.apache.org/viewcvs/incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java?view=diff&rev=122635&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r1=122634&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java&r2=122635
==============================================================================
--- incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
(original)
+++ incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpIoProcessor.java
Fri Dec 17 03:05:52 2004
@@ -262,6 +262,7 @@
                 {
                     if( readBytes > 0 )
                     {
+                        lock.markBaseIndex();
                         fireDataRead( session, readBytes );
                     }
                     else
@@ -422,6 +423,7 @@
                 if( writtenBytes > 0 )
                 {
                     session.increaseWrittenBytes( writtenBytes );
+                    lock.markBaseIndex();
                     fireDataWritten( session, writtenBytes );
                     Queue markers = lock.getMarkers();
                     for( ;; )

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=122635&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java&r1=122634&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpReadBuffer.java&r2=122635
==============================================================================
--- 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 03:05:52 2004
@@ -35,6 +35,8 @@
 
     private final ByteBuffer buf;
 
+    private int baseIndex;
+
     TcpReadBuffer( TcpSession parent, ByteBuffer buf )
     {
         this.parent = parent;
@@ -46,9 +48,9 @@
         return buf;
     }
 
-    public byte get()
+    void markBaseIndex()
     {
-        return buf.get();
+        baseIndex = buf.position();
     }
 
     public ReadBuffer get( byte[] dst )
@@ -63,6 +65,11 @@
         return this;
     }
 
+    public byte get()
+    {
+        return buf.get();
+    }
+
     public char getChar()
     {
         char ret = buf.getChar();
@@ -94,6 +101,49 @@
         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();
@@ -115,8 +165,23 @@
         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;
     }
@@ -152,5 +217,11 @@
     {
         TcpIoProcessor.getInstance().addReadableSession( parent );
         return this;
+    }
+
+    private void checkIndex( int index )
+    {
+        if( index < 0 )
+            throw new IllegalArgumentException();
     }
 }

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=122635&p1=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java&r1=122634&p2=incubator/directory/network/trunk/mina/src/java/org/apache/mina/io/socket/TcpWriteBuffer.java&r2=122635
==============================================================================
--- 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 03:05:52 2004
@@ -38,6 +38,8 @@
     private final ByteBuffer buf;
 
     private final Queue markers = new Queue( 16 );
+    
+    private int baseIndex;
 
     TcpWriteBuffer( TcpSession session, ByteBuffer buf )
     {
@@ -50,10 +52,9 @@
         return buf;
     }
 
-    public WriteBuffer put( byte b )
+    void markBaseIndex()
     {
-        buf.put( b );
-        return this;
+        baseIndex = buf.position();
     }
 
     public WriteBuffer put( byte[] src )
@@ -86,6 +87,12 @@
         return this;
     }
 
+    public WriteBuffer put( byte b )
+    {
+        buf.put( b );
+        return this;
+    }
+
     public WriteBuffer putChar( char c )
     {
         buf.putChar( c );
@@ -122,6 +129,55 @@
         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();
@@ -149,6 +205,18 @@
         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();
@@ -225,5 +293,11 @@
         {
             this.bytesLeft = bytesLeft;
         }
+    }
+
+    private void checkIndex( int index )
+    {
+        if( index < 0 )
+            throw new IllegalArgumentException();
     }
 }

Mime
View raw message