public class Util
extends java.lang.Object
| Constructor | Description |
|---|---|
Util() |
| Modifier and Type | Method | Description |
|---|---|---|
static java.io.File |
createHierarchicalTempFile(java.io.File baseDirectory,
int pathElements,
java.lang.String prefix,
java.lang.String suffix) |
Creates a temporary file with a random hierachical path.
|
static boolean |
parseBoolean(java.lang.String s) |
Parses a Boolean value reliably, throwing an exception if the argument is not
true or false (case insensitively). |
static byte[] |
readByteArray(java.io.ObjectInputStream s) |
Reads a byte array prefixed by its length encoded using vByte.
|
static int |
readVByte(java.io.InputStream is) |
Decodes a natural number from an
InputStream using vByte. |
static byte[] |
toByteArray(java.lang.String s) |
Returns a byte-array representation of an ASCII string.
|
static ByteArrayList |
toByteArrayList(java.lang.String s,
ByteArrayList list) |
Writes an ASCII string in a
ByteArrayList. |
static java.io.OutputStream |
toOutputStream(java.lang.String s,
java.io.OutputStream os) |
Writes a string to an output stream, discarding higher order bits.
|
static java.lang.String |
toString(byte[] byteArray) |
Returns a string representation of an ASCII byte array.
|
static java.lang.String |
toString(byte[] byteArray,
int offset,
int length) |
Returns a string representation of an ASCII byte-array fragment.
|
static java.lang.String |
toString(ByteArrayList byteArrayList) |
Returns a string representation of an ASCII byte array.
|
static int |
vByteLength(int x) |
Returns the length of the vByte encoding of a natural number.
|
static void |
writeByteArray(byte[] a,
java.io.ObjectOutputStream s) |
Writes a byte array prefixed by its length encoded using vByte.
|
static int |
writeVByte(int x,
java.io.OutputStream os) |
Encodes a natural number to an
OutputStream using vByte. |
public static boolean parseBoolean(java.lang.String s)
true or false (case insensitively).s - a string containing true or false.s.public static java.io.File createHierarchicalTempFile(java.io.File baseDirectory,
int pathElements,
java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
A random hierarchical path of n path elements is a sequence of n
directories of two hexadecimal digits each, followed by a filename created by File.createTempFile(String, String, File).
This method creates an empty file having a random hierarchical path of the specified number of path elements under a given base directory, creating all needed directories along the hierarchical path (whereas the base directory is expected to already exist).
baseDirectory - the base directory (it must exist).pathElements - the number of path elements (filename excluded), must be in [0,8]prefix - will be passed to File.createTempFile(String, String, File)suffix - will be passed to File.createTempFile(String, String, File)java.io.IOExceptionpublic static final int vByteLength(int x)
x - a natural number.x.public static int writeVByte(int x,
java.io.OutputStream os)
throws java.io.IOException
OutputStream using vByte.x - a natural number.os - an output stream.java.io.IOExceptionpublic static int readVByte(java.io.InputStream is)
throws java.io.IOException
InputStream using vByte.is - an input stream.is using vByte.java.io.IOExceptionpublic static final void writeByteArray(byte[] a,
java.io.ObjectOutputStream s)
throws java.io.IOException
a - the array to be written.s - the stream where the array should be written.java.io.IOExceptionpublic static final byte[] readByteArray(java.io.ObjectInputStream s)
throws java.io.IOException
s - the stream from which the array should be read.java.io.IOExceptionpublic static byte[] toByteArray(java.lang.String s)
This method is significantly faster than those relying on character encoders, and it allocates just one object—the resulting byte array.
s - an ASCII string.s.java.lang.AssertionError - if assertions are enabled and some character of s is not ASCII.public static java.io.OutputStream toOutputStream(java.lang.String s,
java.io.OutputStream os)
throws java.io.IOException
This method is significantly faster than those relying on character encoders, and it does not allocate any object.
s - a string.os - an output stream.os.java.lang.AssertionError - if assertions are enabled and some character of s does not fit a byte.java.io.IOExceptionpublic static ByteArrayList toByteArrayList(java.lang.String s, ByteArrayList list)
ByteArrayList.s - an ASCII string.list - a byte list that will contain the byte representation of s.list.java.lang.AssertionError - if assertions are enabled and some character of s is not ASCII.public static java.lang.String toString(ByteArrayList byteArrayList)
This method is significantly faster than those relying on character encoders, and it allocates just one object—the resulting string.
byteArrayList - an ASCII byte-array list.byteArrayList.java.lang.AssertionError - if assertions are enabled and some character of byteArrayList is not ASCII.public static java.lang.String toString(byte[] byteArray)
This method is significantly faster than those relying on character encoders, and it allocates just one object—the resulting string.
byteArray - an ASCII byte array.byteArray.java.lang.AssertionError - if assertions are enabled and some character of byteArray is not ASCII.public static java.lang.String toString(byte[] byteArray,
int offset,
int length)
This method is significantly faster than those relying on character encoders, and it allocates just one object—the resulting string.
byteArray - an ASCII byte array.byteArray.java.lang.AssertionError - if assertions are enabled and some character of byteArray is not ASCII.