java.lang.Object
dev.netcode.util.StringUtils
This class contains functions to generate, manipulate or use Strings
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringapplySha256(String input)Applies the SHA-256 algorithm to the given input.static byte[]chunkSplit(String data, int n, char insert)Inserts a char into a string every n chars.static StringUTF-8 decodes an URLstatic StringgetFileExtension(File file)Returns the file extension of a filestatic StringThis class adds spaces to the end of the given string so that the total length of the string is equal to totalLengthstatic StringThis class adds spaces to the begin of the given string so that the total length of the string is equal to totalLengthstatic byte[]readFileData(File file, int fileLength)Reads file into byte arraystatic booleansaveToFile(Path file, String data)Saves a string to a filestatic String[]splitStringEvery(String s, int interval)splits a given string into parts of maximum length of intervalstringToMap(String input)Translates a String in the form of key=value&key2=value2... to aHashMap
-
Constructor Details
-
StringUtils
public StringUtils()
-
-
Method Details
-
padLeft
This class adds spaces to the end of the given string so that the total length of the string is equal to totalLength- Parameters:
string- to padtotalLength- of the result string- Returns:
- string that has been filled up with spaces to the length of totalLength
-
padRight
This class adds spaces to the begin of the given string so that the total length of the string is equal to totalLength- Parameters:
string- to padtotalLength- of the result string- Returns:
- string that has been filled up with spaces to the length of totalLength
-
decodeURL
UTF-8 decodes an URL- Parameters:
encoded- URL- Returns:
- decoded URL
-
applySha256
Applies the SHA-256 algorithm to the given input. Input gets converted to UTF-8- Parameters:
input- to apply the SHA-256 algorithm to- Returns:
- hexadecimal representation of SHA-256 applied string
-
readFileData
Reads file into byte array- Parameters:
file- to be readfileLength- of the file- Returns:
- byte contents of the file
- Throws:
IOException- if something fails
-
saveToFile
Saves a string to a file- Parameters:
file- Path of the file to save the data indata- to save- Returns:
- true if storing the data was successful, false otherwise
-
stringToMap
Translates a String in the form of key=value&key2=value2... to aHashMap- Parameters:
input- string- Returns:
HashMaprepresenting the input string
-
chunkSplit
Inserts a char into a string every n chars. Adds linebreak at the end. Can for example be used to add a linebreak every n characters- Parameters:
data- to insert the chars inton- offset between insertsinsert- char- Returns:
- byte array with inserted chars
-
splitStringEvery
splits a given string into parts of maximum length of interval- Parameters:
s- to splitinterval- amount of chars to split the string after- Returns:
- array of strings representing splitted input
-
getFileExtension
Returns the file extension of a file- Parameters:
file- to get the extension of- Returns:
- the files extension
-