ccs.utils
Class LongEncoder

java.lang.Object
  extended by ccs.utils.LongEncoder

public final class LongEncoder
extends java.lang.Object

Encodes a long as a string using a more compact representation (i.e. a higher radix, actually base-64) than is available from the Long class. The output is as though the input were unsigned, and is not zero-padded. The algorithm may be slower than that of Long.toString.

This class is intended as a specialised helper for applications that have to produce string representations of inconveniently large numbers for cryptography-related purposes. For example, suppose you have a 160-bit hash value; you could convert this into a string by splitting it into 3 longs and encoding each into a StringBuilder with successive calls to encode. YMMV for other types of job; in particular, we don't provide a parser.

NB. The sort order of the outputs is *not* the same as the sort order of the inputs. This is largely coincidental, but it's useful for topicmapping (the perturbation leads to better storage efficiency) and there it is.


Method Summary
static java.lang.String encode(long x)
          Encodes the supplied long and returns the result.
static void encode(long x, java.lang.StringBuilder sb)
          Encodes the supplied long and appends the result onto the supplied StringBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encode

public static void encode(long x,
                          java.lang.StringBuilder sb)
Encodes the supplied long and appends the result onto the supplied StringBuilder.

Parameters:
x - The long to encode.
sb - The StringBuilder to append the output to.

encode

public static java.lang.String encode(long x)
Encodes the supplied long and returns the result. This is a wrapper around the method of two arguments.

Parameters:
x - The long to encode.
Returns:
The string representation.