public final class UtilPlume
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
UtilPlume.NullableStringComparator
Same as built-in String comparison, but accept null arguments, and place them at the beginning.
|
static class |
UtilPlume.ObjectComparator
Attempt to order Objects.
|
static class |
UtilPlume.WildcardFilter
A FilenameFilter that accepts files whose name matches the given wildcard.
|
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
abbreviateNumber(long val)
Convert a number into an abbreviation such as "5.00K" for 5000 or "65.0M" for 65000000.
|
static @Nullable java.lang.String |
appendProperty(java.util.Properties p,
java.lang.String key,
java.lang.String value)
Set the property to its previous value concatenated to the given value.
|
static java.lang.String |
backticks(java.util.List<java.lang.String> command)
Execute the given command, and return all its output as a string.
|
static java.lang.String |
backticks(java.lang.String... command)
Execute the given command, and return all its output as a string.
|
static java.lang.String |
backTrace(java.lang.Throwable t)
Return a String representation of the backtrace of the given Throwable.
|
static java.io.BufferedOutputStream |
bufferedFileOutputStream(java.lang.String filename,
boolean append)
Returns a BufferedOutputStream for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.io.File file)
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.io.File file,
@Nullable java.lang.String charsetName)
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.lang.String filename)
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedReader |
bufferedFileReader(java.lang.String filename,
@Nullable java.lang.String charsetName)
Returns a BufferedReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedWriter |
bufferedFileWriter(java.lang.String filename)
Returns a BufferedWriter for the file, accounting for the possibility that the file is
compressed.
|
static java.io.BufferedWriter |
bufferedFileWriter(java.lang.String filename,
boolean append)
Returns a BufferedWriter for the file, accounting for the possibility that the file is
compressed.
|
static boolean |
canCreateAndWrite(java.io.File file)
Returns true if the file exists and is writable, or if the file can be created.
|
static int |
count(java.lang.String s,
int ch)
Return the number of times the character appears in the string.
|
static int |
count(java.lang.String s,
java.lang.String sub)
Return the number of times the second string appears in the first.
|
static long |
countLines(java.lang.String filename)
Count the number of lines in the specified file.
|
static java.io.File |
createTempDir(java.lang.String prefix,
java.lang.String suffix)
Creates an empty directory in the default temporary-file directory, using the given prefix and
suffix to generate its name.
|
static boolean |
deleteDir(java.io.File dir)
Deletes the directory at dir and all its files.
|
static boolean |
deleteDir(java.lang.String dirName)
Deletes the directory at dirName and all its files.
|
static boolean |
equalFiles(java.lang.String file1,
java.lang.String file2)
Return true iff files have the same contents.
|
static boolean |
equalFiles(java.lang.String file1,
java.lang.String file2,
boolean trimLines)
Return true iff the files have the same contents.
|
static java.lang.String |
escapeNonASCII(java.lang.String orig)
Escape unprintable characters in the target, following the usual Java backslash conventions, so
that the result is sure to be printable ASCII.
|
static java.lang.String |
escapeNonJava(java.lang.Character ch)
Like
escapeNonJava(String), but for a single character. |
static java.lang.String |
escapeNonJava(java.lang.String orig)
Escape \, ", newline, and carriage-return characters in the target as \\, \", \n, and \r;
return a new string if any modifications were necessary.
|
static java.io.File |
expandFilename(java.io.File name)
Does tilde expansion on a file name (to the user's home directory).
|
static java.lang.String |
expandFilename(java.lang.String name)
Does tilde expansion on a file name (to the user's home directory).
|
static java.io.InputStream |
fileInputStream(java.io.File file)
Returns an InputStream for the file, accounting for the possibility that the file is
compressed.
|
static java.io.InputStream |
fileInputStream(java.nio.file.Path path)
Returns an InputStream for the file, accounting for the possibility that the file is
compressed.
|
static java.util.List<java.lang.String> |
fileLines(java.lang.String filename)
Return the contents of the file, as a list of strings, one per line.
|
static java.io.InputStreamReader |
fileReader(java.io.File file)
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.io.InputStreamReader |
fileReader(java.io.File file,
@Nullable java.lang.String charsetName)
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.io.InputStreamReader |
fileReader(java.nio.file.Path path)
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.io.InputStreamReader |
fileReader(java.nio.file.Path path,
@Nullable java.lang.String charsetName)
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static java.io.InputStreamReader |
fileReader(java.lang.String filename)
Returns a Reader for the file, accounting for the possibility that the file is compressed.
|
static int |
hash(double x)
Return a hash of the arguments.
|
static int |
hash(double[] a)
Return a hash of the arguments.
|
static int |
hash(double[] a,
double[] b)
Return a hash of the arguments.
|
static int |
hash(double a,
double b)
Return a hash of the arguments.
|
static int |
hash(double a,
double b,
double c)
Return a hash of the arguments.
|
static int |
hash(long l)
Return a hash of the arguments.
|
static int |
hash(long[] a)
Return a hash of the arguments.
|
static int |
hash(long[] a,
long[] b)
Return a hash of the arguments.
|
static int |
hash(long a,
long b)
Return a hash of the arguments.
|
static int |
hash(long a,
long b,
long c)
Return a hash of the arguments.
|
static int |
hash(@Nullable java.lang.String a)
Return a hash of the arguments.
|
static int |
hash(@Nullable java.lang.String[] a)
Return a hash of the arguments.
|
static int |
hash(@Nullable java.lang.String a,
@Nullable java.lang.String b)
Return a hash of the arguments.
|
static int |
hash(@Nullable java.lang.String a,
@Nullable java.lang.String b,
@Nullable java.lang.String c)
Return a hash of the arguments.
|
static java.lang.String |
inferLineSeparator(java.io.File file)
Tries to infer the line separator used in a file.
|
static java.lang.String |
inferLineSeparator(java.lang.String filename)
Tries to infer the line separator used in a file.
|
static int |
intersectionCardinality(java.util.BitSet a,
java.util.BitSet b)
Returns the cardinality of the intersection of the two BitSets.
|
static int |
intersectionCardinality(java.util.BitSet a,
java.util.BitSet b,
java.util.BitSet c)
Returns the cardinality of the intersection of the three BitSets.
|
static boolean |
intersectionCardinalityAtLeast(java.util.BitSet a,
java.util.BitSet b,
java.util.BitSet c,
int i)
Returns true if the cardinality of the intersection of the three BitSets is at least the given
value.
|
static boolean |
intersectionCardinalityAtLeast(java.util.BitSet a,
java.util.BitSet b,
int i)
Returns true if the cardinality of the intersection of the two BitSets is at least the given
value.
|
static java.lang.String |
javaSource(java.io.File name)
Return a string version of the filename that can be used in Java source.
|
static java.lang.String |
join(java.lang.Iterable<? extends java.lang.Object> v,
java.lang.String delim)
Concatenate the string representations of the objects, placing the delimiter between them.
|
static java.lang.String |
join(java.lang.Object[] a,
java.lang.String delim)
Concatenate the string representations of the array elements, placing the delimiter between
them.
|
static java.lang.String |
joinLines(java.util.List<java.lang.String> v)
Concatenate the string representations of the objects, placing the system-specific line
separator between them.
|
static java.lang.String |
joinLines(java.lang.Object... a)
Concatenate the string representations of the objects, placing the system-specific line
separator between them.
|
static java.io.LineNumberReader |
lineNumberFileReader(java.io.File file)
Returns a LineNumberReader for the file, accounting for the possibility that the file is
compressed.
|
static java.io.LineNumberReader |
lineNumberFileReader(java.lang.String filename)
Returns a LineNumberReader for the file, accounting for the possibility that the file is
compressed.
|
static java.lang.String |
lpad(java.lang.String s,
int length)
Returns a string of the specified length, truncated if necessary, and padded with spaces to the
left if necessary.
|
static java.lang.String |
nplural(int n,
java.lang.String noun)
Return either "n noun" or "n nouns" depending on n.
|
static boolean |
propertyIsTrue(java.util.Properties p,
java.lang.String key)
Determines whether a property has value "true", "yes", or "1".
|
static java.lang.String |
readerContents(java.io.Reader r)
Reads the entire contents of the reader and returns it as a string.
|
static java.lang.String |
readFile(java.io.File file)
Reads the entire contents of the file and returns it as a string.
|
static java.lang.Object |
readObject(java.io.File file)
Reads an Object from a File.
|
static java.lang.String |
removeWhitespaceAfter(java.lang.String arg,
java.lang.String delimiter)
Remove all whitespace after instances of delimiter.
|
static java.lang.String |
removeWhitespaceAround(java.lang.String arg,
java.lang.String delimiter)
Remove all whitespace before or after instances of delimiter.
|
static java.lang.String |
removeWhitespaceBefore(java.lang.String arg,
java.lang.String delimiter)
Remove all whitespace before instances of delimiter.
|
static java.lang.String |
replaceString(java.lang.String target,
java.lang.String oldStr,
java.lang.String newStr)
Return a new string which is the text of target with all instances of oldStr replaced by
newStr.
|
static java.lang.String |
rpad(double num,
int length)
Converts the double to a String, then formats it using
rpad(String,int). |
static java.lang.String |
rpad(int num,
int length)
Converts the int to a String, then formats it using
rpad(String,int). |
static java.lang.String |
rpad(java.lang.String s,
int length)
Returns a string of the specified length, truncated if necessary, and padded with spaces to the
right if necessary.
|
static @Nullable java.lang.String |
setDefaultMaybe(java.util.Properties p,
java.lang.String key,
java.lang.String value)
Set the property only if it was not previously set.
|
static java.lang.String[] |
split(java.lang.String s,
char delim)
Return an array of Strings representing the characters between successive instances of the
delimiter character.
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String delim)
Return an array of Strings representing the characters between successive instances of the
delimiter String.
|
static java.lang.String[] |
splitLines(java.lang.String s)
Return an array of Strings, one for each line in the argument.
|
static void |
streamCopy(java.io.InputStream from,
java.io.OutputStream to)
Copy the contents of the input stream to the output stream.
|
static java.util.List<java.lang.String> |
streamLines(java.io.InputStream stream)
Reads all lines from the stream and returns them in a
List<String>. |
static java.lang.String |
streamString(java.io.InputStream is)
Return a String containing all the characters from the input stream.
|
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str)
Return a ArrayList of the Strings returned by
StringTokenizer.StringTokenizer(String) with the given arguments. |
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str,
java.lang.String delim)
Return a ArrayList of the Strings returned by
StringTokenizer.StringTokenizer(String,String) with the given arguments. |
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str,
java.lang.String delim,
boolean returnDelims)
Return a ArrayList of the Strings returned by
StringTokenizer.StringTokenizer(String,String,boolean) with the given arguments. |
static java.lang.String |
unescapeNonJava(java.lang.String orig)
Replace "\\", "\"", "\n", and "\r" sequences by their one-character equivalents.
|
static void |
writeFile(java.io.File file,
java.lang.String contents)
Creates a file with the given name and writes the specified string to it.
|
static void |
writeObject(java.lang.Object o,
java.io.File file)
Writes an Object to a File.
|
@Pure
public static boolean intersectionCardinalityAtLeast(java.util.BitSet a,
java.util.BitSet b,
int i)
a - the first BitSet to intersectb - the second BitSet to intersecti - the cardinality bound@Pure
public static boolean intersectionCardinalityAtLeast(java.util.BitSet a,
java.util.BitSet b,
java.util.BitSet c,
int i)
a - the first BitSet to intersectb - the second BitSet to intersectc - the third BitSet to intersecti - the cardinality bound@Pure
public static int intersectionCardinality(java.util.BitSet a,
java.util.BitSet b)
a - the first BitSet to intersectb - the second BitSet to intersect@Pure
public static int intersectionCardinality(java.util.BitSet a,
java.util.BitSet b,
java.util.BitSet c)
a - the first BitSet to intersectb - the second BitSet to intersectc - the third BitSet to intersectpublic static java.io.InputStream fileInputStream(java.nio.file.Path path)
throws java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
path - the possibly-compressed file to readjava.io.IOException - if there is trouble reading the filepublic static java.io.InputStream fileInputStream(java.io.File file)
throws java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
file - the possibly-compressed file to readjava.io.IOException - if there is trouble reading the filepublic static java.io.InputStreamReader fileReader(java.lang.String filename)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to readjava.io.IOException - if there is trouble reading the filejava.io.FileNotFoundException - if the file is not foundpublic static java.io.InputStreamReader fileReader(java.nio.file.Path path)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
path - the possibly-compressed file to readjava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.InputStreamReader fileReader(java.nio.file.Path path,
@Nullable java.lang.String charsetName)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
path - the possibly-compressed file to readcharsetName - null, or the name of a Charset to use when reading the filejava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.InputStreamReader fileReader(java.io.File file)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
file - the possibly-compressed file to readjava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.InputStreamReader fileReader(java.io.File file,
@Nullable java.lang.String charsetName)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
file - the possibly-compressed file to readcharsetName - null, or the name of a Charset to use when reading the filejava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.lang.String filename)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to readjava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.io.File file)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
file - the possibility-compressed file to readjava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.lang.String filename,
@Nullable java.lang.String charsetName)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to readcharsetName - the character set to use when reading the filejava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.BufferedReader bufferedFileReader(java.io.File file,
@Nullable java.lang.String charsetName)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
file - the possibly-compressed file to readcharsetName - the character set to use when reading the filejava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.LineNumberReader lineNumberFileReader(java.lang.String filename)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to readjava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.LineNumberReader lineNumberFileReader(java.io.File file)
throws java.io.FileNotFoundException,
java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
file - the possibly-compressed file to readjava.io.FileNotFoundException - if the file cannot be foundjava.io.IOException - if there is trouble reading the filepublic static java.io.BufferedWriter bufferedFileWriter(java.lang.String filename)
throws java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to writejava.io.IOException - if there is trouble writing the filepublic static java.io.BufferedWriter bufferedFileWriter(java.lang.String filename,
boolean append)
throws java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to writeappend - if true, the resulting BufferedWriter appends to the end of the file instead of
the beginningjava.io.IOException - if there is trouble writing the filepublic static java.io.BufferedOutputStream bufferedFileOutputStream(java.lang.String filename,
boolean append)
throws java.io.IOException
Warning: The "gzip" program writes and reads files containing concatenated gzip files. As of Java 1.4, Java reads just the first one: it silently discards all characters (including gzipped files) after the first gzipped file.
filename - the possibly-compressed file to writeappend - if true, the resulting BufferedOutputStream appends to the end of the file
instead of the beginningjava.io.IOException - if there is trouble writing the filepublic static long countLines(java.lang.String filename)
throws java.io.IOException
filename - file whose size to countjava.io.IOException - if there is trouble reading the filepublic static java.util.List<java.lang.String> fileLines(java.lang.String filename)
throws java.io.IOException
filename - the file whose contents to returnfilename, one string per linejava.io.IOException - if there was a problem reading the filepublic static java.lang.String inferLineSeparator(java.lang.String filename)
throws java.io.IOException
filename - the file to infer a line separator fromjava.io.IOException - if there is trouble reading the filepublic static java.lang.String inferLineSeparator(java.io.File file)
throws java.io.IOException
file - the file to infer a line separator fromjava.io.IOException - if there is trouble reading the file@Pure
public static boolean equalFiles(java.lang.String file1,
java.lang.String file2)
file1 - first file to comparefile2 - second file to compare@Pure
public static boolean equalFiles(java.lang.String file1,
java.lang.String file2,
boolean trimLines)
file1 - first file to comparefile2 - second file to comparetrimLines - if true, call String.trim on each line before comparingpublic static boolean canCreateAndWrite(java.io.File file)
file - the file to create and writepublic static java.io.File createTempDir(java.lang.String prefix,
java.lang.String suffix)
throws java.io.IOException
prefix - the prefix string to be used in generating the file's name; must be at least
three characters longsuffix - the suffix string to be used in generating the file's name; may be null, in which
case the suffix ".tmp" will be used Returns: An abstract pathname denoting a newly-created
empty filejava.lang.IllegalArgumentException - If the prefix argument contains fewer than three charactersjava.io.IOException - If a file could not be createdjava.lang.SecurityException - If a security manager exists and its
SecurityManager.checkWrite(java.lang.String) method does not allow a file to be createdFile.createTempFile(String, String, File)public static boolean deleteDir(java.lang.String dirName)
dirName - the directory to deletepublic static boolean deleteDir(java.io.File dir)
dir - the directory to deletepublic static java.io.File expandFilename(java.io.File name)
name - file whose name to expandpublic static java.lang.String expandFilename(java.lang.String name)
name - filename to expandpublic static java.lang.String javaSource(java.io.File name)
The current implementation presumes that backslashes don't appear in filenames except as windows path separators. That seems like a reasonable assumption.
name - file whose name to quotepublic static void writeObject(java.lang.Object o,
java.io.File file)
throws java.io.IOException
o - the object to writefile - the file to which to write the objectjava.io.IOException - if there is trouble writing the filepublic static java.lang.Object readObject(java.io.File file)
throws java.io.IOException,
java.lang.ClassNotFoundException
file - the file from which to readjava.io.IOException - if there is trouble reading the filejava.lang.ClassNotFoundException - if the object's class cannot be foundpublic static java.lang.String readerContents(java.io.Reader r)
r - the Reader to readpublic static java.lang.String readFile(java.io.File file)
You could use new String(Files.readAllBytes(...)), but it requires a Path rather
than a File, and it can throw IOException which has to be caught.
file - the file to readpublic static void writeFile(java.io.File file,
java.lang.String contents)
file - the file to write tocontents - the text to put in the filepublic static int hash(double x)
Double.hashCode().x - value to be hashedpublic static int hash(double a,
double b)
a - value to be hashedb - value to be hashedpublic static int hash(double a,
double b,
double c)
a - value to be hashedb - value to be hashedc - value to be hashedpublic static int hash(double[] a)
a - value to be hashedpublic static int hash(double[] a,
double[] b)
a - value to be hashedb - value to be hashedpublic static int hash(long l)
Long.hashCode(). But it doesn't map -1 and 0 to the same value.l - value to be hashedpublic static int hash(long a,
long b)
a - value to be hashedb - value to be hashedpublic static int hash(long a,
long b,
long c)
a - value to be hashedb - value to be hashedc - value to be hashedpublic static int hash(long[] a)
a - value to be hashedpublic static int hash(long[] a,
long[] b)
a - value to be hashedb - value to be hashedpublic static int hash(@Nullable java.lang.String a)
a - value to be hashedpublic static int hash(@Nullable java.lang.String a,
@Nullable java.lang.String b)
a - value to be hashedb - value to be hashedpublic static int hash(@Nullable java.lang.String a,
@Nullable java.lang.String b,
@Nullable java.lang.String c)
a - value to be hashedb - value to be hashedc - value to be hashedpublic static int hash(@Nullable java.lang.String[] a)
a - value to be hashedpublic static java.lang.String backticks(java.lang.String... command)
command - a command to execute on the command linepublic static java.lang.String backticks(java.util.List<java.lang.String> command)
command - a command to execute on the command line, as a list of strings (the command,
then its arguments)@Pure
public static boolean propertyIsTrue(java.util.Properties p,
java.lang.String key)
p - a Properties object in which to look up the propertykey - name of the property to look upProperties.getProperty(java.lang.String)public static @Nullable java.lang.String appendProperty(java.util.Properties p,
java.lang.String key,
java.lang.String value)
p - a Properties object in which to look up the propertykey - name of the property to look upvalue - value to concatenate to the previous value of the propertyProperties.getProperty(java.lang.String),
Properties.setProperty(java.lang.String, java.lang.String)public static @Nullable java.lang.String setDefaultMaybe(java.util.Properties p,
java.lang.String key,
java.lang.String value)
p - a Properties object in which to look up the propertykey - name of the property to look upvalue - value to set the property to, if it is not already setProperties.getProperty(java.lang.String),
Properties.setProperty(java.lang.String, java.lang.String)public static void streamCopy(java.io.InputStream from,
java.io.OutputStream to)
from - input streamto - output streampublic static java.lang.String streamString(java.io.InputStream is)
is - input stream to readpublic static java.util.List<java.lang.String> streamLines(java.io.InputStream stream)
throws java.io.IOException
List<String>.stream - the stream to read fromjava.io.IOException - if there is an error reading from the streampublic static java.lang.String replaceString(java.lang.String target,
java.lang.String oldStr,
java.lang.String newStr)
target - the string to do replacement inoldStr - the substring to replacenewStr - the replacementpublic static java.lang.String[] split(java.lang.String s,
char delim)
Consider using the built-in String.split method.
s - the string to splitdelim - delimiter to split the string onsplit(String s, String delim)public static java.lang.String[] split(java.lang.String s,
java.lang.String delim)
Consider using the built-in String.split method.
s - the string to splitdelim - delimiter to split the string onsplit(String s, char delim)@SideEffectFree public static java.lang.String[] splitLines(java.lang.String s)
s - the string to splitsplit(String s, char delim)public static java.lang.String join(java.lang.Object[] a,
java.lang.String delim)
If you are using Java 8 or later, then use the String.join() method instead.
a - array of values to concatenatedelim - delimiter to place between printed representationspublic static java.lang.String joinLines(java.lang.Object... a)
a - array of values to concatenatepublic static java.lang.String join(java.lang.Iterable<? extends java.lang.Object> v,
java.lang.String delim)
v - collection of values to concatenatedelim - delimiter to place between printed representationsAbstractCollection.toString()public static java.lang.String joinLines(java.util.List<java.lang.String> v)
v - list of values to concatenateAbstractCollection.toString()public static java.lang.String escapeNonJava(java.lang.String orig)
orig - string to quotepublic static java.lang.String escapeNonJava(java.lang.Character ch)
escapeNonJava(String), but for a single character.ch - character to quotepublic static java.lang.String escapeNonASCII(java.lang.String orig)
orig - string to quotepublic static java.lang.String unescapeNonJava(java.lang.String orig)
escapeNonJava(java.lang.String), but it is
not a general unescaping mechanism for Java strings.orig - string to quotepublic static java.lang.String removeWhitespaceAround(java.lang.String arg,
java.lang.String delimiter)
arg - string to remove whitespace indelimiter - string to remove whitespace abuttingpublic static java.lang.String removeWhitespaceAfter(java.lang.String arg,
java.lang.String delimiter)
arg - string to remove whitespace indelimiter - string to remove whitespace afterpublic static java.lang.String removeWhitespaceBefore(java.lang.String arg,
java.lang.String delimiter)
arg - string to remove whitespace indelimiter - string to remove whitespace beforepublic static java.lang.String nplural(int n,
java.lang.String noun)
n - count of nounsnoun - word being countedpublic static java.lang.String lpad(java.lang.String s,
int length)
s - string to truncate or padlength - goal lengthpublic static java.lang.String rpad(java.lang.String s,
int length)
s - string to truncate or padlength - goal lengthpublic static java.lang.String rpad(int num,
int length)
rpad(String,int).num - int whose string representation to truncate or padlength - goal lengthpublic static java.lang.String rpad(double num,
int length)
rpad(String,int).num - double whose string representation to truncate or padlength - goal lengthpublic static int count(java.lang.String s,
int ch)
s - string to search inch - character to search forpublic static int count(java.lang.String s,
java.lang.String sub)
s - string to search insub - non-empty string to search forpublic static java.lang.String abbreviateNumber(long val)
val - a numeric valuepublic static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str,
java.lang.String delim,
boolean returnDelims)
StringTokenizer.StringTokenizer(String,String,boolean) with the given arguments.
The static type is ArrayList<Object> because StringTokenizer extends Enumeration<Object> instead of Enumeration<String> as it should (probably due to
backward-compatibility).
str - a string to be parseddelim - the delimitersreturnDelims - flag indicating whether to return the delimiters as tokenspublic static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str,
java.lang.String delim)
StringTokenizer.StringTokenizer(String,String) with the given arguments.str - a string to be parseddelim - the delimiterspublic static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str)
StringTokenizer.StringTokenizer(String) with the given arguments.str - a string to be parsedpublic static java.lang.String backTrace(java.lang.Throwable t)
backtrace(new Throwable()).t - the Throwable to obtain a backtrace of