Package htsjdk.tribble.util
Class ParsingUtils
- java.lang.Object
-
- htsjdk.tribble.util.ParsingUtils
-
public class ParsingUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Map<Object,Color>
colorCache
static Class
urlHelperClass
-
Constructor Summary
Constructors Constructor Description ParsingUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
appendToPath(String filepath, String indexExtension)
Add theindexExtension
to thefilepath
, preserving query string elements if present.static URLHelper
getURLHelper(URL url)
Return the registered URLHelper, constructed with the provided URLstatic <T extends Comparable<? super T>>
booleanisSorted(Iterable<T> iterable)
static String
join(String separator, String[] strings)
join an array of strings given a seperatorstatic String
join(String separator, String[] strings, int start, int end)
join a set of strings, using the separator provided, from index start to index stopstatic <T> String
join(String separator, Collection<T> objects)
static InputStream
openInputStream(String path)
static InputStream
openInputStream(String uri, Function<SeekableByteChannel,SeekableByteChannel> wrapper)
open an input stream from the given path and wrap the raw byte stream with a wrapper if given the wrapper will only be applied to paths that are not http, https, ftp, or file, i.e.static Color
parseColor(String string)
Convert an rgb string, hex, or symbol to a color.static void
registerHelperClass(Class helperClass)
Register aURLHelper
class to be used for URL operations.static boolean
resourceExists(String resource)
static <T extends Comparable<T>,V>
StringsortedString(Map<T,V> c)
static <T extends Comparable>
List<T>sortList(Collection<T> list)
a small utility function for sorting a liststatic List<String>
split(String input, char delim)
Split the string into tokens separated by the given delimiter.static int
split(String aString, String[] tokens, char delim)
Split the string into tokesn separated by the given delimiter.static int
split(String aString, String[] tokens, char delim, boolean condenseTrailingTokens)
Split the string into tokens separated by the given delimiter.static int
splitWhitespace(String aString, String[] tokens)
Split the string into tokens separated by tab or space(s).static String
trim(String str, char ch)
-
-
-
Method Detail
-
openInputStream
public static InputStream openInputStream(String path) throws IOException
- Returns:
- an input stream from the given path
- Throws:
IOException
-
openInputStream
public static InputStream openInputStream(String uri, Function<SeekableByteChannel,SeekableByteChannel> wrapper) throws IOException
open an input stream from the given path and wrap the raw byte stream with a wrapper if given the wrapper will only be applied to paths that are not http, https, ftp, or file, i.e. anyPath
using a custom filesystem plugin- Parameters:
uri
- a uri like stringwrapper
- to wrap the input stream in, may be used to implement caching or prefetching, etc- Returns:
- An inputStream appropriately created from uri and conditionally wrapped with wrapper (only in certain cases)
- Throws:
IOException
- when stream cannot be opened against uri
-
join
public static <T> String join(String separator, Collection<T> objects)
-
sortList
public static <T extends Comparable> List<T> sortList(Collection<T> list)
a small utility function for sorting a list- Type Parameters:
T
-- Parameters:
list
-- Returns:
-
sortedString
public static <T extends Comparable<T>,V> String sortedString(Map<T,V> c)
-
join
public static String join(String separator, String[] strings)
join an array of strings given a seperator- Parameters:
separator
- the string to insert between each array elementstrings
- the array of strings- Returns:
- a string, which is the joining of all array values with the separator
-
join
public static String join(String separator, String[] strings, int start, int end)
join a set of strings, using the separator provided, from index start to index stop- Parameters:
separator
- the separator to usestrings
- the list of stringsstart
- the start position (index in the list)0end
- the end position (index in the list)- Returns:
- a joined string, or "" if end - start == 0
-
split
public static List<String> split(String input, char delim)
Split the string into tokens separated by the given delimiter. This looks suspiciously like what String.split should do. It is here because String.split has particularly poor performance for this use case in some versions of the Java SE API because of use of java.util.regex APIs (see bug report at http://bugs.java.com/view_bug.do?bug_id=6840246 for information).- Parameters:
input
- the string to splitdelim
- the character that delimits tokens- Returns:
- a list of the tokens
-
split
public static int split(String aString, String[] tokens, char delim)
Split the string into tokesn separated by the given delimiter. Profiling has revealed that the standard string.split() method typically takes > 1/2 the total time when used for parsing ascii files.- Parameters:
aString
- the string to splittokens
- an array to hold the parsed tokensdelim
- character that delimits tokens- Returns:
- the number of tokens parsed
-
split
public static int split(String aString, String[] tokens, char delim, boolean condenseTrailingTokens)
Split the string into tokens separated by the given delimiter. Profiling has revealed that the standard string.split() method typically takes > 1/2 the total time when used for parsing ascii files.- Parameters:
aString
- the string to splittokens
- an array to hold the parsed tokensdelim
- character that delimits tokenscondenseTrailingTokens
- if true and there are more tokens than will fit in the tokens array, condense all trailing tokens into the last token- Returns:
- the number of tokens parsed
-
splitWhitespace
public static int splitWhitespace(String aString, String[] tokens)
Split the string into tokens separated by tab or space(s). This method was added so support wig and bed files, which apparently accept space delimiters. Note: TODO REGEX expressions are not used for speed. This should be re-evaluated with JDK 1.5 or later- Parameters:
aString
- the string to splittokens
- an array to hold the parsed tokens- Returns:
- the number of tokens parsed
-
isSorted
public static <T extends Comparable<? super T>> boolean isSorted(Iterable<T> iterable)
-
parseColor
public static Color parseColor(String string)
Convert an rgb string, hex, or symbol to a color.- Parameters:
string
-- Returns:
-
resourceExists
public static boolean resourceExists(String resource) throws IOException
- Throws:
IOException
-
getURLHelper
public static URLHelper getURLHelper(URL url)
Return the registered URLHelper, constructed with the provided URL- Parameters:
url
-- Returns:
- See Also:
registerHelperClass(Class)
-
registerHelperClass
public static void registerHelperClass(Class helperClass)
Register aURLHelper
class to be used for URL operations. The helper may be used for both FTP and HTTP operations, so if any FTP URLs are used theURLHelper
must support it. The default helper class isRemoteURLHelper
, which delegates to FTP/HTTP helpers as appropriate.
-
appendToPath
public static String appendToPath(String filepath, String indexExtension)
Add theindexExtension
to thefilepath
, preserving query string elements if present. Intended for use wherefilepath
is a URL. Will behave correctly on regular file paths (just add the extension to the end)- Parameters:
filepath
-indexExtension
-- Returns:
-
-