Class UtilPlume

java.lang.Object
org.plumelib.util.UtilPlume

public final class UtilPlume extends Object
Utility methods that do not belong elsewhere in the plume package: BitSet; hashing; ProcessBuilder; properties; Throwable.
  • Method Details

    • clone

      public static <T> @PolyNull @PolySigned T clone(@PolyNull @PolySigned T data)
      Clones the given object by calling clone() reflectively. It is not possible to call Object.clone() directly because it has protected visibility.
      Type Parameters:
      T - the type of the object to clone
      Parameters:
      data - the object to clone
      Returns:
      a clone of the object
    • firstNonNull

      public static <T> T firstNonNull(T first, T second)
      Return the first argument if it is non-null, otherwise return the second argument. Throws an exception if both arguments are null.
      Type Parameters:
      T - the type of the arguments
      Parameters:
      first - a reference
      second - a reference
      Returns:
      the first argument that is non-null
    • intersectionCardinalityAtLeast

      @Deprecated @Pure public static boolean intersectionCardinalityAtLeast(BitSet a, BitSet b, @org.checkerframework.checker.index.qual.NonNegative int i)
      Deprecated.
      use CollectionsPlume.intersectionCardinalityAtLeast
      Returns true if the cardinality of the intersection of the two BitSets is at least the given value.
      Parameters:
      a - the first BitSet to intersect
      b - the second BitSet to intersect
      i - the cardinality bound
      Returns:
      true iff size(a intersect b) ≥ i
    • intersectionCardinalityAtLeast

      @Deprecated @Pure public static boolean intersectionCardinalityAtLeast(BitSet a, BitSet b, BitSet c, @org.checkerframework.checker.index.qual.NonNegative int i)
      Deprecated.
      use CollectionsPlume.intersectionCardinalityAtLeast
      Returns true if the cardinality of the intersection of the three BitSets is at least the given value.
      Parameters:
      a - the first BitSet to intersect
      b - the second BitSet to intersect
      c - the third BitSet to intersect
      i - the cardinality bound
      Returns:
      true iff size(a intersect b intersect c) ≥ i
    • intersectionCardinality

      @Deprecated @Pure public static int intersectionCardinality(BitSet a, BitSet b)
      Deprecated.
      use CollectionsPlume.intersectionCardinality
      Returns the cardinality of the intersection of the two BitSets.
      Parameters:
      a - the first BitSet to intersect
      b - the second BitSet to intersect
      Returns:
      size(a intersect b)
    • intersectionCardinality

      @Deprecated @Pure public static int intersectionCardinality(BitSet a, BitSet b, BitSet c)
      Deprecated.
      use CollectionsPlume.intersectionCardinality
      Returns the cardinality of the intersection of the three BitSets.
      Parameters:
      a - the first BitSet to intersect
      b - the second BitSet to intersect
      c - the third BitSet to intersect
      Returns:
      size(a intersect b intersect c)
    • fileInputStream

      @Deprecated public static InputStream fileInputStream(Path path) throws IOException
      Returns an InputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      path - the possibly-compressed file to read
      Returns:
      an InputStream for file
      Throws:
      IOException - if there is trouble reading the file
    • fileInputStream

      @Deprecated public static InputStream fileInputStream(File file) throws IOException
      Returns an InputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      file - the possibly-compressed file to read
      Returns:
      an InputStream for file
      Throws:
      IOException - if there is trouble reading the file
    • fileReader

      @Deprecated public static InputStreamReader fileReader(String filename) throws FileNotFoundException, IOException
      Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to read
      Returns:
      an InputStream for filename
      Throws:
      IOException - if there is trouble reading the file
      FileNotFoundException - if the file is not found
    • fileReader

      @Deprecated public static InputStreamReader fileReader(Path path) throws FileNotFoundException, IOException
      Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      path - the possibly-compressed file to read
      Returns:
      an InputStreamReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • fileReader

      @Deprecated public static InputStreamReader fileReader(Path path, @Nullable String charsetName) throws FileNotFoundException, IOException
      Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      path - the possibly-compressed file to read
      charsetName - null, or the name of a Charset to use when reading the file
      Returns:
      an InputStreamReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • fileReader

      @Deprecated public static InputStreamReader fileReader(File file) throws FileNotFoundException, IOException
      Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      file - the possibly-compressed file to read
      Returns:
      an InputStreamReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • fileReader

      @Deprecated public static InputStreamReader fileReader(File file, @Nullable String charsetName) throws FileNotFoundException, IOException
      Returns a Reader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      file - the possibly-compressed file to read
      charsetName - null, or the name of a Charset to use when reading the file
      Returns:
      an InputStreamReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • bufferedFileReader

      @Deprecated public static BufferedReader bufferedFileReader(String filename) throws FileNotFoundException, IOException
      Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to read
      Returns:
      a BufferedReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • bufferedFileReader

      @Deprecated public static BufferedReader bufferedFileReader(File file) throws FileNotFoundException, IOException
      Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      file - the possibility-compressed file to read
      Returns:
      a BufferedReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • bufferedFileReader

      @Deprecated public static BufferedReader bufferedFileReader(String filename, @Nullable String charsetName) throws FileNotFoundException, IOException
      Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to read
      charsetName - the character set to use when reading the file
      Returns:
      a BufferedReader for filename
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • bufferedFileReader

      @Deprecated public static BufferedReader bufferedFileReader(File file, @Nullable String charsetName) throws FileNotFoundException, IOException
      Returns a BufferedReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      file - the possibly-compressed file to read
      charsetName - the character set to use when reading the file
      Returns:
      a BufferedReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • lineNumberFileReader

      @Deprecated public static LineNumberReader lineNumberFileReader(String filename) throws FileNotFoundException, IOException
      Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to read
      Returns:
      a LineNumberReader for filename
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • lineNumberFileReader

      @Deprecated public static LineNumberReader lineNumberFileReader(File file) throws FileNotFoundException, IOException
      Returns a LineNumberReader for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      file - the possibly-compressed file to read
      Returns:
      a LineNumberReader for file
      Throws:
      FileNotFoundException - if the file cannot be found
      IOException - if there is trouble reading the file
    • bufferedFileWriter

      @Deprecated public static BufferedWriter bufferedFileWriter(String filename) throws IOException
      Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to write
      Returns:
      a BufferedWriter for filename
      Throws:
      IOException - if there is trouble writing the file
    • bufferedFileWriter

      @Deprecated public static BufferedWriter bufferedFileWriter(String filename, boolean append) throws IOException
      Returns a BufferedWriter for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to write
      append - if true, the resulting BufferedWriter appends to the end of the file instead of the beginning
      Returns:
      a BufferedWriter for filename
      Throws:
      IOException - if there is trouble writing the file
    • bufferedFileOutputStream

      @Deprecated public static BufferedOutputStream bufferedFileOutputStream(String filename, boolean append) throws IOException
      Returns a BufferedOutputStream for the file, accounting for the possibility that the file is compressed. (A file whose name ends with ".gz" is treated as compressed.)

      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.

      Parameters:
      filename - the possibly-compressed file to write
      append - if true, the resulting BufferedOutputStream appends to the end of the file instead of the beginning
      Returns:
      a BufferedOutputStream for filename
      Throws:
      IOException - if there is trouble writing the file
    • countLines

      @Deprecated public static long countLines(String filename) throws IOException
      Count the number of lines in the specified file.
      Parameters:
      filename - file whose size to count
      Returns:
      number of lines in filename
      Throws:
      IOException - if there is trouble reading the file
    • fileLines

      @Deprecated public static List<String> fileLines(String filename) throws IOException
      Returns the contents of the file, as a list of strings, one per line. The lines do not include any line termination characters.
      Parameters:
      filename - the file whose contents to return
      Returns:
      the contents of filename, one string per line
      Throws:
      IOException - if there was a problem reading the file
    • inferLineSeparator

      @Deprecated public static String inferLineSeparator(String filename) throws IOException
      Tries to infer the line separator used in a file.
      Parameters:
      filename - the file to infer a line separator from
      Returns:
      the inferred line separator used in filename
      Throws:
      IOException - if there is trouble reading the file
    • inferLineSeparator

      @Deprecated public static String inferLineSeparator(File file) throws IOException
      Tries to infer the line separator used in a file.
      Parameters:
      file - the file to infer a line separator from
      Returns:
      the inferred line separator used in filename
      Throws:
      IOException - if there is trouble reading the file
    • equalFiles

      @Deprecated @Pure public static boolean equalFiles(String file1, String file2)
      Returns true iff files have the same contents.
      Parameters:
      file1 - first file to compare
      file2 - second file to compare
      Returns:
      true iff the files have the same contents
    • equalFiles

      @Deprecated @Pure public static boolean equalFiles(String file1, String file2, boolean trimLines)
      Returns true iff the files have the same contents.
      Parameters:
      file1 - first file to compare
      file2 - second file to compare
      trimLines - if true, call String.trim on each line before comparing
      Returns:
      true iff the files have the same contents
    • canCreateAndWrite

      @Deprecated public static boolean canCreateAndWrite(File file)
      Returns true if the file exists and is writable, or if the file can be created.
      Parameters:
      file - the file to create and write
      Returns:
      true iff the file can be created and written
    • createTempDir

      @Deprecated public static File createTempDir(String prefix, String suffix) throws IOException
      Creates an empty directory in the default temporary-file directory, using the given prefix and suffix to generate its name. For example, calling createTempDir("myPrefix", "mySuffix") will create the following directory: temporaryFileDirectory/myUserName/myPrefix_someString_suffix. someString is internally generated to ensure no temporary files of the same name are generated.
      Parameters:
      prefix - the prefix string to be used in generating the file's name; must be at least three characters long
      suffix - 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 file
      Returns:
      a File representing the newly-created temporary directory
      Throws:
      IllegalArgumentException - If the prefix argument contains fewer than three characters
      IOException - If a file could not be created
      SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not allow a file to be created
      See Also:
    • deleteDir

      @Deprecated public static boolean deleteDir(String dirName)
      Deletes the directory at dirName and all its files. Also works on regular files.
      Parameters:
      dirName - the directory to delete
      Returns:
      true if and only if the file or directory is successfully deleted; false otherwise
    • deleteDir

      @Deprecated public static boolean deleteDir(File dir)
      Deletes the directory at dir and all its files. Also works on regular files.
      Parameters:
      dir - the directory to delete
      Returns:
      true if and only if the file or directory is successfully deleted; false otherwise
    • expandFilename

      @Deprecated public static File expandFilename(File name)
      Does tilde expansion on a file name (to the user's home directory).
      Parameters:
      name - file whose name to expand
      Returns:
      file with expanded file
    • expandFilename

      @Deprecated public static String expandFilename(String name)
      Does tilde expansion on a file name (to the user's home directory).
      Parameters:
      name - filename to expand
      Returns:
      expanded filename
    • javaSource

      @Deprecated public static String javaSource(File name)
      Returns a string version of the filename that can be used in Java source. On Windows, the file will return a backslash separated string. Since backslash is an escape character, it must be quoted itself inside the string.

      The current implementation presumes that backslashes don't appear in filenames except as windows path separators. That seems like a reasonable assumption.

      Parameters:
      name - file whose name to quote
      Returns:
      a string version of the name that can be used in Java source
    • writeObject

      @Deprecated public static void writeObject(Object o, File file) throws IOException
      Writes an Object to a File.
      Parameters:
      o - the object to write
      file - the file to which to write the object
      Throws:
      IOException - if there is trouble writing the file
    • readObject

      @Deprecated public static Object readObject(File file) throws IOException, ClassNotFoundException
      Reads an Object from a File. This is a wrapper around ObjectInputStream.readObject(), but it takes a File as an argument. Note that use of that method can lead to security vulnerabilities.
      Parameters:
      file - the file from which to read
      Returns:
      the object read from the file
      Throws:
      IOException - if there is trouble reading the file
      ClassNotFoundException - if the object's class cannot be found
    • readerContents

      @Deprecated public static String readerContents(Reader r)
      Reads the entire contents of the reader and returns it as a string. Any IOException encountered will be turned into an Error.
      Parameters:
      r - the Reader to read
      Returns:
      the entire contents of the reader, as a string
    • readFile

      @Deprecated public static String readFile(File file)
      Reads the entire contents of the file and returns it as a string. Any IOException encountered will be turned into an Error.

      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.

      Parameters:
      file - the file to read
      Returns:
      the entire contents of the reader, as a string
    • writeFile

      @Deprecated public static void writeFile(File file, String contents)
      Creates a file with the given name and writes the specified string to it. If the file currently exists (and is writable) it is overwritten Any IOException encountered will be turned into an Error.
      Parameters:
      file - the file to write to
      contents - the text to put in the file
    • hash

      public static int hash(double @Nullable [] a, double @Nullable [] b)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      public static int hash(long @Nullable [] a, long @Nullable [] b)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(double x)
      Deprecated.
      Returns a hash of the arguments. Note that this differs from the result of Double.hashCode().
      Parameters:
      x - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(double a, double b)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(double a, double b, double c)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      c - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(double @Nullable [] a)
      Deprecated.
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(long l)
      Deprecated.
      Returns a hash of the arguments. Note that this differs from the result of Long.hashCode(). A problem with Long.hashCode() is that it maps -1 and 0 to the same value, 0.
      Parameters:
      l - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(long a, long b)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(long a, long b, long c)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      c - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(long @Nullable [] a)
      Deprecated.
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(@Nullable String a)
      Deprecated.
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(@Nullable String a, @Nullable String b)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(@Nullable String a, @Nullable String b, @Nullable String c)
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      b - value to be hashed
      c - value to be hashed
      Returns:
      a hash of the arguments
    • hash

      @Deprecated public static int hash(@Nullable String @Nullable [] a)
      Deprecated.
      Returns a hash of the arguments.
      Parameters:
      a - value to be hashed
      Returns:
      a hash of the arguments
    • mapToStringAndClass

      @Deprecated public static String mapToStringAndClass(Map<? extends @Signed @PolyNull Object,? extends @Signed @PolyNull Object> m)
      Convert a map to a string, printing the runtime class of keys and values.
      Parameters:
      m - a map
      Returns:
      a string representation of the map
    • toStringAndClass

      @Deprecated public static String toStringAndClass(@Nullable Object o)
      Returns a string representation of a value and its run-time class.
      Parameters:
      o - an object
      Returns:
      a string representation of the value and its run-time class
    • backticks

      public static String backticks(String... command)
      Execute the given command, and return all its output as a string.
      Parameters:
      command - a command to execute on the command line
      Returns:
      all the output of the command
    • backticks

      public static String backticks(List<String> command)
      Execute the given command, and return all its output as a string.
      Parameters:
      command - a command to execute on the command line, as a list of strings (the command, then its arguments)
      Returns:
      all the output of the command
    • propertyIsTrue

      @Pure @Deprecated public static boolean propertyIsTrue(Properties p, String key)
      Determines whether a property has value "true", "yes", or "1".
      Parameters:
      p - a Properties object in which to look up the property
      key - name of the property to look up
      Returns:
      true iff the property has value "true", "yes", or "1"
      See Also:
    • getBooleanProperty

      @Pure public static boolean getBooleanProperty(Properties p, String key, boolean defaultValue)
      Determines whether a property has a string value that represents true: "true", "yes", or "1". Errs if the property is set to a value that is not one of "true", "false", "yes", "no", "1", or "0".
      Parameters:
      p - a Properties object in which to look up the property
      key - name of the property to look up
      defaultValue - the value to return if the property is not set
      Returns:
      true iff the property has value "true", "yes", or "1"
      See Also:
    • getBooleanProperty

      @Pure public static boolean getBooleanProperty(Properties p, String key)
      Determines whether a property has a string value that represents true: "true", "yes", or "1". Errs if the property is set to a value that is not one of "true", "false", "yes", "no", "1", or "0".
      Parameters:
      p - a Properties object in which to look up the property
      key - name of the property to look up
      Returns:
      true iff the property has value "true", "yes", or "1"
      See Also:
    • appendProperty

      public static @Nullable String appendProperty(Properties p, String key, String value)
      Set the property to its previous value concatenated to the given value. Return the previous value.
      Parameters:
      p - a Properties object in which to look up the property
      key - name of the property to look up
      value - value to concatenate to the previous value of the property
      Returns:
      the previous value of the property
      See Also:
    • setDefaultMaybe

      public static @Nullable String setDefaultMaybe(Properties p, String key, String value)
      Set the property only if it was not previously set.
      Parameters:
      p - a Properties object in which to look up the property
      key - name of the property to look up
      value - value to set the property to, if it is not already set
      Returns:
      the previous value of the property
      See Also:
    • streamCopy

      @Deprecated public static void streamCopy(InputStream from, OutputStream to)
      Copy the contents of the input stream to the output stream.
      Parameters:
      from - input stream
      to - output stream
    • streamString

      @Deprecated public static String streamString(InputStream is)
      Returns a String containing all the characters from the input stream.
      Parameters:
      is - input stream to read
      Returns:
      a String containing all the characters from the input stream
    • streamLines

      @Deprecated public static List<String> streamLines(InputStream stream) throws IOException
      Reads all lines from the stream and returns them in a List<String>.
      Parameters:
      stream - the stream to read from
      Returns:
      the list of lines read from the stream
      Throws:
      IOException - if there is an error reading from the stream
    • replaceString

      @Deprecated public static String replaceString(String target, String oldStr, String newStr)
      Returns a new string which is the text of target with all instances of oldStr replaced by newStr.
      Parameters:
      target - the string to do replacement in
      oldStr - the substring to replace
      newStr - the replacement
      Returns:
      target with all instances of oldStr replaced by newStr
    • replacePrefix

      @Deprecated public static String replacePrefix(String target, String oldStr, String newStr)
      Returns the target with an occurrence of oldStr at the start replaced by newStr. Returns the target if it does not strt with oldStr.

      An alternative to this is to use regular expressions: target.replaceFirst("^" + Pattern.quote(oldStr), newStr)

      Parameters:
      target - the string to do replacement in
      oldStr - the prefix to replace
      newStr - the replacement
      Returns:
      the target with an occurrence of oldStr at the start replaced by newStr; returns the target if it does not start with oldStr
    • replaceSuffix

      @Deprecated public static String replaceSuffix(String target, String oldStr, String newStr)
      Returns the target with an occurrence of oldStr at the end replaced by newStr. Returns the target if it does not end with oldStr.

      An alternative to this is to use regular expressions: target.replaceLast(Pattern.quote(oldStr) + "$", newStr)

      Parameters:
      target - the string to do replacement in
      oldStr - the substring to replace
      newStr - the replacement
      Returns:
      the target with an occurrence of oldStr at the start replaced by newStr; returns the target if it does not start with oldStr
    • prefixLines

      @Deprecated public static String prefixLines(String prefix, @Nullable Object o)
      Returns the printed represenation of a value, with each line prefixed by another string.
      Parameters:
      prefix - the prefix to place before each line
      o - the value to be printed
      Returns:
      the printed representation of o, with each line prefixed by the given prefix
    • prefixLinesExceptFirst

      @Deprecated public static String prefixLinesExceptFirst(String prefix, @Nullable Object o)
      Returns the printed represenation of a value, with each line (except the first) prefixed by another string.
      Parameters:
      prefix - the prefix to place before each line
      o - the value to be printed
      Returns:
      the printed representation of o, with each line (except the first) prefixed by the given prefix
    • indentLines

      @Deprecated public static String indentLines(@org.checkerframework.checker.index.qual.NonNegative int indent, @Nullable Object o)
      Returns the printed representation of a value, with each line indented by indent spaces.
      Parameters:
      indent - the number of spaces to indent
      o - the value whose printed representation string to increase indentation of
      Returns:
      the printed representation of o, with each line prefixed by indent space characters
    • indentLinesExceptFirst

      @Deprecated public static String indentLinesExceptFirst(@org.checkerframework.checker.index.qual.NonNegative int indent, @Nullable Object o)
      Returns the printed representation of a value, with each line (except the first) indented by indent spaces.
      Parameters:
      indent - the number of spaces to indent
      o - the value whose printed representation string to increase indentation of
      Returns:
      the printed representation of o, with each line (except the first) prefixed by indent space characters
    • split

      @Deprecated public static String[] split(String s, char delim)
      Returns an array of Strings representing the characters between successive instances of the delimiter character. Always returns an array of length at least 1 (it might contain only the empty string).

      Consider using the built-in String.split method, which takes a regular expression whereas this method takes a a character that is interpreted literally.

      Parameters:
      s - the string to split
      delim - delimiter to split the string on
      Returns:
      array of length at least 1, containing s split on delimiter
      See Also:
    • split

      @Deprecated public static String[] split(String s, String delim)
      Returns an array of Strings representing the characters between successive instances of the delimiter String. Always returns an array of length at least 1 (it might contain only the empty string).

      Consider using the built-in String.split method, method, which takes a regular expression whereas this method takes string.

      Parameters:
      s - the string to split
      delim - delimiter to split the string on
      Returns:
      array of length at least 1, containing s split on delimiter
      See Also:
    • splitLines

      @SideEffectFree @StaticallyExecutable @Deprecated public static String[] splitLines(String s)
      Returns an array of Strings, one for each line in the argument. Always returns an array of length at least 1 (it might contain only the empty string). All common line separators (cr, lf, cr-lf, or lf-cr) are supported. Note that a string that ends with a line separator will return an empty string as the last element of the array.
      Parameters:
      s - the string to split
      Returns:
      an array of Strings, one for each line in the argument
      See Also:
    • join

      @Deprecated public static <T> String join(@Signed T[] a, CharSequence delim)
      Deprecated.
      use join(CharSequence, Object...) which has the arguments in the other order
      Concatenate the string representations of the array elements, placing the delimiter between them.

      This 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.

      Type Parameters:
      T - the type of array elements
      Parameters:
      a - array of values to concatenate
      delim - delimiter to place between printed representations
      Returns:
      the concatenation of the string representations of the values, with the delimiter between
    • join

      @Deprecated @SafeVarargs public static <T> String join(CharSequence delim, @Signed T... a)
      Concatenate the string representations of the array elements, placing the delimiter between them.

      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.

      Type Parameters:
      T - the type of array elements
      Parameters:
      a - array of values to concatenate
      delim - delimiter to place between printed representations
      Returns:
      the concatenation of the string representations of the values, with the delimiter between
    • joinLines

      @SafeVarargs @Deprecated public static <T> String joinLines(@Signed T... a)
      Concatenate the string representations of the objects, placing the system-specific line separator between them.
      Type Parameters:
      T - the type of array elements
      Parameters:
      a - array of values to whose string representation to concatenate
      Returns:
      the concatenation of the string representations of the values, each on its own line
    • join

      @Deprecated public static String join(Iterable<? extends @Signed @PolyNull Object> v, CharSequence delim)
      Deprecated.
      use join(CharSequence, Iterable) which has the arguments in the other order
      Concatenate the string representations of the objects, placing the delimiter between them.

      This differs from the String.join() method added in Java 8, in that this takes any array but that method takes an array of CharSequences.

      Parameters:
      v - collection of values to concatenate
      delim - delimiter to place between printed representations
      Returns:
      the concatenation of the string representations of the values, with the delimiter between
      See Also:
    • join

      @Deprecated public static String join(CharSequence delim, Iterable<? extends @Signed @PolyNull Object> v)
      Concatenate the string representations of the objects, placing the delimiter between them.

      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>.

      Parameters:
      v - collection of values to concatenate
      delim - delimiter to place between printed representations
      Returns:
      the concatenation of the string representations of the values, with the delimiter between
      See Also:
    • joinLines

      @Deprecated public static String joinLines(Iterable<? extends @Signed @PolyNull Object> v)
      Concatenate the string representations of the objects, placing the system-specific line separator between them.
      Parameters:
      v - list of values to concatenate
      Returns:
      the concatenation of the string representations of the values, each on its own line
      See Also:
    • escapeNonJava

      @Deprecated public static String escapeNonJava(String orig)
      Deprecated.
      Parameters:
      orig - string to quote
      Returns:
      quoted version of orig
    • escapeJava

      @Deprecated public static String escapeJava(String orig)
      Escapes a String so that it is expressible in Java source code. By surrounding the return value with double quote marks, the result will be a Java string literal denoting the original string.

      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.

      Parameters:
      orig - string to quote
      Returns:
      quoted version of orig
    • escapeNonJava

      @Deprecated public static String escapeNonJava(Character ch)
      Deprecated.
      Parameters:
      ch - character to quote
      Returns:
      quoted version of ch
    • escapeJava

      @Deprecated public static String escapeJava(Character ch)
      Like escapeJava(String), but for a single character.
      Parameters:
      ch - character to quote
      Returns:
      quoted version of ch
    • escapeJava

      @Deprecated public static String escapeJava(char c)
      Like escapeJava(String), but for a single character.
      Parameters:
      c - character to quote
      Returns:
      quoted version of ch
    • escapeNonASCII

      @Deprecated public static String escapeNonASCII(String orig)
      Escape unprintable characters in the target, following the usual Java backslash conventions, so that the result is sure to be printable ASCII. Returns a new string.
      Parameters:
      orig - string to quote
      Returns:
      quoted version of orig
    • unescapeNonJava

      @Deprecated public static String unescapeNonJava(String orig)
      Deprecated.
      Convert a string from Java source code format (with escape sequences) into the string it would represent at run time. This is the inverse operation of 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.

      Parameters:
      orig - string to quote
      Returns:
      quoted version of orig
    • unescapeJava

      @Deprecated public static String unescapeJava(String orig)
      Convert a string from Java source code format (with escape sequences) into the string it would represent at run time. This is the inverse operation of 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.

      Parameters:
      orig - string to quote
      Returns:
      quoted version of orig
    • removeWhitespaceAround

      @Deprecated public static String removeWhitespaceAround(String arg, String delimiter)
      Remove all whitespace before or after instances of delimiter.
      Parameters:
      arg - string to remove whitespace in
      delimiter - string to remove whitespace abutting
      Returns:
      version of arg, with whitespace abutting delimiter removed
    • removeWhitespaceAfter

      @Deprecated public static String removeWhitespaceAfter(String arg, String delimiter)
      Remove all whitespace after instances of delimiter.
      Parameters:
      arg - string to remove whitespace in
      delimiter - string to remove whitespace after
      Returns:
      version of arg, with whitespace after delimiter removed
    • removeWhitespaceBefore

      @Deprecated public static String removeWhitespaceBefore(String arg, String delimiter)
      Remove all whitespace before instances of delimiter.
      Parameters:
      arg - string to remove whitespace in
      delimiter - string to remove whitespace before
      Returns:
      version of arg, with whitespace before delimiter removed
    • nplural

      @Deprecated public static String nplural(int n, String noun)
      Returns either "n noun" or "n nouns" depending on n. Adds "es" to words ending with "ch", "s", "sh", or "x".
      Parameters:
      n - count of nouns
      noun - word being counted
      Returns:
      noun, if n==1; otherwise, pluralization of noun
    • lpad

      @Deprecated public static String lpad(String s, @org.checkerframework.checker.index.qual.NonNegative int length)
      Returns a string of the specified length, truncated if necessary, and padded with spaces to the left if necessary.
      Parameters:
      s - string to truncate or pad
      length - goal length
      Returns:
      s truncated or padded to length characters
    • rpad

      @Deprecated public static String rpad(String s, @org.checkerframework.checker.index.qual.NonNegative int length)
      Returns a string of the specified length, truncated if necessary, and padded with spaces to the right if necessary.
      Parameters:
      s - string to truncate or pad
      length - goal length
      Returns:
      s truncated or padded to length characters
    • rpad

      @Deprecated public static String rpad(int num, @org.checkerframework.checker.index.qual.NonNegative int length)
      Converts the int to a String, then formats it using rpad(String,int).
      Parameters:
      num - int whose string representation to truncate or pad
      length - goal length
      Returns:
      a string representation of num truncated or padded to length characters
    • rpad

      @Deprecated public static String rpad(double num, @org.checkerframework.checker.index.qual.NonNegative int length)
      Converts the double to a String, then formats it using rpad(String,int).
      Parameters:
      num - double whose string representation to truncate or pad
      length - goal length
      Returns:
      a string representation of num truncated or padded to length characters
    • count

      @Deprecated public static int count(String s, int ch)
      Returns the number of times the character appears in the string.
      Parameters:
      s - string to search in
      ch - character to search for
      Returns:
      number of times the character appears in the string
    • count

      @Deprecated public static int count(String s, String sub)
      Returns the number of times the second string appears in the first.
      Parameters:
      s - string to search in
      sub - non-empty string to search for
      Returns:
      number of times the substring appears in the string
    • abbreviateNumber

      @Deprecated public static String abbreviateNumber(long val)
      Convert a number into an abbreviation such as "5.00K" for 5000 or "65.0M" for 65000000. K stands for 1000, not 1024; M stands for 1000000, not 1048576, etc. There are always exactly 3 decimal digits of precision in the result (counting both sides of the decimal point).
      Parameters:
      val - a numeric value
      Returns:
      an abbreviated string representation of the value
    • countFormatArguments

      @Deprecated public static int countFormatArguments(String s)
      Returns the number of arguments that the given format string takes. This is the number of specifiers that take arguments (some, like %n and %%, do not take arguments).
      Parameters:
      s - a string
      Returns:
      the number of format specifiers in the string
    • tokens

      @Deprecated public static ArrayList<Object> tokens(String str, String delim, boolean returnDelims)
      Returns a ArrayList of the Strings returned by 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).

      Parameters:
      str - a string to be parsed
      delim - the delimiters
      returnDelims - flag indicating whether to return the delimiters as tokens
      Returns:
      vector of strings resulting from tokenization
    • tokens

      @Deprecated public static ArrayList<Object> tokens(String str, String delim)
      Returns a ArrayList of the Strings returned by StringTokenizer(String,String) with the given arguments.
      Parameters:
      str - a string to be parsed
      delim - the delimiters
      Returns:
      vector of strings resulting from tokenization
    • tokens

      @Deprecated public static ArrayList<Object> tokens(String str)
      Returns a ArrayList of the Strings returned by StringTokenizer(String) with the given arguments.
      Parameters:
      str - a string to be parsed
      Returns:
      vector of strings resulting from tokenization
    • sleep

      @Deprecated public static void sleep(long millis)
      Deprecated.
      Like Thread.sleep, but does not throw any checked exceptions, so it is easier for clients to use. Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds.
      Parameters:
      millis - the length of time to sleep in milliseconds
    • usedMemory

      @Deprecated public static long usedMemory()
      Deprecated.
      Returns the amount of used memory in the JVM.

      To force a garbage collection, which gives a more accurate overapproximation of the memory used, but is also slower, use usedMemory(boolean)

      Returns:
      the amount of used memory
    • usedMemory

      @Deprecated public static long usedMemory(boolean forceGc)
      Returns the amount of used memory in the JVM.
      Parameters:
      forceGc - if true, force a garbage collection, which gives a more accurate overapproximation of the memory used, but is also slower
      Returns:
      the amount of used memory
    • gc

      @Deprecated public static void gc()
      Deprecated.
      Perform garbage collection. Like System.gc, but waits to return until garbage collection has completed.
    • backTrace

      @Deprecated public static String backTrace(Throwable t)
      Returns a String representation of the backtrace of the given Throwable. To see a backtrace at the current location, do backtrace(new Throwable()).
      Parameters:
      t - the Throwable to obtain a backtrace of
      Returns:
      a String representation of the backtrace of the given Throwable
    • stackTraceToString

      public static String stackTraceToString(Throwable t)
      Returns a String representation of the stack trace (the backtrace) of the given Throwable. For a stack trace at the current location, do stackTraceToString(new Throwable()).
      Parameters:
      t - the Throwable to obtain a stack trace of
      Returns:
      a String representation of the stack trace of the given Throwable