|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.lts.ipc.Utils
public class Utils
An internal class that provides utility methods common to IPC classes.
Constructor Summary | |
---|---|
Utils()
|
Method Summary | |
---|---|
static boolean |
checkFile(java.io.File f)
Create a file if it does not already exist. |
static void |
checkFile(java.lang.String name)
|
static void |
closeNoExceptions(java.io.BufferedReader reader)
|
static void |
closeNoExceptions(java.io.FileWriter writer)
|
static void |
closeNoExceptions(java.io.InputStream istream)
|
static void |
closeNoExceptions(java.io.OutputStream ostream)
|
static void |
closeNoExceptions(java.io.Reader reader)
|
static byte[] |
createAndFillWith(int size,
java.lang.String pattern)
Create a byte array that is populated with a particular string. |
static void |
fillArrayWith(byte[] dest,
byte[] pattern)
|
static void |
listProperties()
|
static java.lang.Object |
matchIgnoreCase(java.lang.Object[] values,
java.lang.String s)
|
static void |
printEnv()
|
static java.lang.String |
readFile(java.io.File file)
|
static java.lang.String |
readFile(java.lang.String name)
|
static java.lang.String |
readOrCreate(java.io.File file,
java.lang.String contents)
Read or create a file. |
static java.lang.String |
readOrCreate(java.lang.String name,
java.lang.String contents)
|
static long |
toMilliseconds(long seconds,
long nanos)
|
static long |
toNanoseconds(long sec,
long nanos)
|
static java.lang.Object |
toValueIgnoreCase(java.lang.Object[] values,
java.lang.String s)
Find the enum tag that matches a string without regards to case. |
static void |
writeFile(java.io.File file,
java.lang.String contents)
|
static void |
writeFile(java.lang.String name,
java.lang.String contents)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Utils()
Method Detail |
---|
public static boolean checkFile(java.io.File f) throws IPCException
The IPC classes in this package all expect a file to exist that corresponds to the resource that they are manipulating. This method checks to see if the corresponding file does indeed exist on the underlying system. If it does not, then the method will try to create it.
name
- The absolute path to the file.
IPCException
- If the method tries to create the file but an exception is thrown. The
message will be set to IPCException.Errors.ExceptionCreatingFile
and the
cause will be set to the offending exception.public static void checkFile(java.lang.String name) throws IPCException
IPCException
public static long toMilliseconds(long seconds, long nanos)
public static long toNanoseconds(long sec, long nanos)
public static void closeNoExceptions(java.io.Reader reader)
public static void closeNoExceptions(java.io.BufferedReader reader)
public static void closeNoExceptions(java.io.InputStream istream)
public static java.lang.String readFile(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String readFile(java.lang.String name) throws java.io.IOException
java.io.IOException
public static void writeFile(java.io.File file, java.lang.String contents) throws java.io.IOException
java.io.IOException
public static void writeFile(java.lang.String name, java.lang.String contents) throws java.io.IOException
java.io.IOException
public static void closeNoExceptions(java.io.FileWriter writer)
public static java.lang.Object toValueIgnoreCase(java.lang.Object[] values, java.lang.String s)
This method is intended to be used like so:
enum Foo {
One,Two,Three,Four;
public static Foo toValueIgnoreCase(String s) {
return (Foo) Utils.toValueIgnoreCase(Foo.values(), s);
}
}
values
- The enum tag values.s
- The string we are trying to convert.
java.lang.RuntimeException
- If there is no match.public static java.lang.Object matchIgnoreCase(java.lang.Object[] values, java.lang.String s)
public static void closeNoExceptions(java.io.OutputStream ostream)
public static void fillArrayWith(byte[] dest, byte[] pattern)
public static byte[] createAndFillWith(int size, java.lang.String pattern)
Useful when initializing shared memory.
size
- The size of the returned array.pattern
- The pattern to use to populate the array.
public static void listProperties()
public static java.lang.String readOrCreate(java.io.File file, java.lang.String contents) throws java.io.IOException
This method opens the named text file and returns its contents, assuming the file exists.
If the file does not exist, then it creates it and writes the supplied string into it. This operation happens in an "atomic" fashion, so that another thread or process that if another process or thread attempts to write the same file at the same time, only one of them will succeed.
file
- The file to read or create.contents
- If the file needs to be created, the contents of the file.
java.io.IOException
- If a problem exists while trying to read or write the file.public static java.lang.String readOrCreate(java.lang.String name, java.lang.String contents) throws java.io.IOException
java.io.IOException
public static void printEnv()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |