Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1FE4A1022D for ; Tue, 13 Aug 2013 15:44:36 +0000 (UTC) Received: (qmail 66683 invoked by uid 500); 13 Aug 2013 15:44:17 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66614 invoked by uid 500); 13 Aug 2013 15:44:17 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 66360 invoked by uid 99); 13 Aug 2013 15:44:16 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Aug 2013 15:44:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Aug 2013 15:44:07 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C62322388CBE for ; Tue, 13 Aug 2013 15:42:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r874484 [44/45] - in /websites/production/directory/content/mavibot/gen-docs: ./ 1.0.0-M1/ 1.0.0-M1/apidocs/ 1.0.0-M1/apidocs/org/ 1.0.0-M1/apidocs/org/apache/ 1.0.0-M1/apidocs/org/apache/directory/ 1.0.0-M1/apidocs/org/apache/directory/mav... Date: Tue, 13 Aug 2013 15:42:17 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20130813154231.C62322388CBE@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/StringSerializer.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/StringSerializer.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/StringSerializer.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,359 @@ + + + + +StringSerializer xref + + + +
+
+1   /*
+2    *  Licensed to the Apache Software Foundation (ASF) under one
+3    *  or more contributor license agreements.  See the NOTICE file
+4    *  distributed with this work for additional information
+5    *  regarding copyright ownership.  The ASF licenses this file
+6    *  to you under the Apache License, Version 2.0 (the
+7    *  "License"); you may not use this file except in compliance
+8    *  with the License.  You may obtain a copy of the License at
+9    *
+10   *    http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   *  Unless required by applicable law or agreed to in writing,
+13   *  software distributed under the License is distributed on an
+14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   *  KIND, either express or implied.  See the License for the
+16   *  specific language governing permissions and limitations
+17   *  under the License.
+18   *
+19   */
+20  package org.apache.directory.mavibot.btree.serializer;
+21  
+22  
+23  import java.io.IOException;
+24  import java.io.UnsupportedEncodingException;
+25  import java.nio.ByteBuffer;
+26  import java.util.Comparator;
+27  
+28  import org.apache.directory.mavibot.btree.comparator.StringComparator;
+29  import org.apache.directory.mavibot.btree.util.Strings;
+30  
+31  
+32  /**
+33   * The String serializer.
+34   * 
+35   * @author <a href="mailto:labs@labs.apache.org">Mavibot labs Project</a>
+36   */
+37  public class StringSerializer extends AbstractElementSerializer<String>
+38  {
+39      public static final StringSerializer INSTANCE = new StringSerializer();
+40      
+41      /**
+42       * Create a new instance of StringSerializer
+43       */
+44      public StringSerializer()
+45      {
+46          super( new StringComparator() );
+47      }
+48  
+49  
+50      /**
+51       * Create a new instance of StringSerializer with custom comparator
+52       */
+53      public StringSerializer( Comparator comparator )
+54      {
+55          super( comparator );
+56      }
+57  
+58      
+59      /**
+60       * A static method used to deserialize a String from a byte array.
+61       * @param in The byte array containing the String
+62       * @return A String
+63       */
+64      public static String deserialize( byte[] in )
+65      {
+66          return deserialize( in, 0 );
+67      }
+68  
+69  
+70      /**
+71       * A static method used to deserialize a String from a byte array.
+72       * @param in The byte array containing the String
+73       * @return A String
+74       */
+75      public static String deserialize( byte[] in, int start )
+76      {
+77          int length = IntSerializer.deserialize( in, start );
+78  
+79          if ( length == 0xFFFFFFFF )
+80          {
+81              return null;
+82          }
+83  
+84          if ( in.length < length + 4 + start )
+85          {
+86              throw new RuntimeException( "Cannot extract a String from a buffer with not enough bytes" );
+87          }
+88  
+89          return Strings.utf8ToString( in, start + 4, length );
+90      }
+91  
+92  
+93      /**
+94       * Serialize a String. We store the length on 4 bytes, then the String
+95       * 
+96       * @param buffer the Buffer that will contain the serialized value
+97       * @param start the position in the buffer we will store the serialized String
+98       * @param value the value to serialize
+99       * @return The byte[] containing the serialized String
+100      */
+101     public static byte[] serialize( byte[] buffer, int start, String element )
+102     {
+103         int len = -1;
+104 
+105         if ( element != null )
+106         {
+107             len = element.length();
+108         }
+109 
+110         switch ( len )
+111         {
+112             case 0:
+113                 buffer[start] = 0x00;
+114                 buffer[start + 1] = 0x00;
+115                 buffer[start + 2] = 0x00;
+116                 buffer[start + 3] = 0x00;
+117 
+118                 break;
+119 
+120             case -1:
+121                 buffer[start] = ( byte ) 0xFF;
+122                 buffer[start + 1] = ( byte ) 0xFF;
+123                 buffer[start + 2] = ( byte ) 0xFF;
+124                 buffer[start + 3] = ( byte ) 0xFF;
+125 
+126                 break;
+127 
+128             default:
+129                 try
+130                 {
+131                     byte[] strBytes = element.getBytes( "UTF-8" );
+132 
+133                     buffer = new byte[strBytes.length + 4];
+134 
+135                     System.arraycopy( strBytes, 0, buffer, 4, strBytes.length );
+136 
+137                     buffer[start] = ( byte ) ( strBytes.length >>> 24 );
+138                     buffer[start + 1] = ( byte ) ( strBytes.length >>> 16 );
+139                     buffer[start + 2] = ( byte ) ( strBytes.length >>> 8 );
+140                     buffer[start + 3] = ( byte ) ( strBytes.length );
+141                 }
+142                 catch ( UnsupportedEncodingException uee )
+143                 {
+144                     // if this happens something is really strange
+145                     throw new RuntimeException( uee );
+146                 }
+147         }
+148 
+149         return buffer;
+150     }
+151 
+152 
+153     /**
+154      * {@inheritDoc}
+155      */
+156     public byte[] serialize( String element )
+157     {
+158         int len = -1;
+159 
+160         if ( element != null )
+161         {
+162             len = element.length();
+163         }
+164 
+165         byte[] bytes = null;
+166 
+167         switch ( len )
+168         {
+169             case 0:
+170                 bytes = new byte[4];
+171 
+172                 bytes[0] = 0x00;
+173                 bytes[1] = 0x00;
+174                 bytes[2] = 0x00;
+175                 bytes[3] = 0x00;
+176 
+177                 break;
+178 
+179             case -1:
+180                 bytes = new byte[4];
+181 
+182                 bytes[0] = ( byte ) 0xFF;
+183                 bytes[1] = ( byte ) 0xFF;
+184                 bytes[2] = ( byte ) 0xFF;
+185                 bytes[3] = ( byte ) 0xFF;
+186 
+187                 break;
+188 
+189             default:
+190                 char[] chars = element.toCharArray();
+191                 byte[] tmpBytes = new byte[chars.length * 2];
+192 
+193                 int pos = 0;
+194                 len = 0;
+195 
+196                 for ( char c : chars )
+197                 {
+198                     if ( ( c & 0xFF80 ) == 0 )
+199                     {
+200                         tmpBytes[pos++] = ( byte ) c;
+201                     }
+202                     else if ( ( c & 0xF800 ) == 0 )
+203                     {
+204                         tmpBytes[pos++] = ( byte ) ( ( byte ) 0x00C0 | ( byte ) ( ( c & 0x07C0 ) >> 6 ) );
+205                         tmpBytes[pos++] = ( byte ) ( ( byte ) 0x80 | ( byte ) ( c & 0x003F ) );
+206                     }
+207                     else
+208                     {
+209                         tmpBytes[pos++] = ( byte ) ( ( byte ) 0x80 | ( byte ) ( c & 0x001F ) );
+210                         tmpBytes[pos++] = ( byte ) ( ( byte ) 0x80 | ( byte ) ( c & 0x07C0 ) );
+211                         tmpBytes[pos++] = ( byte ) ( ( byte ) 0xE0 | ( byte ) ( c & 0x7800 ) );
+212                     }
+213                 }
+214 
+215                 bytes = new byte[pos + 4];
+216 
+217                 bytes[0] = ( byte ) ( pos >>> 24 );
+218                 bytes[1] = ( byte ) ( pos >>> 16 );
+219                 bytes[2] = ( byte ) ( pos >>> 8 );
+220                 bytes[3] = ( byte ) ( pos );
+221 
+222                 System.arraycopy( tmpBytes, 0, bytes, 4, pos );
+223         }
+224 
+225         return bytes;
+226     }
+227 
+228 
+229     /**
+230      * {@inheritDoc}
+231      * @throws IOException 
+232      */
+233     public String deserialize( BufferHandler bufferHandler ) throws IOException
+234     {
+235         byte[] in = bufferHandler.read( 4 );
+236 
+237         int len = IntSerializer.deserialize( in );
+238 
+239         switch ( len )
+240         {
+241             case 0:
+242                 return "";
+243 
+244             case -1:
+245                 return null;
+246 
+247             default:
+248                 in = bufferHandler.read( len );
+249 
+250                 return Strings.utf8ToString( in );
+251         }
+252     }
+253 
+254 
+255     /**
+256      * {@inheritDoc}
+257      */
+258     public String deserialize( ByteBuffer buffer ) throws IOException
+259     {
+260         int len = buffer.getInt();
+261 
+262         switch ( len )
+263         {
+264             case 0:
+265                 return "";
+266 
+267             case -1:
+268                 return null;
+269 
+270             default:
+271                 byte[] bytes = new byte[len];
+272 
+273                 buffer.get( bytes );
+274                 char[] chars = new char[len];
+275                 int clen = 0;
+276 
+277                 for ( int i = 0; i < len; i++ )
+278                 {
+279                     byte b = bytes[i];
+280 
+281                     if ( b >= 0 )
+282                     {
+283                         chars[clen++] = ( char ) b;
+284                     }
+285                     else
+286                     {
+287                         if ( ( b & 0xE0 ) == 0 )
+288                         {
+289                             // 3 bytes long char
+290                             i++;
+291                             byte b2 = bytes[i];
+292                             i++;
+293                             byte b3 = bytes[i];
+294                             chars[clen++] = ( char ) ( ( ( b & 0x000F ) << 12 ) | ( ( b2 & 0x003F ) << 6 ) | ( ( b3 & 0x003F ) ) );
+295                         }
+296                         else
+297                         {
+298                             // 2 bytes long char
+299                             i++;
+300                             byte b2 = bytes[i];
+301                             chars[clen++] = ( char ) ( ( ( b & 0x001F ) << 6 ) | ( b2 & 0x003F ) );
+302                         }
+303                     }
+304                 }
+305 
+306                 return new String( chars, 0, clen );
+307         }
+308     }
+309 
+310 
+311     /**
+312      * {@inheritDoc}
+313      */
+314     @Override
+315     public int compare( String type1, String type2 )
+316     {
+317         if ( type1 == type2 )
+318         {
+319             return 0;
+320         }
+321 
+322         if ( type1 == null )
+323         {
+324             if ( type2 == null )
+325             {
+326                 return 0;
+327             }
+328             else
+329             {
+330                 return -1;
+331             }
+332         }
+333         else
+334         {
+335             if ( type2 == null )
+336             {
+337                 return 1;
+338             }
+339             else
+340             {
+341                 return type1.compareTo( type2 );
+342             }
+343         }
+344     }
+345 }
+
+
+ + Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/package-frame.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/package-frame.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/package-frame.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,63 @@ + + + + + + ApacheDS MVCC BTree implementation 1.0.0-M1 Reference Package org.apache.directory.mavibot.btree.serializer + + + + +

+ org.apache.directory.mavibot.btree.serializer +

+ +

Classes

+ + + + + \ No newline at end of file Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/package-summary.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/package-summary.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/serializer/package-summary.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,132 @@ + + + + + + ApacheDS MVCC BTree implementation 1.0.0-M1 Reference Package org.apache.directory.mavibot.btree.serializer + + + +
+ +
+
+ +
+ +

Package org.apache.directory.mavibot.btree.serializer

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Class Summary
+ AbstractElementSerializer +
+ BooleanSerializer +
+ BufferHandler +
+ ByteArraySerializer +
+ ByteSerializer +
+ CharArraySerializer +
+ CharSerializer +
+ ElementSerializer +
+ IntSerializer +
+ LongArraySerializer +
+ LongSerializer +
+ Serializer +
+ ShortSerializer +
+ StringSerializer +
+ +
+ +
+
+ +
+
+ Copyright © 2012-2013 Apache Mavibot Project Parent. All Rights Reserved. + + \ No newline at end of file Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/util/BulkDataSorter.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/util/BulkDataSorter.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/util/BulkDataSorter.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,287 @@ + + + + +BulkDataSorter xref + + + +
+
+1   /*
+2    *   Licensed to the Apache Software Foundation (ASF) under one
+3    *   or more contributor license agreements.  See the NOTICE file
+4    *   distributed with this work for additional information
+5    *   regarding copyright ownership.  The ASF licenses this file
+6    *   to you under the Apache License, Version 2.0 (the
+7    *   "License"); you may not use this file except in compliance
+8    *   with the License.  You may obtain a copy of the License at
+9    *
+10   *     http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   *   Unless required by applicable law or agreed to in writing,
+13   *   software distributed under the License is distributed on an
+14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   *   KIND, either express or implied.  See the License for the
+16   *   specific language governing permissions and limitations
+17   *   under the License.
+18   *
+19   */
+20  package org.apache.directory.mavibot.btree.util;
+21  
+22  
+23  import java.io.DataInputStream;
+24  import java.io.DataOutputStream;
+25  import java.io.File;
+26  import java.io.FileInputStream;
+27  import java.io.FileOutputStream;
+28  import java.io.IOException;
+29  import java.lang.reflect.Array;
+30  import java.util.Arrays;
+31  import java.util.Collections;
+32  import java.util.Comparator;
+33  import java.util.Iterator;
+34  import java.util.NoSuchElementException;
+35  import java.util.UUID;
+36  
+37  import org.apache.directory.mavibot.btree.BTreeBuilder;
+38  import org.apache.directory.mavibot.btree.Tuple;
+39  
+40  
+41  /**
+42   * A utility class for sorting a large number of keys before building a BTree using {@link BTreeBuilder}.
+43   *
+44   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+45   */
+46  public class BulkDataSorter<K, V>
+47  {
+48      private File workDir;
+49  
+50      private int splitAfter = 1000;
+51  
+52      private Comparator<Tuple<K, V>> tupleComparator;
+53  
+54      private TupleReaderWriter<K, V> readerWriter;
+55  
+56      private boolean sorted;
+57  
+58  
+59      public BulkDataSorter( TupleReaderWriter<K, V> readerWriter, Comparator<Tuple<K, V>> tupleComparator,
+60          int splitAfter )
+61      {
+62          if ( splitAfter <= 0 )
+63          {
+64              throw new IllegalArgumentException( "Value of splitAfter parameter cannot be null" );
+65          }
+66  
+67          this.splitAfter = splitAfter;
+68  
+69          this.workDir = new File( System.getProperty( "java.io.tmpdir" ), System.currentTimeMillis() + "-sort" );
+70          workDir.mkdir();
+71  
+72          this.readerWriter = readerWriter;
+73          this.tupleComparator = tupleComparator;
+74      }
+75  
+76  
+77      public void sort( File dataFile ) throws IOException
+78      {
+79          int i = 0;
+80  
+81          Tuple<K, V>[] arr = ( Tuple<K, V>[] ) Array.newInstance( Tuple.class, splitAfter );
+82  
+83          Tuple<K, V> t = null;
+84  
+85          DataInputStream in = new DataInputStream( new FileInputStream( dataFile ) );
+86  
+87          while ( ( t = readerWriter.readTuple( in ) ) != null )
+88          {
+89              arr[i++] = t;
+90  
+91              if ( ( i % splitAfter ) == 0 )
+92              {
+93                  i = 0;
+94                  Arrays.sort( arr, tupleComparator );
+95  
+96                  storeSortedData( arr );
+97              }
+98          }
+99  
+100         if ( i != 0 )
+101         {
+102             Tuple<K, V>[] tmp = ( Tuple<K, V>[] ) Array.newInstance( Tuple.class, i );
+103             System.arraycopy( arr, 0, tmp, 0, i );
+104             Arrays.sort( tmp, tupleComparator );
+105 
+106             storeSortedData( tmp );
+107         }
+108 
+109         sorted = true;
+110     }
+111 
+112 
+113     private void storeSortedData( Tuple<K, V>[] arr ) throws IOException
+114     {
+115         File tempFile = File.createTempFile( UUID.randomUUID().toString(), ".batch", workDir );
+116         DataOutputStream out = new DataOutputStream( new FileOutputStream( tempFile ) );
+117 
+118         for ( Tuple<K, V> t : arr )
+119         {
+120             readerWriter.writeTuple( t, out );
+121         }
+122 
+123         out.flush();
+124         out.close();
+125     }
+126 
+127 
+128     public File getWorkDir()
+129     {
+130         return workDir;
+131     }
+132 
+133 
+134     public Iterator<Tuple<K, V>> getMergeSortedTuples() throws IOException
+135     {
+136         if ( !sorted )
+137         {
+138             throw new IllegalStateException( "Data is not sorted" );
+139         }
+140 
+141         File[] batches = workDir.listFiles();
+142 
+143         if ( batches.length == 0 )
+144         {
+145             return Collections.EMPTY_LIST.iterator();
+146         }
+147 
+148         final DataInputStream[] streams = new DataInputStream[batches.length];
+149 
+150         for ( int i = 0; i < batches.length; i++ )
+151         {
+152             streams[i] = new DataInputStream( new FileInputStream( batches[i] ) );
+153         }
+154 
+155         Iterator<Tuple<K, V>> itr = new Iterator<Tuple<K, V>>()
+156         {
+157             private Tuple<K, V>[] heads = ( Tuple<K, V>[] ) Array.newInstance( Tuple.class, streams.length );
+158 
+159             private Tuple<K, V> candidate = null;
+160 
+161             private boolean closed;
+162 
+163             private int candidatePos = -1;
+164 
+165 
+166             @Override
+167             public boolean hasNext()
+168             {
+169 
+170                 if ( closed )
+171                 {
+172                     throw new IllegalStateException( "No elements to read" );
+173                 }
+174 
+175                 Tuple<K, V> available = null;
+176 
+177                 for ( int i = 0; i < streams.length; i++ )
+178                 {
+179                     if ( heads[i] == null )
+180                     {
+181                         heads[i] = readerWriter.readTuple( streams[i] );
+182                     }
+183 
+184                     if ( available == null )
+185                     {
+186                         available = heads[i];
+187                         candidatePos = i;
+188                     }
+189                     else
+190                     {
+191                         if ( ( available != null ) && ( heads[i] != null ) )
+192                         {
+193                             int comp = tupleComparator.compare( heads[i], available );
+194                             if ( comp <= 0 )
+195                             {
+196                                 available = heads[i];
+197                                 candidatePos = i;
+198                             }
+199                         }
+200                     }
+201                 }
+202 
+203                 heads[candidatePos] = null;
+204 
+205                 if ( available == null )
+206                 {
+207                     for ( int i = 0; i < streams.length; i++ )
+208                     {
+209                         if ( heads[i] != null )
+210                         {
+211                             available = heads[i];
+212                             heads[i] = readerWriter.readTuple( streams[i] );
+213                             break;
+214                         }
+215                     }
+216                 }
+217 
+218                 if ( available != null )
+219                 {
+220                     candidate = available;
+221                     return true;
+222                 }
+223 
+224                 // finally close the streams
+225                 for ( DataInputStream in : streams )
+226                 {
+227                     try
+228                     {
+229                         in.close();
+230                     }
+231                     catch ( Exception e )
+232                     {
+233                         e.printStackTrace();
+234                     }
+235                 }
+236 
+237                 closed = true;
+238 
+239                 return false;
+240             }
+241 
+242 
+243             @Override
+244             public Tuple<K, V> next()
+245             {
+246                 if ( candidate == null )
+247                 {
+248                     if ( !closed )
+249                     {
+250                         hasNext();
+251                     }
+252                 }
+253 
+254                 if ( candidate == null )
+255                 {
+256                     throw new NoSuchElementException( "No tuples found" );
+257                 }
+258 
+259                 return candidate;
+260             }
+261 
+262 
+263             @Override
+264             public void remove()
+265             {
+266                 throw new UnsupportedOperationException( "Not supported" );
+267             }
+268 
+269         };
+270 
+271         return itr;
+272     }
+273 }
+
+
+ + Added: websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/util/IntTupleReaderWriter.html ============================================================================== --- websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/util/IntTupleReaderWriter.html (added) +++ websites/production/directory/content/mavibot/gen-docs/1.0.0-M1/xref/org/apache/directory/mavibot/btree/util/IntTupleReaderWriter.html Tue Aug 13 15:42:13 2013 @@ -0,0 +1,81 @@ + + + + +IntTupleReaderWriter xref + + + +
+
+1   /*
+2    *   Licensed to the Apache Software Foundation (ASF) under one
+3    *   or more contributor license agreements.  See the NOTICE file
+4    *   distributed with this work for additional information
+5    *   regarding copyright ownership.  The ASF licenses this file
+6    *   to you under the Apache License, Version 2.0 (the
+7    *   "License"); you may not use this file except in compliance
+8    *   with the License.  You may obtain a copy of the License at
+9    *
+10   *     http://www.apache.org/licenses/LICENSE-2.0
+11   *
+12   *   Unless required by applicable law or agreed to in writing,
+13   *   software distributed under the License is distributed on an
+14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+15   *   KIND, either express or implied.  See the License for the
+16   *   specific language governing permissions and limitations
+17   *   under the License.
+18   *
+19   */
+20  package org.apache.directory.mavibot.btree.util;
+21  
+22  
+23  import java.io.DataInputStream;
+24  import java.io.DataOutputStream;
+25  import java.io.IOException;
+26  
+27  import org.apache.directory.mavibot.btree.Tuple;
+28  
+29  
+30  /**
+31   * TODO IntTupleReaderWriter.
+32   *
+33   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+34   */
+35  public class IntTupleReaderWriter implements TupleReaderWriter<Integer, Integer>
+36  {
+37  
+38      @Override
+39      public void writeTuple( Tuple<Integer, Integer> t, DataOutputStream out ) throws IOException
+40      {
+41          out.writeInt( t.getKey() );
+42          out.writeInt( t.getValue() );
+43      }
+44  
+45  
+46      @Override
+47      public Tuple<Integer, Integer> readTuple( DataInputStream in )
+48      {
+49  
+50          try
+51          {
+52              if ( in.available() <= 0 )
+53              {
+54                  return null;
+55              }
+56  
+57              Tuple<Integer, Integer> t = new Tuple<Integer, Integer>( in.readInt(), in.readInt() );
+58  
+59              return t;
+60          }
+61          catch ( IOException e )
+62          {
+63          }
+64  
+65          return null;
+66      }
+67  }
+
+
+ +