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 StringbytesToHex(byte[] bytes)Converts a byte array to hexadecimal represented Stringstatic byte[]chunkInsert(String data, int n, char insert)Inserts a char into a string after every n chars.static StringDecodes escaped special chars from URLs like '%20' to their UTF-8 counterpartstatic StringgetFileExtension(File file)Returns the file extension of a file.static byte[]hexStringToByteArray(String string)Converts a hexadecimal string to byte arraystatic StringhexToString(String hexStr)Decodes a hexadecimal stringstatic StringThis class adds spaces to the end of the given string so that the total length of the string is equal to totalLength.static StringThis class adds spaces to the begin of the given string so that the total length of the string is equal to totalLength.static 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. If totalLength is less or equal to the strings length no spaces are added and original input is returned. If input string is null, the result will be aswell.- 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. If totalLength is less or equal to the strings length no spaces are added and original input is returned. If input string is null, the result will be aswell.- Parameters:
string- to padtotalLength- of the result string- Returns:
- string that has been filled up with spaces to the length of totalLength
-
decodeURL
Decodes escaped special chars from URLs like '%20' to their UTF-8 counterpart- 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
-
chunkInsert
Inserts a char into a string after every n chars. 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. If file has no extension an empty String is returned- Parameters:
file- to get the extension of- Returns:
- the files extension
-
bytesToHex
Converts a byte array to hexadecimal represented String- Parameters:
bytes- to transform- Returns:
- hexadecimal representation
-
hexStringToByteArray
Converts a hexadecimal string to byte array- Parameters:
string- to transform- Returns:
- byte representation
-
hexToString
Decodes a hexadecimal string- Parameters:
hexStr- hexadecimal string to be decoded- Returns:
- decoded string
-