org.apache.lucene.util.encoding
Class VInt8IntEncoder

java.lang.Object
  extended by org.apache.lucene.util.encoding.IntEncoder
      extended by org.apache.lucene.util.encoding.VInt8IntEncoder

public class VInt8IntEncoder
extends IntEncoder

An IntEncoder which implements variable length encoding. A number is encoded as follows:

Example:
  1. n = 117 = 01110101: This has less than 8 significant bits, therefore is encoded as 01110101 = 0x75.
  2. n = 100000 = (binary) 11000011010100000. This has 17 significant bits, thus needs three Vint8 bytes. Pad it to a multiple of 7 bits, then split it into chunks of 7 and add an MSB, 0 for the last byte, 1 for the others: 1|0000110 1|0001101 0|0100000 = 0x86 0x8D 0x20.
NOTE: although this encoder is not limited to values ≥ 0, it is not recommended for use with negative values, as their encoding will result in 5 bytes written to the output stream, rather than 4. For such values, either use SimpleIntEncoder or write your own version of variable length encoding, which can better handle negative values.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Field Summary
 
Fields inherited from class org.apache.lucene.util.encoding.IntEncoder
out
 
Constructor Summary
VInt8IntEncoder()
           
 
Method Summary
 IntDecoder createMatchingDecoder()
          Returns an IntDecoder which matches this encoder.
 void encode(int value)
          Encodes an integer to the output stream given in reInit
 String toString()
           
 
Methods inherited from class org.apache.lucene.util.encoding.IntEncoder
close, reInit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VInt8IntEncoder

public VInt8IntEncoder()
Method Detail

encode

public void encode(int value)
            throws IOException
Description copied from class: IntEncoder
Encodes an integer to the output stream given in reInit

Specified by:
encode in class IntEncoder
Throws:
IOException

createMatchingDecoder

public IntDecoder createMatchingDecoder()
Description copied from class: IntEncoder
Returns an IntDecoder which matches this encoder. Every encoder must return an IntDecoder and null is not a valid value. If an encoder is just a filter, it should at least return its wrapped encoder's matching decoder.

NOTE: this method should create a new instance of the matching decoder and leave the instance sharing to the caller. Returning the same instance over and over is risky because encoders and decoders are not thread safe.

Specified by:
createMatchingDecoder in class IntEncoder

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.