directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1784232 [8/9] - in /directory/mavibot/branches/single-value/mavibot/src: main/java/org/apache/directory/mavibot/btree/ main/java/org/apache/directory/mavibot/btree/serializer/ test/java/org/apache/directory/mavibot/btree/
Date Fri, 24 Feb 2017 07:16:38 GMT
Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/WriteTransaction.java Fri Feb 24 07:16:37 2017
@@ -19,74 +19,458 @@
  */
 package org.apache.directory.mavibot.btree;
 
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.apache.directory.mavibot.btree.exception.BadTransactionStateException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
 
 /**
- * A data structure used to manage a write transaction
+ * A data structure used to manage a write transaction. We keep a track of all the modified 
+ * {@link WALObject}s, and all the copied {@link WALObject}s, that will be flushed at
+ * the end of the transaction, if it is successful.
+ * 
+ *  We also keep a track of the last position in the file, as we may reclaim some
+ *  new pages when the FreePage list is empty.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-/* no qualifier */ class WriteTransaction
+public class WriteTransaction extends AbstractTransaction
 {
-    /** A lock used to protect the write operation against concurrent access */
-    protected ReentrantLock writeLock;
-
-    /* no qualifier */WriteTransaction()
+    /** The List containing all the user modified pages, in the order they have been created */
+    //private List<WALObject<?, ?>> newUserPages = new ArrayList<WALObject<?, ?>>();
+    private List<WALObject<?, ?>> newPages = new ArrayList<WALObject<?, ?>>();
+    
+    /** The List containing all the BOB/CPB modified pages, in the order they have been created */
+    //private List<WALObject<?, ?>> newAdminPages = new ArrayList<WALObject<?, ?>>();
+
+    /** The map containing all the copied pages, using their offset as a key */
+    private Map<Long, WALObject<?, ?>> copiedPageMap = new HashMap<>();
+    
+    /**
+     * Creates a new WriteTransaction instance
+     * 
+     * @param recordManager The associated {@link RecordManager}
+     */
+    WriteTransaction( RecordManager recordManager )
     {
-        //System.out.println( "Creating the transaction oject" );
-        writeLock = new ReentrantLock();
+        super( recordManager );
+        
+        //System.out.println( "---> Write transaction started, " + this );
+        
+        // We have to increment the revision
+        recordManagerHeader.revision++;
     }
 
 
-    /* no qualifier */ void start()
+    /**
+     * {@inheritDoc}
+     * @throws IOException
+     */
+    @Override
+    public void close() throws IOException
     {
-        /*
-        if ( writeLock.isLocked() )
+        if ( !isClosed() )
         {
-            throw new BadTransactionStateException( "Cannot start a write transaction when it's already started" );
+            commit();
+        }
+        else
+        {
+            //newUserPages.clear();
+            //newAdminPages.clear();
+            newPages.clear();
+            copiedPageMap.clear();
+            super.close();
         }
-        */
-
-        //System.out.println( "Start a TXN [" + Thread.currentThread().getName() + "]" );
-
-        writeLock.lock();
-        //System.out.println( "WriteTransaction " + Thread.currentThread().getName() );
     }
 
 
-    /* no qualifier */ void commit()
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void commit() throws IOException
     {
-        if ( !writeLock.isLocked() )
+        if ( !isClosed() )
         {
-            throw new BadTransactionStateException( "Cannot commit a write transaction when it's not started" );
+            // First, find the modified users B-trees, and flush the user's pages 
+            Set<BTree<?, ?>> btrees = new HashSet<>();
+            
+            //for ( WALObject<?, ?> walObject : newUserPages )
+            for ( WALObject<?, ?> walObject : newPages )
+            {
+                BTree<?, ?> btree = walObject.getBtree();
+                
+                // Flush the page
+                walObject.serialize( this );
+                recordManager.flushPages( recordManagerHeader, walObject.getPageIOs() );
+                
+                // and update the B-tree list if needed
+                btrees.add( btree );
+            }
+            
+            // We can clean the user's list
+            //newUserPages.clear();
+            newPages.clear();
+
+            // Update the BOB, if we aren't already processing the BOB
+            for ( BTree<?, ?> btree : btrees )
+            {
+                recordManager.insertInBtreeOfBtrees( this, btree );
+            }
+            
+            //for ( WALObject<?, ?> walObject : newAdminPages )
+            for ( WALObject<?, ?> walObject : newPages )
+            {
+                // Flush the page
+                walObject.serialize( this );
+                recordManager.flushPages( recordManagerHeader, walObject.getPageIOs() );
+            }
+
+            // BOB done, clear the list
+            //newAdminPages.clear();
+            newPages.clear();
+            
+            // Add the copied pages in the CPB
+            recordManager.insertInCopiedPagesBtree( this );
+            
+            // Last not least, Flush the CPB pages
+            //for ( WALObject<?, ?> walObject : newAdminPages )
+            for ( WALObject<?, ?> walObject : newPages )
+            {
+                walObject.serialize( this );
+                recordManager.flushPages( recordManagerHeader, walObject.getPageIOs() );
+            }
+            
+            long newBtreeOfBtreesOffet = ((BTreeImpl<NameRevision, Long>)recordManagerHeader.btreeOfBtrees).getBtreeHeader().offset;
+            long newCopiedPagesBtreeOffset = ((BTreeImpl<RevisionName, long[]>)recordManagerHeader.copiedPagesBtree).getBtreeHeader().offset;
+
+            // And update the RecordManagerHeader
+            recordManager.updateRecordManagerHeader( recordManagerHeader, newBtreeOfBtreesOffet, newCopiedPagesBtreeOffset );
+            recordManager.writeRecordManagerHeader( recordManagerHeader );
+            
+            // Finally, close the transaction
+            //newAdminPages.clear();
+            newPages.clear();
+            copiedPageMap.clear();
+            super.close();
         }
+    }
 
-        //System.out.println( "Commit a TXN[" + Thread.currentThread().getName() + "]" );
 
-        writeLock.unlock();
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void abort() throws IOException
+    {
+        // We just have to empty the maps
+        //newUserPages.clear();
+        //newAdminPages.clear();
+        newPages.clear();
+        copiedPageMap.clear();
+        super.close();
     }
 
 
-    /* no qualifier */ void rollback()
+    /**
+     * Updates the map of new BTreeHeaders
+     * 
+     * @param <K> The b-tree key type
+     * @param <V> The b-tree value type
+     * @param btreeHeader The new BtreeHeader
+     */
+    <K, V> void updateNewBTreeHeaders( BTreeHeader<K, V> btreeHeader )
     {
-        if ( !writeLock.isLocked() )
+    }
+    
+    
+    /**
+     * @return The offset of the first free page
+     */
+    /* No qualifier */ long getFirstFreePage()
+    {
+        return recordManagerHeader.firstFreePage;
+    }
+    
+    
+    /**
+     * @return The offset of the end of the file
+     */
+    /* No qualifier */ long getLastOffset()
+    {
+        return recordManagerHeader.lastOffset;
+    }
+    
+    
+    /**
+     * Change the last offset in the file
+     * 
+     * @param The new offset of the end of the file
+     */
+    /* No qualifier */ void setLastOffset( long lastOffset )
+    {
+        recordManagerHeader.lastOffset = lastOffset;
+    }
+    
+    
+    /**
+     * Add a page in the list of modified {@link WALObject}s. If there is an existing 
+     * {@link WALObject}, it will be replaced with the new content. Note that a {@link WALObject} 
+     * is associated to one to many {@link PageIO}s.
+     *  
+     * @param walObject The {@link WALObject} to store
+     */
+    /* No qualifier */void addWALObject( WALObject walObject ) throws IOException
+    {
+        if ( walObject != null )
         {
-            throw new BadTransactionStateException( "Cannot commit a write transaction when it's not started" );
+            newPages.add( walObject );
+            /*
+            if ( walObject.getBtree().getType() == BTreeTypeEnum.PERSISTED )
+            {
+                newUserPages.add( walObject );
+            }
+            else
+            {
+                newAdminPages.add( walObject );
+            }
+            */
         }
-
-        //System.out.println( "Rollback a TXN" );
-        writeLock.unlock();
     }
+    
+    
+    /**
+     * Add a page in the list of modified {@link WALObject}s. If there is an existing 
+     * {@link WALObject}, it will be replaced with the new content. Note that a {@link WALObject} 
+     * is associated to one to many {@link PageIO}s.
+     *  
+     * @param walObject The {@link WALObject} to store
+     */
+    /* No qualifier */WALObject removeWALObject( long id ) throws IOException
+    {
+        for ( int i = 0; i < newPages.size(); i++ )
+        {
+            if ( newPages.get( i ).getId() == id )
+            {
+                return newPages.remove( i );
+            }
+        }
+        /*
+        for ( int i = 0; i < newUserPages.size(); i++ )
+        {
+            if ( newUserPages.get( i ).getId() == id )
+            {
+                return newUserPages.remove( i );
+            }
+        }
 
+        for ( int i = 0; i < newAdminPages.size(); i++ )
+        {
+            if ( newAdminPages.get( i ).getId() == id )
+            {
+                return newAdminPages.remove( i );
+            }
+        }
+        */
+        
+        return null;
+    }
+    
+    
+    /**
+     * Add a WALObject in the list of copied {@link WALObject}s. If there is an existing 
+     * {@link WALObject}, it will be replaced with the new content. Note that a {@link WALObject} 
+     * is associated to one to many {@link PageIO}s.
+     *  
+     * @param walObject The {@link WALObject} to store
+     */
+    /* No qualifier */void addCopiedWALObject( WALObject walObject )
+    {
+        if ( walObject != null )
+        {
+            copiedPageMap.put( Long.valueOf( walObject.getOffset() ), walObject );
+        }
+    }
+    
+    
+    /**
+     * Search for a {@link WALObject}. It may be present in the cache, or if it's not, we will
+     * have to fetch it from the disk.
+     * 
+     * @param offset The position of this {@link WALObject} on disk
+     * @return The found {@link WALObject}
+     */
+    public WALObject<?, ?> getWALObject( long id )
+    {
+        for ( WALObject walObject : newPages )
+        {
+            if ( walObject.getId() == id )
+            {
+                return walObject;
+            }
+        }
+        /*
+        for ( WALObject walObject : newUserPages )
+        {
+            if ( walObject.getId() == id )
+            {
+                return walObject;
+            }
+        }
 
+        for ( WALObject walObject : newAdminPages )
+        {
+            if ( walObject.getId() == id )
+            {
+                return walObject;
+            }
+        }
+        */
+        
+        return null;
+    }
+    
+    
+    /* No qualifier */ Map<Long, WALObject<?, ?>> getCopiedPageMap()
+    {
+        return copiedPageMap;
+    }
+    
+    
     /**
-     * Tells if the transaction has started
-     * @return true if the transaction has started
+     * {@inheritDoc}
      */
-    /* no qualifier */ boolean isStarted()
+    @Override
+    public String toString()
     {
-        return writeLock.isLocked();
+        StringBuilder sb = new StringBuilder();
+        
+        sb.append( "W:" );
+        sb.append( super.toString() );
+        sb.append( ", last offset" );
+        sb.append( String.format( " %x", getLastOffset() ) ).append( '\n' );
+        
+        if ( newPages.size() > 0 )
+        {
+            sb.append( "    pageList :[\n        " );
+            boolean isFirst = true;
+            
+            for ( WALObject walObject : newPages )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ",\n        " );
+                }
+
+                sb.append( walObject.prettyPrint() );
+            }
+            
+            sb.append( '\n' );
+            
+            /*
+            for ( Entry<Long, WALObject<?, ?>> entry : pageMap.entrySet() )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ", " );
+                }
+                
+                sb.append( String.format( "%x", entry.getKey() ) );
+                sb.append(  ':' );
+                sb.append( '<' );
+                sb.append( entry.getValue().getName() );
+                sb.append( ':' );
+                
+                if ( entry.getValue().getRevision() == RecordManager.NO_PAGE )
+                {
+                    sb.append( "info" );
+                }
+                else
+                {
+                    sb.append( entry.getValue().getRevision() );
+                }
+                sb.append( '>' );
+                sb.append( entry.getValue().getClass().getSimpleName() );
+            }
+            
+            sb.append( "]\n" );
+            */
+        }
+        else
+        {
+            sb.append( "    UserPageList empty\n" );
+        }
+        
+        /*
+        if ( newAdminPages.size() > 0 )
+        {
+            sb.append( "    AdminPageList :[\n        " );
+            boolean isFirst = true;
+            
+            for ( WALObject walObject : newAdminPages )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ",\n        " );
+                }
+
+                sb.append( walObject.prettyPrint() );
+            }
+            
+            sb.append( '\n' );
+        }
+        else
+        {
+            sb.append( "    AdminPageList empty\n" );
+        }
+        */
+
+        if ( copiedPageMap.size() > 0 )
+        {
+            sb.append( "    CopiedPagesMap :[\n        " );
+            boolean isFirst = true;
+            
+            for ( Entry<Long, WALObject<?, ?>> entry : copiedPageMap.entrySet() )
+            {
+                if ( isFirst )
+                {
+                    isFirst = false;
+                }
+                else
+                {
+                    sb.append( ",\n        " );
+                }
+                
+                sb.append( String.format( "%x", entry.getKey() ) );
+                sb.append(  ':' );
+                sb.append( '<' ).append( entry.getValue().getName() ).append( '>' );
+                
+                sb.append( entry.getValue().getClass().getSimpleName() );
+            }
+            
+            sb.append( "]\n" );
+        }
+        else
+        {
+            sb.append( "    CopiedPagesMap empty\n" );
+        }
+
+        return sb.toString();
     }
 }

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/BooleanSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/BooleanSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/BooleanSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/BooleanSerializer.java Fri Feb 24 07:16:37 2017
@@ -49,6 +49,7 @@ public class BooleanSerializer extends A
     /**
      * {@inheritDoc}
      */
+    @Override
     public byte[] serialize( Boolean element )
     {
         byte[] bytes = new byte[1];
@@ -123,6 +124,7 @@ public class BooleanSerializer extends A
      * @param in The byte array containing the boolean
      * @return A boolean
      */
+    @Override
     public Boolean fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -136,6 +138,7 @@ public class BooleanSerializer extends A
      * @param start the position in the byte[] we will deserialize the boolean from
      * @return A boolean
      */
+    @Override
     public Boolean fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 1 + start ) )
@@ -150,6 +153,7 @@ public class BooleanSerializer extends A
     /**
      * {@inheritDoc}
      */
+    @Override
     public Boolean deserialize( ByteBuffer buffer ) throws IOException
     {
         return buffer.get() != 0x00;

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteArraySerializer.java Fri Feb 24 07:16:37 2017
@@ -61,16 +61,16 @@ public class ByteArraySerializer extends
      */
     public byte[] serialize( byte[] element )
     {
-        int len = -1;
+        int nbBytes = -1;
 
         if ( element != null )
         {
-            len = element.length;
+            nbBytes = element.length;
         }
 
-        byte[] bytes = null;
+        byte[] bytes;
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 bytes = new byte[4];
@@ -93,14 +93,14 @@ public class ByteArraySerializer extends
                 break;
 
             default:
-                bytes = new byte[len + 4];
+                bytes = new byte[nbBytes + 4];
 
-                System.arraycopy( element, 0, bytes, 4, len );
+                System.arraycopy( element, 0, bytes, 4, nbBytes );
 
-                bytes[0] = ( byte ) ( len >>> 24 );
-                bytes[1] = ( byte ) ( len >>> 16 );
-                bytes[2] = ( byte ) ( len >>> 8 );
-                bytes[3] = ( byte ) ( len );
+                bytes[0] = ( byte ) ( nbBytes >>> 24 );
+                bytes[1] = ( byte ) ( nbBytes >>> 16 );
+                bytes[2] = ( byte ) ( nbBytes >>> 8 );
+                bytes[3] = ( byte ) ( nbBytes );
         }
 
         return bytes;
@@ -117,14 +117,14 @@ public class ByteArraySerializer extends
      */
     public static byte[] serialize( byte[] buffer, int start, byte[] element )
     {
-        int len = -1;
+        int nbBytes = -1;
 
         if ( element != null )
         {
-            len = element.length;
+            nbBytes = element.length;
         }
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 buffer[start] = 0x00;
@@ -144,12 +144,12 @@ public class ByteArraySerializer extends
 
             default:
 
-                buffer[start] = ( byte ) ( len >>> 24 );
-                buffer[start + 1] = ( byte ) ( len >>> 16 );
-                buffer[start + 2] = ( byte ) ( len >>> 8 );
-                buffer[start + 3] = ( byte ) ( len );
+                buffer[start] = ( byte ) ( nbBytes >>> 24 );
+                buffer[start + 1] = ( byte ) ( nbBytes >>> 16 );
+                buffer[start + 2] = ( byte ) ( nbBytes >>> 8 );
+                buffer[start + 3] = ( byte ) ( nbBytes );
 
-                System.arraycopy( element, 0, buffer, 4 + start, len );
+                System.arraycopy( element, 0, buffer, 4 + start, nbBytes );
         }
 
         return buffer;
@@ -170,9 +170,9 @@ public class ByteArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in );
+        int nbBytes = IntSerializer.deserialize( in );
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 return new byte[]
@@ -182,8 +182,8 @@ public class ByteArraySerializer extends
                 return null;
 
             default:
-                byte[] result = new byte[len];
-                System.arraycopy( in, 4, result, 0, len );
+                byte[] result = new byte[nbBytes];
+                System.arraycopy( in, 4, result, 0, nbBytes );
 
                 return result;
         }
@@ -204,9 +204,9 @@ public class ByteArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in, start );
+        int nbBytes = IntSerializer.deserialize( in, start );
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 return new byte[]
@@ -216,8 +216,8 @@ public class ByteArraySerializer extends
                 return null;
 
             default:
-                byte[] result = new byte[len];
-                System.arraycopy( in, 4 + start, result, 0, len );
+                byte[] result = new byte[nbBytes];
+                System.arraycopy( in, 4 + start, result, 0, nbBytes );
 
                 return result;
         }
@@ -230,6 +230,7 @@ public class ByteArraySerializer extends
      * @param in The byte array containing the byte array
      * @return A byte[]
      */
+    @Override
     public byte[] fromBytes( byte[] in )
     {
         if ( ( in == null ) || ( in.length < 4 ) )
@@ -237,9 +238,9 @@ public class ByteArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in );
+        int nbBytes = IntSerializer.deserialize( in );
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 return new byte[]
@@ -249,8 +250,8 @@ public class ByteArraySerializer extends
                 return null;
 
             default:
-                byte[] result = new byte[len];
-                System.arraycopy( in, 4, result, 0, len );
+                byte[] result = new byte[nbBytes];
+                System.arraycopy( in, 4, result, 0, nbBytes );
 
                 return result;
         }
@@ -264,6 +265,7 @@ public class ByteArraySerializer extends
      * @param start the position in the byte[] we will deserialize the byte[] from
      * @return A byte[]
      */
+    @Override
     public byte[] fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 4 + start ) )
@@ -271,9 +273,9 @@ public class ByteArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in, start );
+        int nbBytes = IntSerializer.deserialize( in, start );
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 return new byte[]
@@ -283,8 +285,8 @@ public class ByteArraySerializer extends
                 return null;
 
             default:
-                byte[] result = new byte[len];
-                System.arraycopy( in, 4 + start, result, 0, len );
+                byte[] result = new byte[nbBytes];
+                System.arraycopy( in, 4 + start, result, 0, nbBytes );
 
                 return result;
         }
@@ -294,13 +296,14 @@ public class ByteArraySerializer extends
     /**
      * {@inheritDoc}
      */
+    @Override
     public byte[] deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 4 );
 
-        int len = IntSerializer.deserialize( in );
+        int nbBytes = IntSerializer.deserialize( in );
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 return new byte[]
@@ -310,7 +313,7 @@ public class ByteArraySerializer extends
                 return null;
 
             default:
-                in = bufferHandler.read( len );
+                in = bufferHandler.read( nbBytes );
 
                 return in;
         }
@@ -320,11 +323,12 @@ public class ByteArraySerializer extends
     /**
      * {@inheritDoc}
      */
+    @Override
     public byte[] deserialize( ByteBuffer buffer ) throws IOException
     {
-        int len = buffer.getInt();
+        int nbBytes = buffer.getInt();
 
-        switch ( len )
+        switch ( nbBytes )
         {
             case 0:
                 return new byte[]
@@ -334,7 +338,7 @@ public class ByteArraySerializer extends
                 return null;
 
             default:
-                byte[] bytes = new byte[len];
+                byte[] bytes = new byte[nbBytes];
 
                 buffer.get( bytes );
 

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ByteSerializer.java Fri Feb 24 07:16:37 2017
@@ -120,6 +120,7 @@ public class ByteSerializer extends Abst
      * @param in The byte array containing the Byte
      * @return A Byte
      */
+    @Override
     public Byte fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -132,6 +133,7 @@ public class ByteSerializer extends Abst
      * @param start the position in the byte[] we will deserialize the byte from
      * @return A Byte
      */
+    @Override
     public Byte fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 1 + start ) )
@@ -146,6 +148,7 @@ public class ByteSerializer extends Abst
     /**
      * {@inheritDoc}
      */
+    @Override
     public Byte deserialize( ByteBuffer buffer ) throws IOException
     {
         return buffer.get();
@@ -155,6 +158,7 @@ public class ByteSerializer extends Abst
     /**
      * {@inheritDoc}
      */
+    @Override
     public Byte deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 1 );

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharArraySerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharArraySerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharArraySerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharArraySerializer.java Fri Feb 24 07:16:37 2017
@@ -51,16 +51,16 @@ public class CharArraySerializer extends
      */
     public byte[] serialize( char[] element )
     {
-        int len = -1;
+        int nbChars = -1;
 
         if ( element != null )
         {
-            len = element.length;
+            nbChars = element.length;
         }
 
-        byte[] bytes = null;
+        byte[] bytes;
 
-        switch ( len )
+        switch ( nbChars )
         {
             case 0:
                 bytes = new byte[4];
@@ -83,13 +83,13 @@ public class CharArraySerializer extends
                 break;
 
             default:
-                bytes = new byte[len * 2 + 4];
+                bytes = new byte[nbChars * 2 + 4];
                 int pos = 4;
 
-                bytes[0] = ( byte ) ( len >>> 24 );
-                bytes[1] = ( byte ) ( len >>> 16 );
-                bytes[2] = ( byte ) ( len >>> 8 );
-                bytes[3] = ( byte ) ( len );
+                bytes[0] = ( byte ) ( nbChars >>> 24 );
+                bytes[1] = ( byte ) ( nbChars >>> 16 );
+                bytes[2] = ( byte ) ( nbChars >>> 8 );
+                bytes[3] = ( byte ) ( nbChars );
 
                 for ( char c : element )
                 {
@@ -115,9 +115,9 @@ public class CharArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in );
+        int nbChars = IntSerializer.deserialize( in );
 
-        switch ( len )
+        switch ( nbChars )
         {
             case 0:
                 return new char[]
@@ -127,12 +127,11 @@ public class CharArraySerializer extends
                 return null;
 
             default:
-                char[] result = new char[len];
+                char[] result = new char[nbChars];
 
-                for ( int i = 4; i < len * 2 + 4; i += 2 )
+                for ( int i = 4; i < nbChars * 2 + 4; i += 2 )
                 {
-                    result[i] = Character.valueOf( ( char ) ( ( in[i] << 8 ) +
-                        ( in[i + 1] & 0xFF ) ) );
+                    result[i] = ( char ) ( ( in[i] << 8 ) + ( in[i + 1] & 0xFF ) );
                 }
 
                 return result;
@@ -146,6 +145,7 @@ public class CharArraySerializer extends
      * @param in The byte array containing the char array
      * @return A char[]
      */
+    @Override
     public char[] fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length - start < 4 ) )
@@ -153,9 +153,9 @@ public class CharArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in, start );
+        int nbChars = IntSerializer.deserialize( in, start );
 
-        switch ( len )
+        switch ( nbChars )
         {
             case 0:
                 return new char[]
@@ -165,12 +165,11 @@ public class CharArraySerializer extends
                 return null;
 
             default:
-                char[] result = new char[len];
+                char[] result = new char[nbChars];
 
-                for ( int i = 4; i < len * 2 + 4; i += 2 )
+                for ( int i = 4; i < nbChars * 2 + 4; i += 2 )
                 {
-                    result[i] = Character.valueOf( ( char ) ( ( in[i] << 8 ) +
-                        ( in[i + 1] & 0xFF ) ) );
+                    result[i] = ( char ) ( ( in[i] << 8 ) + ( in[i + 1] & 0xFF ) );
                 }
 
                 return result;
@@ -184,6 +183,7 @@ public class CharArraySerializer extends
      * @param in The byte array containing the char array
      * @return A char[]
      */
+    @Override
     public char[] fromBytes( byte[] in )
     {
         if ( ( in == null ) || ( in.length < 4 ) )
@@ -191,9 +191,9 @@ public class CharArraySerializer extends
             throw new SerializerCreationException( "Cannot extract a byte[] from a buffer with not enough bytes" );
         }
 
-        int len = IntSerializer.deserialize( in );
+        int nbChars = IntSerializer.deserialize( in );
 
-        switch ( len )
+        switch ( nbChars )
         {
             case 0:
                 return new char[]
@@ -203,12 +203,11 @@ public class CharArraySerializer extends
                 return null;
 
             default:
-                char[] result = new char[len];
+                char[] result = new char[nbChars];
 
-                for ( int i = 4; i < len * 2 + 4; i += 2 )
+                for ( int i = 4; i < nbChars * 2 + 4; i += 2 )
                 {
-                    result[i] = Character.valueOf( ( char ) ( ( in[i] << 8 ) +
-                        ( in[i + 1] & 0xFF ) ) );
+                    result[i] = ( char ) ( ( in[i] << 8 ) + ( in[i + 1] & 0xFF ) );
                 }
 
                 return result;
@@ -219,13 +218,14 @@ public class CharArraySerializer extends
     /**
      * {@inheritDoc}
      */
+    @Override
     public char[] deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 4 );
 
-        int len = IntSerializer.deserialize( in );
+        int nbChars = IntSerializer.deserialize( in );
 
-        switch ( len )
+        switch ( nbChars )
         {
             case 0:
                 return new char[]
@@ -235,13 +235,12 @@ public class CharArraySerializer extends
                 return null;
 
             default:
-                char[] result = new char[len];
-                byte[] buffer = bufferHandler.read( len * 2 );
+                char[] result = new char[nbChars];
+                byte[] buffer = bufferHandler.read( nbChars * 2 );
 
-                for ( int i = 0; i < len * 2; i += 2 )
+                for ( int i = 0; i < nbChars * 2; i += 2 )
                 {
-                    result[i] = Character.valueOf( ( char ) ( ( buffer[i] << 8 ) +
-                        ( buffer[i + 1] & 0xFF ) ) );
+                    result[i] = ( char ) ( ( buffer[i] << 8 ) + ( buffer[i + 1] & 0xFF ) );
                 }
 
                 return result;
@@ -252,11 +251,12 @@ public class CharArraySerializer extends
     /**
      * {@inheritDoc}
      */
+    @Override
     public char[] deserialize( ByteBuffer buffer ) throws IOException
     {
-        int len = buffer.getInt();
+        int nbChars = buffer.getInt();
 
-        switch ( len )
+        switch ( nbChars )
         {
             case 0:
                 return new char[]
@@ -266,9 +266,9 @@ public class CharArraySerializer extends
                 return null;
 
             default:
-                char[] result = new char[len];
+                char[] result = new char[nbChars];
 
-                for ( int i = 0; i < len; i++ )
+                for ( int i = 0; i < nbChars; i++ )
                 {
                     result[i] = buffer.getChar();
                 }

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/CharSerializer.java Fri Feb 24 07:16:37 2017
@@ -122,6 +122,7 @@ public class CharSerializer extends Abst
      * @param in The byte array containing the Character
      * @return A Character
      */
+    @Override
     public Character fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -131,9 +132,10 @@ public class CharSerializer extends Abst
     /**
      * A static method used to deserialize a Character from a byte array.
      * @param in The byte array containing the Character
-    * @param start the position in the byte[] we will deserialize the char from
+     * @param start the position in the byte[] we will deserialize the char from
      * @return A Character
      */
+    @Override
     public Character fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 2 + start ) )
@@ -149,6 +151,7 @@ public class CharSerializer extends Abst
     /**
      * {@inheritDoc}
      */
+    @Override
     public Character deserialize( ByteBuffer buffer ) throws IOException
     {
         return buffer.getChar();
@@ -158,6 +161,7 @@ public class CharSerializer extends Abst
     /**
      * {@inheritDoc}
      */
+    @Override
     public Character deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 2 );

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/IntSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/IntSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/IntSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/IntSerializer.java Fri Feb 24 07:16:37 2017
@@ -82,6 +82,7 @@ public class IntSerializer extends Abstr
      * @param in The byte array containing the Integer
      * @return An Integer
      */
+    @Override
     public Integer fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -94,6 +95,7 @@ public class IntSerializer extends Abstr
      * @param start the position in the byte[] we will deserialize the int from
      * @return An Integer
      */
+    @Override
     public Integer fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 4 + start ) )
@@ -111,6 +113,7 @@ public class IntSerializer extends Abstr
     /**
      * {@inheritDoc}
      */
+    @Override
     public Integer deserialize( ByteBuffer buffer ) throws IOException
     {
         return buffer.getInt();
@@ -120,6 +123,7 @@ public class IntSerializer extends Abstr
     /**
      * {@inheritDoc}
      */
+    @Override
     public Integer deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 4 );

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongArraySerializer.java Fri Feb 24 07:16:37 2017
@@ -50,17 +50,17 @@ public class LongArraySerializer extends
      */
     public byte[] serialize( long[] element )
     {
-        int len = -1;
+        int nbLongs = -1;
 
         if ( element != null )
         {
-            len = element.length;
+            nbLongs = element.length;
         }
 
-        byte[] bytes = null;
+        byte[] bytes;
         int pos = 0;
 
-        switch ( len )
+        switch ( nbLongs )
         {
             case 0:
                 bytes = new byte[4];
@@ -69,7 +69,7 @@ public class LongArraySerializer extends
                 bytes[pos++] = 0x00;
                 bytes[pos++] = 0x00;
                 bytes[pos++] = 0x00;
-                bytes[pos++] = 0x00;
+                bytes[pos] = 0x00;
 
                 break;
 
@@ -80,19 +80,19 @@ public class LongArraySerializer extends
                 bytes[pos++] = ( byte ) 0xFF;
                 bytes[pos++] = ( byte ) 0xFF;
                 bytes[pos++] = ( byte ) 0xFF;
-                bytes[pos++] = ( byte ) 0xFF;
+                bytes[pos] = ( byte ) 0xFF;
 
                 break;
 
             default:
-                int dataLen = len * 8 + 4;
+                int dataLen = nbLongs * 8 + 4;
                 bytes = new byte[dataLen];
 
                 // The number of longs
-                bytes[pos++] = ( byte ) ( len >>> 24 );
-                bytes[pos++] = ( byte ) ( len >>> 16 );
-                bytes[pos++] = ( byte ) ( len >>> 8 );
-                bytes[pos++] = ( byte ) ( len );
+                bytes[pos++] = ( byte ) ( nbLongs >>> 24 );
+                bytes[pos++] = ( byte ) ( nbLongs >>> 16 );
+                bytes[pos++] = ( byte ) ( nbLongs >>> 8 );
+                bytes[pos++] = ( byte ) ( nbLongs );
 
                 // Serialize the longs now
                 for ( long value : element )
@@ -115,15 +115,11 @@ public class LongArraySerializer extends
     /**
      * {@inheritDoc}
      */
+    @Override
     public long[] deserialize( BufferHandler bufferHandler ) throws IOException
     {
-        // Read the DataLength first. Note that we don't use it here.
-        byte[] in = bufferHandler.read( 4 );
-
-        IntSerializer.deserialize( in );
-
         // Now, read the number of Longs
-        in = bufferHandler.read( 4 );
+        byte[] in = bufferHandler.read( 4 );
 
         int nbLongs = IntSerializer.deserialize( in );
 
@@ -162,11 +158,9 @@ public class LongArraySerializer extends
     /**
      * {@inheritDoc}
      */
+    @Override
     public long[] deserialize( ByteBuffer buffer ) throws IOException
     {
-        // Read the dataLength. Note that we don't use it here.
-        buffer.getInt();
-        
         // The number of longs
         int nbLongs = buffer.getInt();
 
@@ -275,13 +269,16 @@ public class LongArraySerializer extends
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public long[] fromBytes( byte[] buffer ) throws IOException
     {
-        int len = IntSerializer.deserialize( buffer );
+        int nbLongs = IntSerializer.deserialize( buffer );
         int pos = 4;
 
-        switch ( len )
+        switch ( nbLongs )
         {
             case 0:
                 return new long[]
@@ -291,9 +288,9 @@ public class LongArraySerializer extends
                 return null;
 
             default:
-                long[] longs = new long[len];
+                long[] longs = new long[nbLongs];
 
-                for ( int i = 0; i < len; i++ )
+                for ( int i = 0; i < nbLongs; i++ )
                 {
                     longs[i] = LongSerializer.deserialize( buffer, pos );
                     pos += 8;
@@ -304,13 +301,16 @@ public class LongArraySerializer extends
     }
 
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public long[] fromBytes( byte[] buffer, int pos ) throws IOException
     {
-        int len = IntSerializer.deserialize( buffer, pos );
+        int nbLongs = IntSerializer.deserialize( buffer, pos );
         int newPos = pos + 4;
 
-        switch ( len )
+        switch ( nbLongs )
         {
             case 0:
                 return new long[]
@@ -320,9 +320,9 @@ public class LongArraySerializer extends
                 return null;
 
             default:
-                long[] longs = new long[len];
+                long[] longs = new long[nbLongs];
 
-                for ( int i = 0; i < len; i++ )
+                for ( int i = 0; i < nbLongs; i++ )
                 {
                     longs[i] = LongSerializer.deserialize( buffer, newPos );
                     newPos += 8;

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/LongSerializer.java Fri Feb 24 07:16:37 2017
@@ -35,7 +35,7 @@ import org.apache.directory.mavibot.btre
 public class LongSerializer extends AbstractElementSerializer<Long>
 {
     /** A static instance of a LongSerializer */
-    public final static LongSerializer INSTANCE = new LongSerializer();
+    public static final LongSerializer INSTANCE = new LongSerializer();
 
     /**
      * Create a new instance of LongSerializer
@@ -117,7 +117,7 @@ public class LongSerializer extends Abst
             throw new SerializerCreationException( "Cannot extract a Long from a buffer with not enough bytes" );
         }
 
-        long result = ( ( long ) in[start] << 56 ) +
+        return ( ( long ) in[start] << 56 ) +
             ( ( in[start + 1] & 0x00FFL ) << 48 ) +
             ( ( in[start + 2] & 0x00FFL ) << 40 ) +
             ( ( in[start + 3] & 0x00FFL ) << 32 ) +
@@ -125,8 +125,6 @@ public class LongSerializer extends Abst
             ( ( in[start + 5] & 0x00FFL ) << 16 ) +
             ( ( in[start + 6] & 0x00FFL ) << 8 ) +
             ( in[start + 7] & 0x00FFL );
-
-        return result;
     }
 
 
@@ -136,6 +134,7 @@ public class LongSerializer extends Abst
      * @param start the position in the byte[] we will deserialize the long from
      * @return A Long
      */
+    @Override
     public Long fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -148,6 +147,7 @@ public class LongSerializer extends Abst
      * @param start the position in the byte[] we will deserialize the long from
      * @return An Integer
      */
+    @Override
     public Long fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 8 + start ) )
@@ -155,7 +155,7 @@ public class LongSerializer extends Abst
             throw new SerializerCreationException( "Cannot extract a Long from a buffer with not enough bytes" );
         }
 
-        long result = ( ( long ) in[start] << 56 ) +
+        return ( ( long ) in[start] << 56 ) +
             ( ( in[start + 1] & 0xFFL ) << 48 ) +
             ( ( in[start + 2] & 0xFFL ) << 40 ) +
             ( ( in[start + 3] & 0xFFL ) << 32 ) +
@@ -163,14 +163,13 @@ public class LongSerializer extends Abst
             ( ( in[start + 5] & 0xFFL ) << 16 ) +
             ( ( in[start + 6] & 0xFFL ) << 8 ) +
             ( in[start + 7] & 0xFFL );
-
-        return result;
     }
 
 
     /**
      * {@inheritDoc}
      */
+    @Override
     public Long deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 8 );
@@ -182,6 +181,7 @@ public class LongSerializer extends Abst
     /**
      * {@inheritDoc}
      */
+    @Override
     public Long deserialize( ByteBuffer buffer ) throws IOException
     {
         return buffer.getLong();

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ShortSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ShortSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ShortSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/ShortSerializer.java Fri Feb 24 07:16:37 2017
@@ -121,6 +121,7 @@ public class ShortSerializer extends Abs
      * @param in The byte array containing the Short
      * @return A Short
      */
+    @Override
     public Short fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -133,6 +134,7 @@ public class ShortSerializer extends Abs
      * @param start the position in the byte[] we will deserialize the short from
      * @return A Short
      */
+    @Override
     public Short fromBytes( byte[] in, int start )
     {
         if ( ( in == null ) || ( in.length < 2 + start ) )
@@ -147,6 +149,7 @@ public class ShortSerializer extends Abs
     /**
      * {@inheritDoc}
      */
+    @Override
     public Short deserialize( ByteBuffer buffer ) throws IOException
     {
         return buffer.getShort();
@@ -156,6 +159,7 @@ public class ShortSerializer extends Abs
     /**
      * {@inheritDoc}
      */
+    @Override
     public Short deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 2 );

Modified: directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java
URL: http://svn.apache.org/viewvc/directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java?rev=1784232&r1=1784231&r2=1784232&view=diff
==============================================================================
--- directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java (original)
+++ directory/mavibot/branches/single-value/mavibot/src/main/java/org/apache/directory/mavibot/btree/serializer/StringSerializer.java Fri Feb 24 07:16:37 2017
@@ -97,6 +97,7 @@ public class StringSerializer extends Ab
      * @param in The byte array containing the String
      * @return A String
      */
+    @Override
     public String fromBytes( byte[] in )
     {
         return deserialize( in, 0 );
@@ -108,6 +109,7 @@ public class StringSerializer extends Ab
      * @param in The byte array containing the String
      * @return A String
      */
+    @Override
     public String fromBytes( byte[] in, int start )
     {
         int length = IntSerializer.deserialize( in, start );
@@ -134,13 +136,13 @@ public class StringSerializer extends Ab
      * @param value the value to serialize
      * @return The byte[] containing the serialized String
      */
-    public static byte[] serialize( byte[] buffer, int start, String element )
+    public static byte[] serialize( byte[] buffer, int start, String string )
     {
         int len = -1;
 
-        if ( element != null )
+        if ( string != null )
         {
-            len = element.length();
+            len = string.length();
         }
 
         switch ( len )
@@ -164,7 +166,7 @@ public class StringSerializer extends Ab
             default:
                 try
                 {
-                    byte[] strBytes = element.getBytes( "UTF-8" );
+                    byte[] strBytes = string.getBytes( "UTF-8" );
 
                     buffer = new byte[strBytes.length + 4];
 
@@ -189,16 +191,16 @@ public class StringSerializer extends Ab
     /**
      * {@inheritDoc}
      */
-    public byte[] serialize( String element )
+    public byte[] serialize( String string )
     {
         int len = -1;
 
-        if ( element != null )
+        if ( string != null )
         {
-            len = element.length();
+            len = string.length();
         }
 
-        byte[] bytes = null;
+        byte[] bytes;
 
         switch ( len )
         {
@@ -223,11 +225,10 @@ public class StringSerializer extends Ab
                 break;
 
             default:
-                char[] chars = element.toCharArray();
+                char[] chars = string.toCharArray();
                 byte[] tmpBytes = new byte[chars.length * 2];
 
                 int pos = 0;
-                len = 0;
 
                 for ( char c : chars )
                 {
@@ -266,6 +267,7 @@ public class StringSerializer extends Ab
      * {@inheritDoc}
      * @throws IOException
      */
+    @Override
     public String deserialize( BufferHandler bufferHandler ) throws IOException
     {
         byte[] in = bufferHandler.read( 4 );
@@ -291,6 +293,7 @@ public class StringSerializer extends Ab
     /**
      * {@inheritDoc}
      */
+    @Override
     public String deserialize( ByteBuffer buffer ) throws IOException
     {
         int len = buffer.getInt();
@@ -357,14 +360,7 @@ public class StringSerializer extends Ab
 
         if ( type1 == null )
         {
-            if ( type2 == null )
-            {
-                return 0;
-            }
-            else
-            {
-                return -1;
-            }
+            return -1;
         }
         else
         {



Mime
View raw message