it.unipi.di.util
Class Utils

java.lang.Object
  extended by it.unipi.di.util.Utils

public abstract class Utils
extends Object

Utility class with a variety of multi-purpose static methods.

Author:
Claudio Corsi, Paolo Ferragina

Method Summary
static int bytesToInt(byte[] array)
           
static long bytesToLong(byte[] array)
           
static String elapsedTime(long msecs)
           
static String elapsedTime(long start, long stop)
           
static int fastUnzip(byte[] input, it.unimi.dsi.mg4j.io.FastByteArrayOutputStream out)
          Read the input byte array compressed with ZIP and uncompress it using a previously allocated FastByteArrayOutputStream.
static int fastUnzip(byte[] input, int offset, int size, it.unimi.dsi.mg4j.io.FastByteArrayOutputStream out)
          Read the input byte array compressed with ZIP and uncompress it using a previously allocated FastByteArrayOutputStream.
static void fastZip(byte[] input, int off, int len, it.unimi.dsi.mg4j.io.FastByteArrayOutputStream out, int level)
          Compress with ZIP using the JCraft library.
static String formatSize(long size)
           
static it.unimi.dsi.mg4j.util.MutableString getField(it.unimi.dsi.mg4j.util.MutableString rec, int field, it.unimi.dsi.mg4j.util.MutableString fieldSeparator)
           
static String getKey(String line, int[] cols, char sep, boolean numeric)
           
static long getLong(byte[] buff, int pos)
           
static String getSortingCols(String line, int[] fields, Pattern p)
           
static byte[] intToBytes(int val)
           
static byte[] loadFromDisk(String file)
          A fast way to load in memory the content of a file.
static byte[] longToBytes(long val)
           
static byte[] merge(byte[] b1, byte[] b2)
           
static String pad(String str)
           
static double round(double val, int precision)
           
static String trimLeftZeros(String str)
           
static byte[] zip(byte[] input, int off, int len)
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

round

public static double round(double val,
                           int precision)

formatSize

public static String formatSize(long size)

elapsedTime

public static String elapsedTime(long start,
                                 long stop)

elapsedTime

public static String elapsedTime(long msecs)

intToBytes

public static byte[] intToBytes(int val)

longToBytes

public static byte[] longToBytes(long val)

merge

public static byte[] merge(byte[] b1,
                           byte[] b2)

bytesToLong

public static long bytesToLong(byte[] array)

bytesToInt

public static int bytesToInt(byte[] array)

fastUnzip

public static int fastUnzip(byte[] input,
                            it.unimi.dsi.mg4j.io.FastByteArrayOutputStream out)
                     throws IOException
Read the input byte array compressed with ZIP and uncompress it using a previously allocated FastByteArrayOutputStream. The implementation is based on the JCraft ZLib implementation.

Parameters:
input - the compressed data
out - the output buffer
Returns:
the size of the uncompressed data in output
Throws:
IOException

fastUnzip

public static int fastUnzip(byte[] input,
                            int offset,
                            int size,
                            it.unimi.dsi.mg4j.io.FastByteArrayOutputStream out)
                     throws IOException
Read the input byte array compressed with ZIP and uncompress it using a previously allocated FastByteArrayOutputStream. The implementation is based on the JCraft ZLib implementation.

Parameters:
input - the compressed data
offset - the starting position on the input array
size - the number of bytes to consider of the input array
out - the output buffer (reset by this method)
Returns:
the size of the uncompressed data in output
Throws:
IOException

fastZip

public static void fastZip(byte[] input,
                           int off,
                           int len,
                           it.unimi.dsi.mg4j.io.FastByteArrayOutputStream out,
                           int level)
                    throws IOException
Compress with ZIP using the JCraft library.

Throws:
IOException

zip

public static byte[] zip(byte[] input,
                         int off,
                         int len)
Deprecated. 

Compress with ZIP using the java.util.zip package.

See Also:
fastZip(byte[], int, int, FastByteArrayOutputStream, int)

loadFromDisk

public static byte[] loadFromDisk(String file)
                           throws IOException
A fast way to load in memory the content of a file.

Parameters:
file - the file to load
Returns:
the file content in bytes
Throws:
IOException

getSortingCols

public static String getSortingCols(String line,
                                    int[] fields,
                                    Pattern p)

trimLeftZeros

public static String trimLeftZeros(String str)

getKey

public static String getKey(String line,
                            int[] cols,
                            char sep,
                            boolean numeric)

pad

public static String pad(String str)

getLong

public static long getLong(byte[] buff,
                           int pos)

getField

public static it.unimi.dsi.mg4j.util.MutableString getField(it.unimi.dsi.mg4j.util.MutableString rec,
                                                            int field,
                                                            it.unimi.dsi.mg4j.util.MutableString fieldSeparator)