net.siefkes.nlstego.util
Class NumUtils

java.lang.Object
  extended by net.siefkes.nlstego.util.NumUtils

public final class NumUtils
extends Object

A static utility class that provides methods for working with numbers. No instances of this class can be created, only the static members should be used.

Version:
$Revision: 1.3 $, $Date: 2005/07/12 17:02:22 $, $Author: siefkes $
Author:
Christian Siefkes

Method Summary
static long decodeVInt(InputStream in)
          Reads a number in the variable-length VInt format (as used by Apache Lucene).
static byte[] encodeVInt(long num)
          Encodes a number in the variable-length VInt format (as used by Apache Lucene).
static void encodeVInt(long num, OutputStream out)
          Encodes a number in the variable-length VInt format (as used by Apache Lucene).
static boolean endsVInt(byte b)
          Checks whether a byte is the last byte of a number stored in the variable-length VInt format (as used by Apache Lucene).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

decodeVInt

public static long decodeVInt(InputStream in)
                       throws IOException
Reads a number in the variable-length VInt format (as used by Apache Lucene).

Parameters:
in - the stream to read from
Returns:
the decoded number
Throws:
IOException - if an I/O error occurs while reading

endsVInt

public static boolean endsVInt(byte b)
Checks whether a byte is the last byte of a number stored in the variable-length VInt format (as used by Apache Lucene). For the last byte in a VInt, the highest-order bit is 0, for all other bytes in a VInt it is 1 .

Parameters:
b - the byte to check
Returns:
true if the byte looks like the last byte in a VInt

encodeVInt

public static void encodeVInt(long num,
                              OutputStream out)
                       throws IOException
Encodes a number in the variable-length VInt format (as used by Apache Lucene).

Parameters:
num - the number to write
out - the stream to write the number to
Throws:
IOException - if an I/O error occurs while writing

encodeVInt

public static byte[] encodeVInt(long num)
Encodes a number in the variable-length VInt format (as used by Apache Lucene).

Parameters:
num - the number to write
Returns:
a byte array encoding the given number in VInt format


Copyright © 2003-2005 Christian Siefkes. All Rights Reserved.