Package net.razorvine.pickle
Class PickleUtils
- java.lang.Object
-
- net.razorvine.pickle.PickleUtils
-
public abstract class PickleUtils extends java.lang.ObjectUtility 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 doublebytes_to_double(byte[] bytes, int offset)Convert a big endian 8-byte to a double.static floatbytes_to_float(byte[] bytes, int offset)Convert a big endian 4-byte to a float.static intbytes_to_integer(byte[] bytes)Convert a couple of bytes into the corresponding integer number.static intbytes_to_integer(byte[] bytes, int offset, int size)static longbytes_to_long(byte[] bytes, int offset)Convert 8 little endian bytes into a longstatic longbytes_to_uint(byte[] bytes, int offset)Convert 4 little endian bytes into an unsigned int (as a long)static java.lang.Stringdecode_escaped(java.lang.String str)Decode a string with possible escaped char sequences in it (\x??).static java.lang.Numberdecode_long(byte[] data)read an arbitrary 'long' number.static java.lang.Stringdecode_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.NumberoptimizeBigint(java.math.BigInteger bigint)Optimize a biginteger, if possible return a long primitive datatype.static java.lang.StringrawStringFromBytes(byte[] data)Construct a String from the given bytes where these are directly converted to the corresponding chars, without using a given character encodingstatic shortreadbyte(java.io.InputStream input)read a single unsigned bytestatic byte[]readbytes(java.io.InputStream input, int n)read a number of signed bytesstatic byte[]readbytes(java.io.InputStream input, long n)read a number of signed bytesstatic voidreadbytes_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 arraystatic java.lang.Stringreadline(java.io.InputStream input)read a line of text, excluding the terminating LF charstatic java.lang.Stringreadline(java.io.InputStream input, boolean includeLF)read a line of text, possibly including the terminating LF charstatic byte[]str2bytes(java.lang.String str)Convert a string to a byte array, no encoding is used.
-
-
-
Method Detail
-
readline
public static java.lang.String readline(java.io.InputStream input) throws java.io.IOExceptionread 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.IOExceptionread 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.IOExceptionread a single unsigned byte- Throws:
java.io.IOException
-
readbytes
public static byte[] readbytes(java.io.InputStream input, int n) throws java.io.IOExceptionread a number of signed bytes- Throws:
java.io.IOException
-
readbytes
public static byte[] readbytes(java.io.InputStream input, long n) throws java.io.IOExceptionread 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.IOExceptionread 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.IOExceptionConvert 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 (€)
-
-