public class Utils
public static java.lang.String getBasename(java.lang.String str)
Returns the base name of a string delimited with periods (i.e. Java Class).
str - string to parsepublic static java.lang.String getFilename(java.lang.String str)
This returns the filename only. Preceding directories are removed and everything after last . is removed.
str - original filenamepublic static java.lang.String getFilename(java.lang.String str,
java.lang.String suffix)
This returns the filename only. Preceding directories are removed and suffix. If suffix not found, then everything after last . is removed.
str - original filenamesuffix - suffixpublic static java.lang.String getDirectory(java.lang.String str)
Returns just the directory with the filename removed.
str - original filenamepublic static java.util.Set<java.lang.String> getFullyQualifiedResourceNames(java.lang.String filename)
This returns a set of fully qualified resource names that match the specified filename.
filename - filenamepublic static java.util.List<java.lang.String> getFullyQualifiedClassNames(java.lang.String simpleName)
public static java.util.Collection<java.lang.String> getJavaPackages()
public static java.util.Set<java.lang.String> getPackagesFromClassPath(java.lang.String classpath)
public static java.util.Set<java.lang.String> getTasselClasses()
public static java.util.Set<java.lang.String> readDirectory(java.lang.String path)
public static void recursiveRead(java.io.File file,
int startIndex,
java.util.Set<java.lang.String> packages)
public static java.util.Set<java.lang.String> readZipFile(java.lang.String path)
public static java.lang.String shortenStrLineLen(java.lang.String str,
int preferredLen)
public static java.lang.String shortenStrLineLen(java.lang.String str,
int preferredLen,
int preferredLines)
public static java.lang.String addSuffixIfNeeded(java.lang.String filename,
java.lang.String suffix)
Adds suffix (i.e. .txt) to end of filename if it's not already there.
filename - filenamesuffix - suffixpublic static java.lang.String addGzSuffixIfNeeded(java.lang.String filename,
java.lang.String suffix)
public static java.lang.String addSuffixIfNeeded(java.lang.String filename,
java.lang.String defaultSuffix,
java.lang.String[] possible)
Adds default suffix if not already one of the possible suffixes.
filename - filenamedefaultSuffix - default suffixpossible - possible suffixespublic static java.io.BufferedReader getBufferedReader(java.lang.String inSourceName)
public static java.io.BufferedReader getBufferedReader(java.lang.String inSourceName,
int bufSize)
public static java.io.BufferedReader getBufferedReader(java.io.File file,
int bufSize)
public static java.util.stream.Stream<java.lang.String> lines(java.nio.file.Path path,
int bufSize)
Read all lines from a file as a Stream. Unlike Path.readAllLines, this method does not read all lines into a List, but instead populates lazily as the stream is consumed.
Bytes from the file are decoded into characters using the specified charset and the same line terminators as specified by readAllLines are supported.
After this method returns, then any subsequent I/O exception that occurs while reading from the file or when a malformed or unmappable byte sequence is read, is wrapped in an java.io.UncheckedIOException that will be thrown from the java.util.stream.Stream method that caused the read to take place. In case an IOException is thrown when closing the file, it is also wrapped as an UncheckedIOException.
The returned stream encapsulates a java.io.Reader. If timely disposal of file system resources is required, the try-with-resources construct should be used to ensure that the stream's close method is invoked after the stream operations are completed.
path - the path to the fileStreamIOException - if an I/O error occurs opening the fileSecurityException - In the case of the default provider, and a security manager is installed, the checkRead method is invoked to check read access to the filepublic static java.io.BufferedWriter getBufferedWriter(java.lang.String filename)
public static java.io.BufferedWriter getBufferedWriter(java.lang.String filename,
boolean append)
public static java.io.BufferedWriter getBufferedWriter(java.io.File file)
public static java.io.BufferedWriter getBufferedWriter(java.io.File file,
boolean append)
public static java.io.DataOutputStream getDataOutputStream(java.lang.String filename,
int bufSize)
public static int findNthOccurrenceInString(java.lang.String str,
char match,
int n)
Finds index of Nth occurrence of character in string.
str - stringmatch - character to matchn - Nth occurrencepublic static long getMaxHeapSizeMB()
Returns max heap size in MB.
public static java.io.InputStream getInputStream(java.lang.String filename)
Gets input stream for given file.
filename - file namepublic static java.io.BufferedOutputStream getBufferedOutputStream(java.lang.String filename)
public static int getNumberLines(java.lang.String filename)
Return number of lines in given file.
filename - file namepublic static int getNumberLinesNotHashOrBlank(java.lang.String filename)
Return number of lines in given file that doesn't begin with Hash (#) and isn't blank.
filename - file namepublic static java.lang.String readLineSkipComments(java.io.BufferedReader br)