de.scheisseichfindemalkeinen.tool
Class Tool

java.lang.Object
  extended by de.scheisseichfindemalkeinen.tool.Tool

public class Tool
extends java.lang.Object

This class provides methods, which are often used.


Field Summary
static int FILENAME_LENGTH_LIMIT
          Maximum length of a filename
static int PATH_LENGTH_LIMIT
          Maximum length of a path
 
Constructor Summary
Tool()
           
 
Method Summary
static boolean checkIsSameOrSubFolder(java.lang.String path, java.lang.String parentPath)
          Checks if path is a subfolder of parentPath It will also return true, if the path is not a direct subfolder.
static int compareJavaVersions(java.lang.String v1, java.lang.String v2)
          Compares Java-Versions
static int compareVersions(java.lang.String v1, java.lang.String v2)
          Compares two Version-Strings
static java.lang.String correctFileString(java.lang.String str, boolean noPath)
          This method filters not allowed chars in paths or filenames You must set noPath to true, if the string is only a filename.
static java.lang.String correctPathString(java.lang.String str, java.lang.String filename)
          Verzeichnisnamen kuerzen
static java.lang.String encodeURL(java.lang.String url)
          Encodes an url
static java.lang.String getBitrateString(long size, long max, long timeStarted, long timeNow)
          Returns a String with the download rate
static java.lang.String[] getDomainAndPathFromURL(java.lang.String url)
          Returns the domain and path part of a URL If the url could not be splitted, null is returned
static java.lang.String getDomainFromURL(java.lang.String url)
          Returns the domain of a URL If the domain could not be found an empty String is returned
static java.lang.String getEncodingFromSourceCode(java.lang.String htmlCode, java.lang.String url)
          Returns the charset defined in meta http-equiv="Content-Type" tag if available otherwise an empty String
static java.lang.String getFilenameFromURL(java.lang.String url)
          Returns the filename from the url if possible or otherwise BH.getString("Unkown")
static java.lang.String getNumberedFilename(java.lang.String filename, int number)
          Returns a filename with "#" replaced by the given number If there are more # as the numbers length is than the # is replaced by zero.
static java.lang.String getPathFromFile(java.io.File file)
          Returns the path of a file
static java.lang.String getPercentString(long size, long max)
          Returns the progress as percent
static java.lang.String getProgressString(long size, long max)
          Returns a String with the percent or size read
static java.lang.String getSizeString(long size)
          Returns the bytes read in a suitable unit, or a specific unit, if the user defined that in the options
static java.lang.String getThisApplicationsJarFilename(java.lang.String[] ignoredJarFilenames)
          Returns the jarfilename of this application or an empty string, if filename could not be detected
static java.lang.String getThisApplicationsPath(java.lang.String jarFilename)
          Returns the path of this application
static java.lang.String getZeroFilledNumber(int number, int len)
          Returns the number with leading zeros Example: Number is 2 and length is 4: This method returns: 0002
static java.lang.String lTrim(java.lang.String str)
          Trims the start of a path
static int[] parseColWidthsSetting(java.lang.String setting)
          Parses a colwidth setting and returns an array of integers.
static java.lang.String pathRTrim(java.lang.String path)
          Trims a path
static java.lang.String rTrim(java.lang.String str)
          Trims the end of a path
static java.lang.String trimURL(java.lang.String url)
          Trims an url
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PATH_LENGTH_LIMIT

public static final int PATH_LENGTH_LIMIT
Maximum length of a path

See Also:
Constant Field Values

FILENAME_LENGTH_LIMIT

public static final int FILENAME_LENGTH_LIMIT
Maximum length of a filename

See Also:
Constant Field Values
Constructor Detail

Tool

public Tool()
Method Detail

correctFileString

public static java.lang.String correctFileString(java.lang.String str,
                                                 boolean noPath)
This method filters not allowed chars in paths or filenames You must set noPath to true, if the string is only a filename.

Parameters:
str - String
noPath - Is no path
Returns:
Corrected String

correctPathString

public static java.lang.String correctPathString(java.lang.String str,
                                                 java.lang.String filename)
Verzeichnisnamen kuerzen

Parameters:
str - Pfad
filename - Dateiname
Returns:
Gekuerzter Pfad

compareVersions

public static int compareVersions(java.lang.String v1,
                                  java.lang.String v2)
Compares two Version-Strings

Parameters:
v1 - First Version-String
v2 - Second Version-String
Returns:
0/<0/>0

compareJavaVersions

public static int compareJavaVersions(java.lang.String v1,
                                      java.lang.String v2)
Compares Java-Versions

Parameters:
v1 - Version
v2 - Version
Returns:
0/<0/>0

getNumberedFilename

public static java.lang.String getNumberedFilename(java.lang.String filename,
                                                   int number)
Returns a filename with "#" replaced by the given number If there are more # as the numbers length is than the # is replaced by zero. Example: The filename is "file###name" and the number is 2, then this method will return this: "file002name"

Parameters:
filename - Filename
number - Number
Returns:
Filename

getZeroFilledNumber

public static java.lang.String getZeroFilledNumber(int number,
                                                   int len)
Returns the number with leading zeros Example: Number is 2 and length is 4: This method returns: 0002

Parameters:
number - Number
len - Length
Returns:
Number with leading zeros

lTrim

public static java.lang.String lTrim(java.lang.String str)
Trims the start of a path

Parameters:
str - Path
Returns:
Path

rTrim

public static java.lang.String rTrim(java.lang.String str)
Trims the end of a path

Parameters:
str - Path
Returns:
Path

pathRTrim

public static java.lang.String pathRTrim(java.lang.String path)
Trims a path

Parameters:
path - Path
Returns:
Path

trimURL

public static java.lang.String trimURL(java.lang.String url)
Trims an url

Parameters:
url - URL
Returns:
Trimmed URL

encodeURL

public static java.lang.String encodeURL(java.lang.String url)
Encodes an url

Parameters:
url - URL
Returns:
Encoded URL

getSizeString

public static java.lang.String getSizeString(long size)
Returns the bytes read in a suitable unit, or a specific unit, if the user defined that in the options

Parameters:
size - Number of bytes read
Returns:
Progress-String

getPercentString

public static java.lang.String getPercentString(long size,
                                                long max)
Returns the progress as percent

Parameters:
size - Number of bytes read
max - Filesize
Returns:
Percent-String

getProgressString

public static java.lang.String getProgressString(long size,
                                                 long max)
Returns a String with the percent or size read

Parameters:
size - Number of bytes read
max - Filesize
Returns:
Progress-String

getBitrateString

public static java.lang.String getBitrateString(long size,
                                                long max,
                                                long timeStarted,
                                                long timeNow)
Returns a String with the download rate

Parameters:
size - Number of bytes read
max - Filesize
timeStarted - Start-Time
timeNow - Now
Returns:
String with the download rate

getThisApplicationsPath

public static java.lang.String getThisApplicationsPath(java.lang.String jarFilename)
Returns the path of this application

Parameters:
jarFilename - Filename of the Jar
Returns:
Path

getThisApplicationsJarFilename

public static java.lang.String getThisApplicationsJarFilename(java.lang.String[] ignoredJarFilenames)
Returns the jarfilename of this application or an empty string, if filename could not be detected

Parameters:
ignoredJarFilenames - Filenames to ignore
Returns:
Jarfilename or empty String

getPathFromFile

public static java.lang.String getPathFromFile(java.io.File file)
Returns the path of a file

Parameters:
file - File
Returns:
Path

getDomainFromURL

public static java.lang.String getDomainFromURL(java.lang.String url)
Returns the domain of a URL If the domain could not be found an empty String is returned

Parameters:
url - URL
Returns:
Domain

getDomainAndPathFromURL

public static java.lang.String[] getDomainAndPathFromURL(java.lang.String url)
Returns the domain and path part of a URL If the url could not be splitted, null is returned

Parameters:
url - URL
Returns:
String-Array

parseColWidthsSetting

public static int[] parseColWidthsSetting(java.lang.String setting)
Parses a colwidth setting and returns an array of integers. If the parsing fails completly null is returned. If only some values could not be parsed, then they are set to 0.

Parameters:
setting - ColWidth-Setting
Returns:
Array of integers or null

checkIsSameOrSubFolder

public static boolean checkIsSameOrSubFolder(java.lang.String path,
                                             java.lang.String parentPath)
Checks if path is a subfolder of parentPath It will also return true, if the path is not a direct subfolder. And if path and parentPath are the same, this method will also return true! This method does not check if the folders exist! Example: parentPath = C:\ path = C:\example <-- this returns true Example: parentPath = C:\ path = C:\example\something\bla\blub <-- this returns true

Parameters:
path - Path
parentPath - Parent Path
Returns:
TRUE if it is the same folder or a subfolder

getFilenameFromURL

public static java.lang.String getFilenameFromURL(java.lang.String url)
Returns the filename from the url if possible or otherwise BH.getString("Unkown")

Parameters:
url - URL
Returns:
Filename

getEncodingFromSourceCode

public static java.lang.String getEncodingFromSourceCode(java.lang.String htmlCode,
                                                         java.lang.String url)
Returns the charset defined in meta http-equiv="Content-Type" tag if available otherwise an empty String

Parameters:
htmlCode - Page Source Code
url - URL
Returns:
Encoding