public final class UtilPlume
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
UtilPlume.NullableStringComparator
Deprecated.
use StringsPlume.NullableStringComparator
|
static class |
UtilPlume.ObjectComparator
Deprecated.
use StringsPlume.ObjectComparator
|
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)
Deprecated.
use StringsPlume.abbreviateNumber
|
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)
Deprecated.
|
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)
Deprecated.
use StringsPlume.count
|
static int |
count(java.lang.String s,
java.lang.String sub)
Deprecated.
use StringsPlume.count
|
static int |
countFormatArguments(java.lang.String s)
Deprecated.
use StringsPlume.countFormatArguments
|
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 |
escapeJava(char c)
Deprecated.
use StringsPlume.escapeJava
|
static java.lang.String |
escapeJava(java.lang.Character ch)
Deprecated.
use StringsPlume.escapeJava
|
static java.lang.String |
escapeJava(java.lang.String orig)
Deprecated.
use StringsPlume.escapeJava
|
static java.lang.String |
escapeNonASCII(java.lang.String orig)
Deprecated.
use StringsPlume.escapeNonASCII
|
static java.lang.String |
escapeNonJava(java.lang.Character ch)
Deprecated.
|
static java.lang.String |
escapeNonJava(java.lang.String orig)
Deprecated.
|
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)
Deprecated.
use Files.readAllLines
|
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 void |
gc()
Deprecated.
use
SystemPlume.gc() |
static int |
hash(double x)
Deprecated.
use Double.hashCode()
|
static int |
hash(double[] a)
Deprecated.
use Arrays.hashCode
|
static int |
hash(double[] a,
double[] b)
Return a hash of the arguments.
|
static int |
hash(double a,
double b)
Deprecated.
use Objects.hash
|
static int |
hash(double a,
double b,
double c)
Deprecated.
use Objects.hash
|
static int |
hash(long l)
Deprecated.
use
Long.hashCode() |
static int |
hash(long[] a)
Deprecated.
use Arrays.hashCode
|
static int |
hash(long[] a,
long[] b)
Return a hash of the arguments.
|
static int |
hash(long a,
long b)
Deprecated.
use Objects.hash
|
static int |
hash(long a,
long b,
long c)
Deprecated.
use Objects.hash
|
static int |
hash(@Nullable java.lang.String a)
Deprecated.
use String.hashCode
|
static int |
hash(@Nullable java.lang.String[] a)
Deprecated.
use Arrays.hashCode
|
static int |
hash(@Nullable java.lang.String a,
@Nullable java.lang.String b)
Deprecated.
use Objects.hash
|
static int |
hash(@Nullable java.lang.String a,
@Nullable java.lang.String b,
@Nullable java.lang.String c)
Deprecated.
use Objects.hash
|
static java.lang.String |
indentLines(@NonNegative int indent,
@Nullable java.lang.Object o)
Deprecated.
use StringsPlume.indentLines
|
static java.lang.String |
indentLinesExceptFirst(@NonNegative int indent,
@Nullable java.lang.Object o)
Deprecated.
use StringsPlume.indentLinesExceptFirst
|
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,
@NonNegative 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,
@NonNegative 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.CharSequence delim,
java.lang.Iterable<?> v)
Deprecated.
use StringsPlume.join
|
static <T> java.lang.String |
join(java.lang.CharSequence delim,
T... a)
Deprecated.
use StringsPlume.join
|
static java.lang.String |
join(java.lang.Iterable<?> v,
java.lang.CharSequence delim)
Deprecated.
use
join(CharSequence, Iterable) which has the arguments in the other
order |
static <T> java.lang.String |
join(T[] a,
java.lang.CharSequence delim)
Deprecated.
use
join(CharSequence, Object...) which has the arguments in the other
order |
static java.lang.String |
joinLines(java.lang.Iterable<?> v)
Deprecated.
use StringsPlume.joinLines
|
static <T> java.lang.String |
joinLines(T... a)
Deprecated.
use StringsPlume.joinLines
|
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,
@NonNegative int length)
Deprecated.
use StringsPlume.lpad
|
static java.lang.String |
mapToStringAndClass(java.util.Map<?,?> m)
Deprecated.
use StringsPlume.mapToStringAndClass
|
static java.lang.String |
nplural(int n,
java.lang.String noun)
Deprecated.
use StringsPlume.nplural
|
static java.lang.String |
prefixLines(java.lang.String prefix,
@Nullable java.lang.Object o)
Deprecated.
use StringsPlume.prefixLines
|
static java.lang.String |
prefixLinesExceptFirst(java.lang.String prefix,
@Nullable java.lang.Object o)
Deprecated.
use StringsPlume.prefixLinesExceptFirst
|
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)
Deprecated.
use StringsPlume.removeWhitespaceAfter
|
static java.lang.String |
removeWhitespaceAround(java.lang.String arg,
java.lang.String delimiter)
Deprecated.
use StringsPlume.removeWhitespaceAround
|
static java.lang.String |
removeWhitespaceBefore(java.lang.String arg,
java.lang.String delimiter)
Deprecated.
use StringsPlume.removeWhitespaceBefore
|
static java.lang.String |
replacePrefix(java.lang.String target,
java.lang.String oldStr,
java.lang.String newStr)
Deprecated.
use StringsPlume.replacePrefix
|
static java.lang.String |
replaceString(java.lang.String target,
java.lang.String oldStr,
java.lang.String newStr)
Deprecated.
use String.replace
|
static java.lang.String |
replaceSuffix(java.lang.String target,
java.lang.String oldStr,
java.lang.String newStr)
Deprecated.
use StringsPlume.replaceSuffix
|
static java.lang.String |
rpad(double num,
@NonNegative int length)
Deprecated.
use StringsPlume.rpad
|
static java.lang.String |
rpad(int num,
@NonNegative int length)
Deprecated.
use StringsPlume.rpad
|
static java.lang.String |
rpad(java.lang.String s,
@NonNegative int length)
Deprecated.
use StringsPlume.rpad
|
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 void |
sleep(long millis)
Deprecated.
|
static java.lang.String[] |
split(java.lang.String s,
char delim)
Deprecated.
use StringsPlume.split
|
static java.lang.String[] |
split(java.lang.String s,
java.lang.String delim)
Deprecated.
use StringsPlume.split
|
static java.lang.String[] |
splitLines(java.lang.String s)
Deprecated.
use StringsPlume.splitLines
|
static java.lang.String |
stackTraceToString(java.lang.Throwable t)
Return a String representation of the stack trace (the backtrace) of the given Throwable.
|
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)
Deprecated.
use StringsPlume.tokens
|
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str,
java.lang.String delim)
Deprecated.
use StringsPlume.tokens
|
static java.util.ArrayList<java.lang.Object> |
tokens(java.lang.String str,
java.lang.String delim,
boolean returnDelims)
Deprecated.
use StringsPlume.tokens
|
static java.lang.String |
toStringAndClass(@Nullable java.lang.Object o)
Deprecated.
use StringsPlume.toStringAndClass
|
static java.lang.String |
unescapeJava(java.lang.String orig)
Deprecated.
use StringsPlume.unescapeJava
|
static java.lang.String |
unescapeNonJava(java.lang.String orig)
Deprecated.
|
static long |
usedMemory()
Deprecated.
|
static long |
usedMemory(boolean forceGc)
Deprecated.
|
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, @NonNegative 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, @NonNegative 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 file@Deprecated public 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[] a, double[] b)
a
- value to be hashedb
- value to be hashedpublic static int hash(long[] a, long[] b)
a
- value to be hashedb
- value to be hashed@Deprecated public static int hash(double x)
Double.hashCode()
.x
- value to be hashed@Deprecated public static int hash(double a, double b)
a
- value to be hashedb
- value to be hashed@Deprecated public static int hash(double a, double b, double c)
a
- value to be hashedb
- value to be hashedc
- value to be hashed@Deprecated public static int hash(double[] a)
a
- value to be hashed@Deprecated public static int hash(long l)
Long.hashCode()
Long.hashCode()
. A problem with Long.hashCode()
is that it maps -1 and 0 to the same
value, 0.l
- value to be hashed@Deprecated public static int hash(long a, long b)
a
- value to be hashedb
- value to be hashed@Deprecated public static int hash(long a, long b, long c)
a
- value to be hashedb
- value to be hashedc
- value to be hashed@Deprecated public static int hash(long[] a)
a
- value to be hashed@Deprecated public static int hash(@Nullable java.lang.String a)
a
- value to be hashed@Deprecated public static int hash(@Nullable java.lang.String a, @Nullable java.lang.String b)
a
- value to be hashedb
- value to be hashed@Deprecated public 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 hashed@Deprecated public static int hash(@Nullable java.lang.String[] a)
a
- value to be hashed@Deprecated public static java.lang.String mapToStringAndClass(java.util.Map<?,?> m)
m
- a map@Deprecated public static java.lang.String toStringAndClass(@Nullable java.lang.Object o)
o
- an objectpublic 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 stream@Deprecated public 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 replacement@Deprecated public static java.lang.String replacePrefix(java.lang.String target, java.lang.String oldStr, java.lang.String newStr)
An alternative to this is to use regular expressions: target.replaceFirst("^" +
Pattern.quote(oldStr), newStr)
target
- the string to do replacement inoldStr
- the prefix to replacenewStr
- the replacement@Deprecated public static java.lang.String replaceSuffix(java.lang.String target, java.lang.String oldStr, java.lang.String newStr)
An alternative to this is to use regular expressions: target.replaceLast(Pattern.quote(oldStr) + "$", newStr)
target
- the string to do replacement inoldStr
- the substring to replacenewStr
- the replacement@Deprecated public static java.lang.String prefixLines(java.lang.String prefix, @Nullable java.lang.Object o)
prefix
- the prefix to place before each lineo
- the value to be printedo
, with each line prefixed by the given prefix@Deprecated public static java.lang.String prefixLinesExceptFirst(java.lang.String prefix, @Nullable java.lang.Object o)
prefix
- the prefix to place before each lineo
- the value to be printedo
, with each line (except the first) prefixed by
the given prefix@Deprecated public static java.lang.String indentLines(@NonNegative int indent, @Nullable java.lang.Object o)
indent
spaces.indent
- the number of spaces to indento
- the value whose printed representation string to increase indentation ofo
, with each line prefixed by indent
space characters@Deprecated public static java.lang.String indentLinesExceptFirst(@NonNegative int indent, @Nullable java.lang.Object o)
indent
spaces.indent
- the number of spaces to indento
- the value whose printed representation string to increase indentation ofo
, with each line (except the first) prefixed by
indent
space characters@Deprecated public static java.lang.String[] split(java.lang.String s, char delim)
Consider using the built-in String.split method, which takes a regular expression whereas this method takes a string.
s
- the string to splitdelim
- delimiter to split the string onsplit(String s, String delim)
@Deprecated 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 @StaticallyExecutable @Deprecated public static java.lang.String[] splitLines(java.lang.String s)
s
- the string to splitsplit(String s, char delim)
@Deprecated public static <T> java.lang.String join(T[] a, java.lang.CharSequence delim)
join(CharSequence, Object...)
which has the arguments in the other
orderThis differs from the built-in String.join()
method added in Java 8, in that this
takes an array of Objects but that method takes an array of CharSequences. Use the Java 8
String.join()
method when the arguments are CharSequences.
T
- the type of array elementsa
- array of values to concatenatedelim
- delimiter to place between printed representations@SafeVarargs @Deprecated public static <T> java.lang.String join(java.lang.CharSequence delim, T... a)
This differs from the built-in String.join()
method added in Java 8, in that this
takes any arbitrary array but that method takes an array of CharSequences. Use the String
method when the arguments are CharSequences.
T
- the type of array elementsa
- array of values to concatenatedelim
- delimiter to place between printed representations@SafeVarargs @Deprecated public static <T> java.lang.String joinLines(T... a)
T
- the type of array elementsa
- array of values to whose string representation to concatenate@Deprecated public static java.lang.String join(java.lang.Iterable<?> v, java.lang.CharSequence delim)
join(CharSequence, Iterable)
which has the arguments in the other
orderThis differs from the String.join()
method added in Java 8, in that this takes any
array but that method takes an array of CharSequences.
v
- collection of values to concatenatedelim
- delimiter to place between printed representationsAbstractCollection.toString()
@Deprecated public static java.lang.String join(java.lang.CharSequence delim, java.lang.Iterable<?> v)
This differs from the String.join()
method added in Java 8, in that this takes any
Iterable but that method takes only Iterable<? extends CharSequence>
.
v
- collection of values to concatenatedelim
- delimiter to place between printed representationsAbstractCollection.toString()
@Deprecated public static java.lang.String joinLines(java.lang.Iterable<?> v)
v
- list of values to concatenateAbstractCollection.toString()
@Deprecated public static java.lang.String escapeNonJava(java.lang.String orig)
escapeJava(String)
orig
- string to quote@Deprecated public static java.lang.String escapeJava(java.lang.String orig)
Returns a new string only if any modifications were necessary.
Compared to the `escapeJava` method in Apache Commons Text StringEscapeUtils, this one correctly handles non-printable ASCII characters.
orig
- string to quote@Deprecated public static java.lang.String escapeNonJava(java.lang.Character ch)
escapeJava(Character)
ch
- character to quote@Deprecated public static java.lang.String escapeJava(java.lang.Character ch)
escapeJava(String)
, but for a single character.ch
- character to quote@Deprecated public static java.lang.String escapeJava(char c)
escapeJava(String)
, but for a single character.c
- character to quote@Deprecated public static java.lang.String escapeNonASCII(java.lang.String orig)
orig
- string to quote@Deprecated public static java.lang.String unescapeNonJava(java.lang.String orig)
unescapeJava(String)
escapeJava(java.lang.String)
, but it is
not a general unescaping mechanism for Java strings.
Compared to the `unescapeJava` method in Apache Commons Text StringEscapeUtils, this one correctly handles non-printable ASCII characters.
orig
- string to quote@Deprecated public static java.lang.String unescapeJava(java.lang.String orig)
escapeJava(java.lang.String)
, but it is
not a general unescaping mechanism for Java strings.
Compared to the `unescapeJava` method in Apache Commons Text StringEscapeUtils, this one correctly handles non-printable ASCII characters.
orig
- string to quote@Deprecated public static java.lang.String removeWhitespaceAround(java.lang.String arg, java.lang.String delimiter)
arg
- string to remove whitespace indelimiter
- string to remove whitespace abutting@Deprecated public static java.lang.String removeWhitespaceAfter(java.lang.String arg, java.lang.String delimiter)
arg
- string to remove whitespace indelimiter
- string to remove whitespace after@Deprecated public static java.lang.String removeWhitespaceBefore(java.lang.String arg, java.lang.String delimiter)
arg
- string to remove whitespace indelimiter
- string to remove whitespace before@Deprecated public static java.lang.String nplural(int n, java.lang.String noun)
n
- count of nounsnoun
- word being counted@Deprecated public static java.lang.String lpad(java.lang.String s, @NonNegative int length)
s
- string to truncate or padlength
- goal length@Deprecated public static java.lang.String rpad(java.lang.String s, @NonNegative int length)
s
- string to truncate or padlength
- goal length@Deprecated public static java.lang.String rpad(int num, @NonNegative int length)
rpad(String,int)
.num
- int whose string representation to truncate or padlength
- goal length@Deprecated public static java.lang.String rpad(double num, @NonNegative int length)
rpad(String,int)
.num
- double whose string representation to truncate or padlength
- goal length@Deprecated public static int count(java.lang.String s, int ch)
s
- string to search inch
- character to search for@Deprecated public static int count(java.lang.String s, java.lang.String sub)
s
- string to search insub
- non-empty string to search for@Deprecated public static java.lang.String abbreviateNumber(long val)
val
- a numeric value@Deprecated public static int countFormatArguments(java.lang.String s)
%n
and %%
, do not take arguments).s
- a string@Deprecated public 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 tokens@Deprecated public 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 delimiters@Deprecated public static java.util.ArrayList<java.lang.Object> tokens(java.lang.String str)
StringTokenizer.StringTokenizer(String)
with the given arguments.str
- a string to be parsed@Deprecated public static void sleep(long millis)
SystemPlume.sleep(long)
millis
- the length of time to sleep in milliseconds@Deprecated public static long usedMemory()
SystemPlume.usedMemory()
To force a garbage collection, which gives a more accurate overapproximation of the memory
used, but is also slower, use usedMemory(boolean)
@Deprecated public static long usedMemory(boolean forceGc)
SystemPlume.usedMemory(boolean)
forceGc
- if true, force a garbage collection, which gives a more accurate
overapproximation of the memory used, but is also slower@Deprecated public static void gc()
SystemPlume.gc()
@Deprecated public static java.lang.String backTrace(java.lang.Throwable t)
stackTraceToString(java.lang.Throwable)
backtrace(new Throwable())
.t
- the Throwable to obtain a backtrace ofpublic static java.lang.String stackTraceToString(java.lang.Throwable t)
stackTraceToString(new Throwable())
.t
- the Throwable to obtain a stack trace of