Class PickleUtils


  • public abstract class PickleUtils
    extends java.lang.Object
    Utility stuff for dealing with pickle data streams.
    Author:
    Irmen de Jong (irmen@razorvine.net)
    • Constructor Summary

      Constructors 
      Constructor Description
      PickleUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double bytes_to_double​(byte[] bytes, int offset)
      Convert a big endian 8-byte to a double.
      static float bytes_to_float​(byte[] bytes, int offset)
      Convert a big endian 4-byte to a float.
      static int bytes_to_integer​(byte[] bytes)
      Convert a couple of bytes into the corresponding integer number.
      static int bytes_to_integer​(byte[] bytes, int offset, int size)  
      static long bytes_to_long​(byte[] bytes, int offset)
      Convert 8 little endian bytes into a long
      static long bytes_to_uint​(byte[] bytes, int offset)
      Convert 4 little endian bytes into an unsigned int (as a long)
      static java.lang.String decode_escaped​(java.lang.String str)
      Decode a string with possible escaped char sequences in it (\x??).
      static java.lang.Number decode_long​(byte[] data)
      read an arbitrary 'long' number.
      static java.lang.String decode_unicode_escaped​(java.lang.String str)
      Decode a string with possible escaped unicode in it (€)
      static byte[] double_to_bytes​(double d)
      Convert a double to its 8-byte representation (big endian).
      static byte[] encode_long​(java.math.BigInteger big)
      encode an arbitrary long number into a byte array (little endian).
      static byte[] integer_to_bytes​(int i)
      Convert a signed integer to its 4-byte representation.
      static java.lang.Number optimizeBigint​(java.math.BigInteger bigint)
      Optimize a biginteger, if possible return a long primitive datatype.
      static java.lang.String rawStringFromBytes​(byte[] data)
      Construct a String from the given bytes where these are directly converted to the corresponding chars, without using a given character encoding
      static short readbyte​(java.io.InputStream input)
      read a single unsigned byte
      static byte[] readbytes​(java.io.InputStream input, int n)
      read a number of signed bytes
      static byte[] readbytes​(java.io.InputStream input, long n)
      read a number of signed bytes
      static void readbytes_into​(java.io.InputStream input, byte[] buffer, int offset, int length)
      read a number of signed bytes into the specified location in an existing byte array
      static java.lang.String readline​(java.io.InputStream input)
      read a line of text, excluding the terminating LF char
      static java.lang.String readline​(java.io.InputStream input, boolean includeLF)
      read a line of text, possibly including the terminating LF char
      static byte[] str2bytes​(java.lang.String str)
      Convert a string to a byte array, no encoding is used.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PickleUtils

        public PickleUtils()
    • Method Detail

      • readline

        public static java.lang.String readline​(java.io.InputStream input)
                                         throws java.io.IOException
        read a line of text, excluding the terminating LF char
        Throws:
        java.io.IOException
      • readline

        public static java.lang.String readline​(java.io.InputStream input,
                                                boolean includeLF)
                                         throws java.io.IOException
        read a line of text, possibly including the terminating LF char
        Throws:
        java.io.IOException
      • readbyte

        public static short readbyte​(java.io.InputStream input)
                              throws java.io.IOException
        read a single unsigned byte
        Throws:
        java.io.IOException
      • readbytes

        public static byte[] readbytes​(java.io.InputStream input,
                                       int n)
                                throws java.io.IOException
        read a number of signed bytes
        Throws:
        java.io.IOException
      • readbytes

        public static byte[] readbytes​(java.io.InputStream input,
                                       long n)
                                throws java.io.IOException
        read a number of signed bytes
        Throws:
        java.io.IOException
      • readbytes_into

        public static void readbytes_into​(java.io.InputStream input,
                                          byte[] buffer,
                                          int offset,
                                          int length)
                                   throws java.io.IOException
        read a number of signed bytes into the specified location in an existing byte array
        Throws:
        java.io.IOException
      • bytes_to_integer

        public static int bytes_to_integer​(byte[] bytes)
        Convert a couple of bytes into the corresponding integer number. Can deal with 2-bytes unsigned int and 4-bytes signed int.
      • bytes_to_integer

        public static int bytes_to_integer​(byte[] bytes,
                                           int offset,
                                           int size)
      • bytes_to_long

        public static long bytes_to_long​(byte[] bytes,
                                         int offset)
        Convert 8 little endian bytes into a long
      • bytes_to_uint

        public static long bytes_to_uint​(byte[] bytes,
                                         int offset)
        Convert 4 little endian bytes into an unsigned int (as a long)
      • integer_to_bytes

        public static byte[] integer_to_bytes​(int i)
        Convert a signed integer to its 4-byte representation. (little endian)
      • double_to_bytes

        public static byte[] double_to_bytes​(double d)
        Convert a double to its 8-byte representation (big endian).
      • bytes_to_double

        public static double bytes_to_double​(byte[] bytes,
                                             int offset)
        Convert a big endian 8-byte to a double.
      • bytes_to_float

        public static float bytes_to_float​(byte[] bytes,
                                           int offset)
        Convert a big endian 4-byte to a float.
      • decode_long

        public static java.lang.Number decode_long​(byte[] data)
        read an arbitrary 'long' number. Returns an int/long/BigInteger as appropriate to hold the number.
      • encode_long

        public static byte[] encode_long​(java.math.BigInteger big)
        encode an arbitrary long number into a byte array (little endian).
      • optimizeBigint

        public static java.lang.Number optimizeBigint​(java.math.BigInteger bigint)
        Optimize a biginteger, if possible return a long primitive datatype.
      • rawStringFromBytes

        public static java.lang.String rawStringFromBytes​(byte[] data)
        Construct a String from the given bytes where these are directly converted to the corresponding chars, without using a given character encoding
      • str2bytes

        public static byte[] str2bytes​(java.lang.String str)
                                throws java.io.IOException
        Convert a string to a byte array, no encoding is used. String must only contain characters less than 256.
        Throws:
        java.io.IOException
      • decode_escaped

        public static java.lang.String decode_escaped​(java.lang.String str)
        Decode a string with possible escaped char sequences in it (\x??).
      • decode_unicode_escaped

        public static java.lang.String decode_unicode_escaped​(java.lang.String str)
        Decode a string with possible escaped unicode in it (€)