Package com.nomagic.utils
Class Utilities
java.lang.Object
com.nomagic.utils.CameoUtilities
com.nomagic.utils.Utilities
General purpose utilities.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
addHttpParameter
(String parameters, String parameter, String value) Adds http parameter to given parameters stringstatic <T> Collection<T>
append
(Collection<T> source, Collection<? extends T> v, boolean allowDublication) Deprecated.static <T> Collection<T>
append
(Collection<T> source, Iterator<? extends T> it, boolean allowDublication) static boolean
areChildrenDisabled
(JMenu menu) Are all children disabled?static int
arrayHash
(byte[] array) Calculate hash code for array of bytesstatic int
calculateTextWidth
(String text, FontMetrics metrics, int numberOfLines) Calculates possible text longest text width of the given text splitted into lines.static String
checkIsInstallRootWritable
(com.nomagic.runtime.RuntimeEnvironment runtime) Get message for install root read only error.static String
checkIsInstallRootWritable
(com.nomagic.runtime.RuntimeEnvironment runtime, boolean skipWinUAC) Get message for install root read only error.static boolean
checkProperty
(Properties properties, String property, boolean defaultValue) static boolean
checkResolvableException
(boolean rule) if rule is false and it's DEVELOPER mode throwsIllegalStateException
static boolean
checkSystemProperty
(String property, boolean defaultValue) Checks given system (boolean) property valuestatic String
clearAllLine
(String src, String trash) Removes all trash from stringstatic String
clearFromEveryLine
(String text, String mask) Divides given string into lines and from every line beginning and end removes all chars from given string mask.static String
removes from line ends wanted charactersstatic int
collectInteger
(byte[] bytes) Makes int value from array of bytesstatic boolean
compareFiles
(File f1, File f2) Compares two filesstatic boolean
compareStreams
(InputStream oldStr, InputStream newStr) Compares two input streams.static byte[]
compressData
(byte[] data) Compresses specified data using gzip output stream and returns the result as bytes array.static byte[]
compressData
(byte[] data, String zipEntryName) Compresses specified data using zip output stream and returns the result as bytes array.static String
concatHttpParameter
(String parameters1, String parameters2) Concatenate given http parametersstatic String
constructHttpParameter
(String parameter, String value) Constructs http parameterstatic boolean
Deprecated.static boolean
containSameElements
(Collection<?> collection1, Collection<?> collection2) static boolean
containsAny
(Collection location, Collection what) static boolean
containsNonDirectory
(List<File> fileList) static boolean
containsOnlyFiles
(List list) Indicates if given list contains only file objects.static boolean
contentEquals
(InputStream input1, InputStream input2) Compare content of two streams.static void
copy
(InputStream input, OutputStream output) Copies all bytes from InputStream into OutputStream.static void
copy
(InputStream input, OutputStream output, long crc, boolean closeInput) Copies all bytes from InputStream into OutputStream.static void
copy
(InputStream input, OutputStream output, Checksum checksum) Copies all bytes from InputStream into OutputStreamstatic boolean
copyDirectory
(File source, File destination) Copy all directory recursivelystatic boolean
Copy source file to destination file.static boolean
Copy source file to destination file.static int
countOccurrences
(String string, char c) Returns the number of times the character c appears in a string.static Rectangle
coverRectangle
(Rectangle inner, Rectangle outer) Moves outer rectangle in such way that it must cover inner one (if outer is smaller than inner resizes outer).static <E extends Collection>
EcreateCollection
(Class<E> collection, Iterator it) Deprecated.static Cursor
createCursor
(Image image, Point pt, String cursorName) Creates the cursor for given image.static Cursor
createCursor
(Icon icon, Point pt, String cursorName) Creates the cursor for given icon.static Rectangle
Creates rectangle from vector of points.static String
static byte[]
Decode string using Base64 encoding.deepPointsClone
(List<Point> v) Makes a deep clone of vector that contains points.deepPointsClone
(List<Point> v, boolean cloneList) Makes a deep clone of vector that contains points.static void
Removes given directory contents.static void
deleteTree
(File f) Removes given directory and all its contents.static void
Removes given file (directory and all its contents) on exit.static byte[]
distributeInteger
(int intValue, int size) Distributes integer intValue into array of bytes.static void
Dumps all threads to system out.static void
dumpThreads
(PrintStream out) Dumps all threads to given stream.static String
encodeBase64
(byte[] abyte0) Encodes data using base64 encoding.static <T> void
ensureObjectIsInCollection
(Collection<T> collection, T object) Ensures an object is in given collection.static <T> Set<T>
excludeCommonElements
(Collection<T> first, Collection<T> second) Creates result collection which contains not common elements from two argumentsstatic Collection<String>
extractZip
(InputStream is, String dstDir, Collection<String> onlyTheseEntries, Collection<String> skipTheseEntries) Extracts files from Zip archivestatic void
extractZip
(ZipFile zipFile, String dstDir) Extracts files from Zip archivestatic Rectangle
fitInRectangle
(Rectangle small, Rectangle big) recalculate bounds to fit in rectanglestatic String
Constructs the string representation of the given key stroke.static String
getAsStringKeyStrokes
(List<KeyStroke> shortcuts, String bracketFirst, String bracketSecond) Constructs the string representation of the given key strokes.static byte[]
Returns bytes of string.static String
getClassName
(Class clazz) Get class name.static String
static <E> int
getDistance
(E from, E to, Function<E, Collection<E>> connectedNodes) Calculate minimal distance in graph.static String
getFileExtension
(File file) Get The given file extension.static String
getFileExtension
(String fileName) Get the given file extension.static String
getFileName
(String text) static String
getFileWithoutExtension
(String filename) Returns file name without extension (removes chars from last "." to end of string)static String
getFileWitoutExtention
(String filename) Deprecated.type error in namestatic ResizableIcon
getGrayIcon
(Icon icon) Deprecated.static ResizableIcon
getGrayIcon
(Icon icon, Component component) Deprecated.static String
getHtmlPage
(String pageHttpAddress, String parameters, ProxyServerData proxy) Returns HTML pagestatic JMenuItem
getItemWithText
(JPopupMenu menu, String text) Returns inner component (not recursively) with given text.static DateFormat
getSystemDateFormat
(int style) Returns system date format.static String
Returns System temp directory.static String
static String
getVersionFromInternal
(int internal) Convert internal MagicDraw style version to human version in 17.0.2 format.static String
getVersionFromInternal
(String internal) Convert internal MagicDraw style version to human version in 17.0.2 format.static boolean
hasModalDialogs
(Window window) Checks recursively if given window has modal dialog as child (or window itself is a modal dialog)static String
Deprecated.static String
implode
(Collection collection, String delimiter) Returns a new String composed of copies of the collection elements joined together with a copy of the specified delimiter.static String
insertPeriodically
(String text, String insert, int period) static String
insertSeparators
(char[] chars, String separator, int groupSize) Constructs string from arrays of chars.static void
Executes given runnable on event dispatcher.static void
Executes given runnable on event dispatcher.static void
invokeLaterAfterCondition
(Runnable runnable, Supplier<Boolean> condition) Invokes runnable latter after condition is satisfied.static void
invokeLaterAfterCondition
(Runnable runnable, Supplier<Boolean> condition, int conditionCheckAttemptCount) Invokes runnable latter after condition is satisfied.static void
If this thread is event dispatcher, than direct calls "run", else invoke on invoke laterstatic boolean
isAlphaNumeric
(String str) static boolean
isFileNameValid
(String fileName) Returns if given file name is valid to be created.static boolean
isHTMLText
(String s) Check the given string to see if it should trigger the html rendering logic.static boolean
isNameValid
(String name) static boolean
isPrintableChar
(char c) Checks if char is printable or not.static boolean
isStreamEmpty
(URL url) Check if it is possible to open a stream from a given URL and that stream is not emptystatic boolean
isUseProxy
(ProxyServerData proxy) Checks if use proxy server according given proxy server datastatic boolean
isValidKeyCode
(int keyCode) Checks if given code is correct one or not.static void
static void
Make destination the same as source with minimum changes to destinationstatic boolean
Checks if given string matches given pattern with wild cards.static boolean
matchIncludingEmpty
(String pattern, String string) Checks if given string matches given pattern with wild cards.static <T> void
Merges two vector.static <T> List<T>
mergeLists
(List<T> l1, List<T> l2) Merges two lists into newly created one.static void
normalizes rectangle mRectToDraw;static void
Normalizes rectangle; Calculates rectangle size and location using firstCorner and secondCorner.static Collection
Deprecated.static HttpURLConnection
openHttpURLConnection
(String pageHttpAddress, ProxyServerData proxyServerData) Opens HttpURLConnection according given page address and proxy server data.static String[]
parseExceptQuotes
(String cmd) parses string by standard tokens, except parts wrapped in quotesstatic String
readFileSkipFirstLines
(File file, int n) Reads a file to string and skips a specified number of lines from the beginning.static String
removeComments
(String body) Removes / * * / comments from body.static String
removeNewLines
(String string) Removes new lines from the string.static String
removeNonUtf8CompliantCharacters
(String inString) static String
removeSeparators
(String str, String separator) Removes separators from specified strstatic String
Replaces string fragment with another stringstatic String
replaceEpsString
(String aStr) Replace special char for Eps format stringstatic String
reverseString
(String source) Given a string, returns a string with reversed characters.static void
sendHttpParameters
(HttpURLConnection connection, String parameters) Deprecated.useHttpUtilities.sendHttpParameters(HttpURLConnection, String)
static String
sha1Hex
(byte[] data) Returns SHA-1 hash key that should be constructed from the specified data.static String
Returns SHA-1 hash key that should be constructed from the specified strings.static void
sortStrings
(Vector elem) Sorts elements in strings' vectorstatic String[]
splitString
(String str, String delimiter, boolean returnDelimiter) Splits stringstatic void
swapVector
(List v) Deprecated.static void
synchronizeDirectories
(File source, File destination) Synchronize two directories.static byte[]
toByteArray
(InputStream stream) Copies the given file into the array of bytes.static byte[]
toByteArray
(String bytes) Returns byte array from string formatted in toString(byte[]) method.static String
toString
(byte[] data) Returns string representation of the given byte array.static String
toString
(InputStream inputStream) Get String representation of inputStreamstatic String
toString
(Collection<String> strings) Get String representation of given strings collectionstatic String
Removes from begin and end given Strings.static byte[]
uncompressData
(byte[] data) Uncompresses specified data using gzip input stream and returns the result as bytes array.static void
zipDir
(String dir2zip, ZipOutputStream zos) Compress specified directory recursively to the specified stream.Methods inherited from class com.nomagic.utils.CameoUtilities
copy, hasExtension, hasExtension, isEqual, isEqual, removeExtension, removeFromLine, replaceNewLine, toString
-
Constructor Details
-
Utilities
public Utilities()
-
-
Method Details
-
createStringRepresentation
-
deepPointsClone
Makes a deep clone of vector that contains points.- Parameters:
v
- List of point.- Returns:
- vector
-
deepPointsClone
Makes a deep clone of vector that contains points.- Parameters:
v
- List of point.cloneList
- True if clone to new list.- Returns:
- vector
-
replace
Replaces string fragment with another string- Parameters:
src
- Source string.pattern
- String pattern.replaceWith
- The another string.- Returns:
- string.
-
match
Checks if given string matches given pattern with wild cards. Empty string does not match any pattern.- Parameters:
pattern
- pattern with wildcardsstring
- string- Returns:
- boolean true if string matches pattern
-
matchIncludingEmpty
Checks if given string matches given pattern with wild cards. Empty string matches pattern "*".- Parameters:
pattern
- pattern with wildcardsstring
- string- Returns:
- boolean true if string matches pattern
-
sortStrings
Sorts elements in strings' vector- Parameters:
elem
- The given vector.
-
clearLine
removes from line ends wanted characters- Parameters:
line
- The given line.trash
- characters as string.- Returns:
- String.
-
clearAllLine
Removes all trash from string- Parameters:
src
- String that be removed trashtrash
- Trash string.- Returns:
- String.
-
merge
Merges two vector. Removes non existing in vector v elements from vector source. Adds existing in v into source. Result vector is source- Parameters:
source
- source list.v
- The given vector.
-
append
@Deprecated public static <T> Collection<T> append(Collection<T> source, Collection<? extends T> v, boolean allowDublication) -
append
@Deprecated public static <T> Collection<T> append(Collection<T> source, Iterator<? extends T> it, boolean allowDublication) -
contains
Deprecated. -
containsAny
-
clearFromEveryLine
Divides given string into lines and from every line beginning and end removes all chars from given string mask.- Parameters:
text
- The given string.mask
- The given string mark.- Returns:
- String.
-
countOccurrences
Returns the number of times the character c appears in a string.- Parameters:
string
- The given stringc
- character- Returns:
- number of time
-
removeNonUtf8CompliantCharacters
-
fitInRectangle
recalculate bounds to fit in rectangle- Parameters:
small
- Small rectanglebig
- Big rectangle- Returns:
- New rectangle
-
containsOnlyFiles
Indicates if given list contains only file objects.- Parameters:
list
- list to check.- Returns:
- true if given list contains only file objects, false otherwise.
-
containsNonDirectory
- Parameters:
fileList
- list of File objects- Returns:
- true if there is at least one file that is not a directory
-
coverRectangle
Moves outer rectangle in such way that it must cover inner one (if outer is smaller than inner resizes outer). Modifies outer and returns it.- Parameters:
inner
- Inner rectangle.outer
- Outer rectangle.- Returns:
- Moved rectangle.
-
createRectFromList
Creates rectangle from vector of points.- Parameters:
v
- List of point- Returns:
- null if vector was empty
-
swapVector
Deprecated.Swaps vector ( first element will be last, same with others elements)- Parameters:
v
- List that be swapped.
-
getFileWithoutExtension
Returns file name without extension (removes chars from last "." to end of string)- Parameters:
filename
- The given file name
-
getFileWitoutExtention
Deprecated.type error in nameReturns file name without extension (removes chars from last "." to end of string)- Parameters:
filename
- The given file name- See Also:
-
getFileExtension
Get The given file extension.- Parameters:
file
- The given file- Returns:
- File extension
-
getFileExtension
Get the given file extension.- Parameters:
fileName
- file name- Returns:
- File extension
-
getFileName
-
getCurrentDateFormatted
-
removeComments
Removes / * * / comments from body.- Parameters:
body
- String body.- Returns:
- body without comment.
-
createCollection
@Deprecated public static <E extends Collection> E createCollection(Class<E> collection, Iterator it) Deprecated. -
notDublicatedList
Deprecated. -
trim
Removes from begin and end given Strings.- Parameters:
src
- The given string.trashBegin
- Trash string that is a beginning.trashEnd
- Trash string that is a ending.- Returns:
- String
-
replaceEpsString
Replace special char for Eps format string- Parameters:
aStr
- The given string.- Returns:
- String
-
copy
public static void copy(InputStream input, OutputStream output, long crc, boolean closeInput) throws IOException Copies all bytes from InputStream into OutputStream. Closes the streams.- Parameters:
input
- the input stream.output
- the output stream.crc
- crc to check. -1 if do not check crc.- Throws:
IOException
-
copy
public static void copy(InputStream input, OutputStream output, @CheckForNull Checksum checksum) throws IOException Copies all bytes from InputStream into OutputStream- Parameters:
input
- the input stream.output
- the output stream.checksum
- checksum.- Throws:
IOException
- exception
-
copy
Copies all bytes from InputStream into OutputStream. Closes the streams.- Parameters:
input
- the input stream.output
- the output stream.- Throws:
IOException
-
copyFile
Copy source file to destination file.- Parameters:
sourceName
- Source file name.dstName
- destination file name.- Returns:
- True if work successful.
-
copyFile
Copy source file to destination file.- Parameters:
source
- Source file.destination
- destination file.- Returns:
- true if successful.
-
copyDirectory
Copy all directory recursively -
extractZip
Extracts files from Zip archive- Parameters:
zipFile
- Zip archive filedstDir
- name of the destination directory- Throws:
IOException
-
extractZip
public static Collection<String> extractZip(InputStream is, String dstDir, Collection<String> onlyTheseEntries, Collection<String> skipTheseEntries) throws IOException Extracts files from Zip archive- Parameters:
is
- Input Stream - must be valid zip filedstDir
- destination directoryonlyTheseEntries
- if not null specifies which entries must be extracted.skipTheseEntries
- if not null specifies which entries should be skiped.- Returns:
- extracted entry names.
- Throws:
IOException
-
toByteArray
Copies the given file into the array of bytes.- Parameters:
stream
- the given file.- Returns:
- the byte array with the context of the file;null if some errors occurs
-
getItemWithText
Returns inner component (not recursively) with given text.- Parameters:
menu
- The given JPopupMenu.text
- The given text.- Returns:
- JMenuItem.
-
createCursor
Creates the cursor for given image.- Parameters:
image
- the given image.pt
- the hot point.cursorName
- the cursor name.- Returns:
- Cursor.
-
createCursor
Creates the cursor for given icon.- Parameters:
icon
- the given icon.pt
- the hot point.cursorName
- the cursor name.- Returns:
- Cursor.
-
getAsStringKeyStrokes
public static String getAsStringKeyStrokes(List<KeyStroke> shortcuts, String bracketFirst, String bracketSecond) Constructs the string representation of the given key strokes.- Parameters:
shortcuts
- The given key strokes.bracketFirst
- Open bracket.bracketSecond
- Close bracket.- Returns:
- String.
-
getAsString
Constructs the string representation of the given key stroke.- Parameters:
e
- the given key stroke.- Returns:
- String representation.
-
isValidKeyCode
public static boolean isValidKeyCode(int keyCode) Checks if given code is correct one or not.- Parameters:
keyCode
- The given key code.- Returns:
- true if given code is not CTRL, SHIFT, META or ALT.
-
isPrintableChar
public static boolean isPrintableChar(char c) Checks if char is printable or not.- Parameters:
c
- char which ic checked.- Returns:
- true if char is printable.
-
toString
Returns string representation of the given byte array.- Parameters:
data
- the given bytes array.- Returns:
- the string representation (every byte is represented as hex string separated by space)
-
toByteArray
Returns byte array from string formatted in toString(byte[]) method.- Parameters:
bytes
- the given string.- Returns:
- the byte array.
-
areChildrenDisabled
Are all children disabled?- Parameters:
menu
- the menu- Returns:
- true, if all menu children are disabled
-
normalize
Normalizes rectangle; Calculates rectangle size and location using firstCorner and secondCorner.- Parameters:
rectangle
- rectangle to normalizefirstCorner
- first cornersecondCorner
- second corner
-
normalize
normalizes rectangle mRectToDraw;- Parameters:
rect
- rectangle to normalize
-
getTempDir
Returns System temp directory.- Returns:
- string.
-
openHttpURLConnection
public static HttpURLConnection openHttpURLConnection(String pageHttpAddress, ProxyServerData proxyServerData) throws IOException Opens HttpURLConnection according given page address and proxy server data.- Parameters:
pageHttpAddress
- page address with protocol e.g"http://www.nomagic.com"
proxyServerData
- proxy server data- Returns:
- HttpURLConnection.
- Throws:
IOException
-
isUseProxy
Checks if use proxy server according given proxy server data- Parameters:
proxy
- proxy data.- Returns:
- true if use; otherwise - false
-
getHtmlPage
public static String getHtmlPage(String pageHttpAddress, String parameters, ProxyServerData proxy) throws IOException Returns HTML page- Parameters:
pageHttpAddress
- page address with protocol e.g"http://www.nomagic.com"
parameters
- parameters for POST method (null if no data to POST)proxy
- proxy server data- Returns:
- HTML page
- Throws:
IOException
-
toString
Get String representation of inputStream- Parameters:
inputStream
- The given inputStream- Returns:
- String representation.
- Throws:
IOException
-
toString
Get String representation of given strings collection- Parameters:
strings
- many strings- Returns:
- String representation.
-
sendHttpParameters
@Deprecated public static void sendHttpParameters(HttpURLConnection connection, String parameters) throws IOException Deprecated.useHttpUtilities.sendHttpParameters(HttpURLConnection, String)
Send Http Parameters.- Parameters:
connection
- HttpURLConnectionparameters
- Http Parameters.- Throws:
IOException
-
constructHttpParameter
Constructs http parameter- Parameters:
parameter
- parameter namevalue
- parameter value- Returns:
- constructed parameter
-
addHttpParameter
Adds http parameter to given parameters string- Parameters:
parameters
- parametersparameter
- parameter name to addvalue
- parameter value to add- Returns:
- constructed parameters string
-
concatHttpParameter
Concatenate given http parameters- Parameters:
parameters1
-parameters2
-- Returns:
- concatenated parameters
-
insertSeparators
Constructs string from arrays of chars. String characters are grouped into groups. Groups are separated by separator.- Parameters:
chars
- array of characters to divideseparator
- group separatorgroupSize
- size if the group- Returns:
- result string
-
removeSeparators
Removes separators from specified str- Parameters:
str
- string to uniteseparator
-- Returns:
- str without separators
-
getBytes
Returns bytes of string. 2 bytes for every char. -
distributeInteger
public static byte[] distributeInteger(int intValue, int size) Distributes integer intValue into array of bytes. int is 4 bytes, so max array size is 4- Parameters:
intValue
- int intValue to distributesize
- size of result array- Returns:
- array of bytes
-
collectInteger
public static int collectInteger(byte[] bytes) Makes int value from array of bytes- Parameters:
bytes
- array of bytes- Returns:
- int value
-
invokeAndWaitOnDispatcher
Executes given runnable on event dispatcher. Note if current thread is interrupted after runnable is submitted to the queue this method throws exception but runnable will be run on EDT.- Parameters:
r
- the given runnable- Throws:
RuntimeException
-
invokeAndWaitOnDispatcherEvenInterrupted
Executes given runnable on event dispatcher. Waits until r is finished even current thread is interrupted.- Parameters:
r
- the given runnable- Throws:
RuntimeException
-
invokeOnDispatcherOrLater
If this thread is event dispatcher, than direct calls "run", else invoke on invoke later- Parameters:
r
-
-
invokeLaterAfterCondition
Invokes runnable latter after condition is satisfied.- Parameters:
runnable
- runnable which will be executed.condition
- condition condition after which satisfaction runnable will be executed.
-
invokeLaterAfterCondition
public static void invokeLaterAfterCondition(Runnable runnable, Supplier<Boolean> condition, int conditionCheckAttemptCount) Invokes runnable latter after condition is satisfied.- Parameters:
runnable
- runnable which will be executed.condition
- condition condition after which satisfaction runnable will be executed.conditionCheckAttemptCount
- attempts count of the condition check; if count is reached before the condition is satisfied, runnable will not be executed.
-
compareStreams
Compares two input streams.- Parameters:
oldStr
- First input stream.newStr
- Second input stream.- Returns:
- true if streams contains identical data.
- Throws:
IOException
-
compareFiles
Compares two files- Parameters:
f1
- First file.f2
- Second file.- Returns:
- true if files contains identical data.
- Throws:
IOException
-
deleteTree
Removes given directory and all its contents. File.delete fails if directory is not empty- Parameters:
f
- file to delete
-
deleteTreeOnExit
Removes given file (directory and all its contents) on exit. File.delete fails if directory is not empty- Parameters:
f
- file to delete
-
deleteDirContent
Removes given directory contents. File.delete fails if directory is not empty- Parameters:
f
- file to delete
-
getGrayIcon
Deprecated.Returns grey(disabled) icon from given one.- Parameters:
icon
- the given icon.- Returns:
- disabled icon
-
getGrayIcon
@Deprecated @CheckForNull public static ResizableIcon getGrayIcon(@CheckForNull Icon icon, Component component) Deprecated.Returns grey(disabled) icon from given one.- Parameters:
icon
- the given icon.component
- component.- Returns:
- disabled icon
-
makeEqual
Make destination the same as source with minimum changes to destination- Parameters:
destination
- Listsource
- List
-
getClassName
Get class name.- Parameters:
clazz
- The given class.- Returns:
- Class name.
-
isAlphaNumeric
-
mergeLists
Merges two lists into newly created one.- Parameters:
l1
- first list.l2
- second list.- Returns:
- newly created list with added elements from l1 and l2.
-
synchronizeDirectories
Synchronize two directories. If new file appears in source, it should appear in destination. If file is removed from destination it should not appear in destination again. Typical use for this method is when one directory has default settings, and another have working copy.- Parameters:
source
- source directory.destination
- destination directory.- Throws:
IOException
-
splitString
Splits string- Parameters:
str
- a string to be parsed.delimiter
- the delimiter.returnDelimiter
- flag indicating whether to include the delimiter in result.- Returns:
- array of strings
-
implode
Returns a new String composed of copies of the collection elements joined together with a copy of the specified delimiter. Consider usingString.join(CharSequence, Iterable)
.- Parameters:
collection
- collection of elements.delimiter
- delimiter.- Returns:
- joined string.
- See Also:
-
implode
Deprecated. -
parseExceptQuotes
parses string by standard tokens, except parts wrapped in quotes -
readFileSkipFirstLines
Reads a file to string and skips a specified number of lines from the beginning.- Parameters:
file
- - file to read.n
- - number of lines to skip from the beginning.- Returns:
- file contents as string with skipped lines.
-
zipDir
Compress specified directory recursively to the specified stream.- Parameters:
dir2zip
- directory to zip.zos
-ZipOutputStream
object.- Throws:
IOException
- if any occurs during
-
compressData
Compresses specified data using zip output stream and returns the result as bytes array.- Parameters:
data
- a data.zipEntryName
- name of how the data will be named in the archive.- Returns:
- compressed data.
- Throws:
IOException
- if any occurs during compressing the data.
-
compressData
Compresses specified data using gzip output stream and returns the result as bytes array.- Parameters:
data
- a data.- Returns:
- compressed data.
- Throws:
IOException
- if any occurs during compressing the data.
-
uncompressData
Uncompresses specified data using gzip input stream and returns the result as bytes array.- Parameters:
data
- a data.- Returns:
- compressed data.
- Throws:
IOException
- if any occurs during compressing the data.
-
checkSystemProperty
Checks given system (boolean) property value- Parameters:
property
-defaultValue
-- Returns:
- value of the system property, or defaultValue if system property is not set
-
checkProperty
-
checkResolvableException
public static boolean checkResolvableException(boolean rule) if rule is false and it's DEVELOPER mode throwsIllegalStateException
- Returns:
- rule
-
dumpThreads
public static void dumpThreads()Dumps all threads to system out. -
dumpThreads
Dumps all threads to given stream. -
reverseString
Given a string, returns a string with reversed characters.- Parameters:
source
- string which has to be reversed.- Returns:
- a string with reversed characters.
-
calculateTextWidth
Calculates possible text longest text width of the given text splitted into lines.- Parameters:
text
- text for which to calculate width.metrics
- font metrics according which to calculate.numberOfLines
- number of lines into which to split the text.- Returns:
- calculated possible text width.
-
isHTMLText
Check the given string to see if it should trigger the html rendering logic.- Parameters:
s
- the given string.- Returns:
- true if given text is html, false otherwise.
-
ensureObjectIsInCollection
Ensures an object is in given collection. If it isn't, the object is added to it.- Parameters:
collection
- collection in which to check object existence.object
- object to check.
-
encodeBase64
Encodes data using base64 encoding.- Parameters:
abyte0
- data for encoding- Returns:
- encoded string
-
decodeBase64
Decode string using Base64 encoding.- Parameters:
s
- string for decoding- Returns:
- decoded data
-
hasModalDialogs
Checks recursively if given window has modal dialog as child (or window itself is a modal dialog)- Parameters:
window
- window- Returns:
- true if modal dialog is found
-
removeNewLines
Removes new lines from the string.- Parameters:
string
- string for which to remove new lines.- Returns:
- string with removed new lines.
-
checkIsInstallRootWritable
@CheckForNull public static String checkIsInstallRootWritable(com.nomagic.runtime.RuntimeEnvironment runtime) Get message for install root read only error. Returns null if install root is writable. Method is suitable for read only checking.- Parameters:
runtime
- Application runtime.- Returns:
- Message for install root read only error or null if install root is writable
-
checkIsInstallRootWritable
@CheckForNull public static String checkIsInstallRootWritable(com.nomagic.runtime.RuntimeEnvironment runtime, boolean skipWinUAC) Get message for install root read only error. Returns null if install root is writable. Method is suitable for read only checking.- Parameters:
runtime
- runtime environment.skipWinUAC
- skip checking writable install root if Windows is supporting UAC.- Returns:
- Message for install root read only error or null if install root is writable
-
main
-
getVersionFromInternal
public static String getVersionFromInternal(String internal) throws NumberFormatException, IndexOutOfBoundsException Convert internal MagicDraw style version to human version in 17.0.2 format.- Parameters:
internal
- Internal version.- Returns:
- Human version
- Throws:
NumberFormatException
- parse exception.IndexOutOfBoundsException
- if internal version is negative.
-
getVersionFromInternal
Convert internal MagicDraw style version to human version in 17.0.2 format.- Parameters:
internal
- Internal version.- Returns:
- human version
- Throws:
IndexOutOfBoundsException
- if internal version is negative.
-
containSameElements
-
arrayHash
public static int arrayHash(byte[] array) Calculate hash code for array of bytes- Parameters:
array
- bytes- Returns:
- hash code
-
isStreamEmpty
Check if it is possible to open a stream from a given URL and that stream is not empty- Parameters:
url
- url to check- Returns:
- true if not empty stream is opened from a given url
-
insertPeriodically
-
sha1Hex
Returns SHA-1 hash key that should be constructed from the specified strings.- Parameters:
strings
- array of strings.- Returns:
- SHA-1 hash key.
- Throws:
NoSuchAlgorithmException
-
sha1Hex
Returns SHA-1 hash key that should be constructed from the specified data.- Parameters:
data
- array of bytes- Returns:
- SHA-1 hash key.
- Throws:
NoSuchAlgorithmException
-
getDistance
Calculate minimal distance in graph.- Type Parameters:
E
- type of node.- Parameters:
from
- starting point in graph.to
- destination point in graph.connectedNodes
- function to get connected edges.- Returns:
- minimal number of steps required to get from node from to node to. Return -1 if nodes are not connected.
-
contentEquals
Compare content of two streams.- Parameters:
input1
- first stream.input2
- another stream.- Returns:
- true if stream provides exactly same content.
-
getSystemDateFormat
Returns system date format. Ordinary Java date format getting methods returns format taken from locale, which can be different from real system date format, set in calendar settings.- Parameters:
style
- Format style (e.g.DateFormat.SHORT
,DateFormat.LONG
).- Returns:
- System date format. If can't get it, returns SimpleDateFormat.
-
isFileNameValid
Returns if given file name is valid to be created.- Parameters:
fileName
- file name- Returns:
- true if file name can be created or already exists, else false
-
excludeCommonElements
Creates result collection which contains not common elements from two arguments- Type Parameters:
T
- type of collection- Parameters:
first
- first collectionsecond
- second collection- Returns:
- not common elements of two arguments
-
isNameValid
-
getThreadsInfo
-
CollectionUtils.append(java.util.Collection, java.util.Collection, boolean)