Class DataFormatTools
- java.lang.Object
-
- com.sedmelluq.discord.lavaplayer.tools.DataFormatTools
-
public class DataFormatTools extends java.lang.ObjectHelper methods related to strings and maps.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDataFormatTools.TextRange
-
Constructor Summary
Constructors Constructor Description DataFormatTools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanarrayRangeEquals(byte[] array, int offset, byte[] segment)static java.util.Map<java.lang.String,java.lang.String>convertToMapLayout(java.lang.String response)static java.util.Map<java.lang.String,java.lang.String>convertToMapLayout(java.util.Collection<org.apache.http.NameValuePair> pairs)Converts name value pairs to a map, with the last entry for each name being present.static java.util.Map<java.lang.String,java.lang.String>decodeUrlEncodedItems(java.lang.String input, boolean escapedSeparator)static <T> TdefaultOnNull(T value, T defaultValue)Returns the specified default value if the value itself is null.static longdurationTextToMillis(java.lang.String durationText)Converts duration in the format HH:mm:ss (or mm:ss or ss) to milliseconds.static java.lang.StringextractAfter(java.lang.String haystack, java.lang.String start)static java.lang.StringextractAfter(java.lang.String haystack, java.lang.String[] candidates)static java.lang.StringextractBetween(java.lang.String haystack, DataFormatTools.TextRange[] candidates)static java.lang.StringextractBetween(java.lang.String haystack, java.lang.String start, java.lang.String end)Extract text between the first subsequent occurrences of start and end in haystackstatic booleanisNullOrEmpty(java.lang.String text)static java.lang.StringreadNullableText(java.io.DataInput input)Reads a string from input which may benull.static java.lang.String[]streamToLines(java.io.InputStream inputStream, java.nio.charset.Charset charset)Consumes a stream and returns it as lines.static voidwriteNullableText(java.io.DataOutput output, java.lang.String text)Writes a string to output with the additional information whether it isnullor not.
-
-
-
Method Detail
-
extractBetween
public static java.lang.String extractBetween(java.lang.String haystack, java.lang.String start, java.lang.String end)Extract text between the first subsequent occurrences of start and end in haystack- Parameters:
haystack- The text to search fromstart- The text after which to start extractingend- The text before which to stop extracting- Returns:
- The extracted string
-
extractBetween
public static java.lang.String extractBetween(java.lang.String haystack, DataFormatTools.TextRange[] candidates)
-
extractAfter
public static java.lang.String extractAfter(java.lang.String haystack, java.lang.String start)
-
extractAfter
public static java.lang.String extractAfter(java.lang.String haystack, java.lang.String[] candidates)
-
isNullOrEmpty
public static boolean isNullOrEmpty(java.lang.String text)
-
convertToMapLayout
public static java.util.Map<java.lang.String,java.lang.String> convertToMapLayout(java.util.Collection<org.apache.http.NameValuePair> pairs)
Converts name value pairs to a map, with the last entry for each name being present.- Parameters:
pairs- Name value pairs to convert- Returns:
- The resulting map
-
convertToMapLayout
public static java.util.Map<java.lang.String,java.lang.String> convertToMapLayout(java.lang.String response)
-
decodeUrlEncodedItems
public static java.util.Map<java.lang.String,java.lang.String> decodeUrlEncodedItems(java.lang.String input, boolean escapedSeparator)
-
defaultOnNull
public static <T> T defaultOnNull(T value, T defaultValue)Returns the specified default value if the value itself is null.- Type Parameters:
T- The type of the value- Parameters:
value- Value to checkdefaultValue- Default value to return if value is null- Returns:
- Value or default value
-
streamToLines
public static java.lang.String[] streamToLines(java.io.InputStream inputStream, java.nio.charset.Charset charset) throws java.io.IOExceptionConsumes a stream and returns it as lines.- Parameters:
inputStream- Input stream to consume.charset- Character set of the stream- Returns:
- Lines from the stream
- Throws:
java.io.IOException- On read error
-
durationTextToMillis
public static long durationTextToMillis(java.lang.String durationText)
Converts duration in the format HH:mm:ss (or mm:ss or ss) to milliseconds. Does not support day count.- Parameters:
durationText- Duration in text format.- Returns:
- Duration in milliseconds.
-
writeNullableText
public static void writeNullableText(java.io.DataOutput output, java.lang.String text) throws java.io.IOExceptionWrites a string to output with the additional information whether it isnullor not. Compatible withreadNullableText(DataInput).- Parameters:
output- Output to write to.text- Text to write.- Throws:
java.io.IOException- On write error.
-
readNullableText
public static java.lang.String readNullableText(java.io.DataInput input) throws java.io.IOExceptionReads a string from input which may benull. Compatible withwriteNullableText(DataOutput, String).- Parameters:
input- Input to read from.- Returns:
- The string that was read, or
null. - Throws:
java.io.IOException- On read error.
-
arrayRangeEquals
public static boolean arrayRangeEquals(byte[] array, int offset, byte[] segment)
-
-