Package com.nomagic.utils
Class Utilities
- java.lang.Object
-
- com.nomagic.utils.CameoUtilities
-
- com.nomagic.utils.Utilities
-
@OpenApiAll public class Utilities extends CameoUtilities
General purpose utilities.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
private static java.util.function.Supplier<java.text.spi.DateFormatProvider>
dateFormatSupplier
Provider for user configured date formatprivate static org.apache.logging.log4j.Logger
LOGGER
-
Constructor Summary
Constructors Constructor Description Utilities()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.lang.String
addHttpParameter(java.lang.String parameters, java.lang.String parameter, java.lang.String value)
Adds http parameter to given parameters stringstatic <T> java.util.Collection<T>
append(java.util.Collection<T> source, java.util.Collection<? extends T> v, boolean allowDublication)
static <T> java.util.Collection<T>
append(java.util.Collection<T> source, java.util.Iterator<? extends T> it, boolean allowDublication)
static boolean
areChildrenDisabled(javax.swing.JMenu menu)
Are all children disabled?static int
arrayHash(byte[] array)
Calculate hash code for array of bytesstatic int
calculateTextWidth(java.lang.String text, java.awt.FontMetrics metrics, int numberOfLines)
Calculates possible text longest text width of the given text splitted into lines.static java.lang.String
checkIsInstallRootWritable(com.nomagic.runtime.RuntimeEnvironment runtime)
Get message for install root read only error.static java.lang.String
checkIsInstallRootWritable(com.nomagic.runtime.RuntimeEnvironment runtime, boolean skipWinUAC)
Get message for install root read only error.static boolean
checkProperty(java.util.Properties properties, java.lang.String property, boolean defaultValue)
static boolean
checkResolvableException(boolean rule)
if rule is false and it's DEVELOPER mode throwsIllegalStateException
static boolean
checkSystemProperty(java.lang.String property, boolean defaultValue)
Checks given system (boolean) property valuestatic java.lang.String
clearAllLine(java.lang.String src, java.lang.String trash)
Removes all trash from stringstatic java.lang.String
clearFromEveryLine(java.lang.String text, java.lang.String mask)
Divides given string into lines and from every line beginning and end removes all chars from given string mask.static java.lang.String
clearLine(java.lang.String line, java.lang.String trash)
removes from line ends wanted charactersstatic int
collectInteger(byte[] bytes)
Makes int value from array of bytesstatic boolean
compareFiles(java.io.File f1, java.io.File f2)
Compares two filesstatic boolean
compareStreams(java.io.InputStream oldStr, java.io.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, java.lang.String zipEntryName)
Compresses specified data using zip output stream and returns the result as bytes array.static java.lang.String
concatHttpParameter(java.lang.String parameters1, java.lang.String parameters2)
Concatenate given http parametersstatic java.lang.String
constructHttpParameter(java.lang.String parameter, java.lang.String value)
Constructs http parameterstatic boolean
contains(java.util.Iterator it, java.lang.Object o)
Deprecated.static boolean
containSameElements(java.util.Collection<?> collection1, java.util.Collection<?> collection2)
static boolean
containsAny(java.util.Collection location, java.util.Collection what)
static boolean
containsNonDirectory(java.util.List<java.io.File> fileList)
static boolean
containsOnlyFiles(java.util.List list)
Indicates if given list contains only file objects.static boolean
contentEquals(java.io.InputStream input1, java.io.InputStream input2)
Compare content of two streams.static void
copy(java.io.InputStream input, java.io.OutputStream output)
Copies all bytes from InputStream into OutputStream.static void
copy(java.io.InputStream input, java.io.OutputStream output, long crc, boolean closeInput)
Copies all bytes from InputStream into OutputStream.static void
copy(java.io.InputStream input, java.io.OutputStream output, java.util.zip.Checksum checksum)
Copies all bytes from InputStream into OutputStreamstatic boolean
copyDirectory(java.io.File source, java.io.File destination)
Copy all directory recursivelystatic boolean
copyFile(java.io.File source, java.io.File destination)
Copy source file to destination file.static boolean
copyFile(java.lang.String sourceName, java.lang.String dstName)
Copy source file to destination file.static int
countOccurrences(java.lang.String string, char c)
Returns the number of times the character c appears in a string.static java.awt.Rectangle
coverRectangle(java.awt.Rectangle inner, java.awt.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 java.util.Collection>
EcreateCollection(java.lang.Class<E> collection, java.util.Iterator it)
Deprecated.static java.awt.Cursor
createCursor(java.awt.Image image, java.awt.Point pt, java.lang.String cursorName)
Creates the cursor for given image.static java.awt.Cursor
createCursor(javax.swing.Icon icon, java.awt.Point pt, java.lang.String cursorName)
Creates the cursor for given icon.static java.awt.Rectangle
createRectFromList(java.util.List<java.awt.Point> v)
Creates rectangle from vector of points.static java.lang.String
createStringRepresentation(java.util.Collection value)
static byte[]
decodeBase64(java.lang.String s)
Decode string using Base64 encoding.static java.util.List<java.awt.Point>
deepPointsClone(java.util.List<java.awt.Point> v)
Makes a deep clone of vector that contains points.static java.util.List<java.awt.Point>
deepPointsClone(java.util.List<java.awt.Point> v, boolean cloneList)
Makes a deep clone of vector that contains points.static void
deleteDirContent(java.io.File f)
Removes given directory contents.static void
deleteTree(java.io.File f)
Removes given directory and all its contents.static void
deleteTreeOnExit(java.io.File f)
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
dumpThreads()
Dumps all threads to system out.static void
dumpThreads(java.io.PrintStream out)
Dumps all threads to given stream.static java.lang.String
encodeBase64(byte[] abyte0)
Encodes data using base64 encoding.private static char[]
encodeBlock(byte[] abyte0, int i)
static <T> void
ensureObjectIsInCollection(java.util.Collection<T> collection, T object)
Ensures an object is in given collection.static <T> java.util.Set<T>
excludeCommonElements(java.util.Collection<T> first, java.util.Collection<T> second)
Creates result collection which contains not common elements from two argumentsstatic java.util.Collection<java.lang.String>
extractZip(java.io.InputStream is, java.lang.String dstDir, java.util.Collection<java.lang.String> onlyTheseEntries, java.util.Collection<java.lang.String> skipTheseEntries)
Extracts files from Zip archivestatic void
extractZip(java.util.zip.ZipFile zipFile, java.lang.String dstDir)
Extracts files from Zip archivestatic java.awt.Rectangle
fitInRectangle(java.awt.Rectangle small, java.awt.Rectangle big)
recalculate bounds to fit in rectanglestatic java.lang.String
getAsString(javax.swing.KeyStroke e)
Constructs the string representation of the given key stroke.static java.lang.String
getAsStringKeyStrokes(java.util.List shortcuts, java.lang.String bracketFirst, java.lang.String bracketSecond)
Constructs the string representation of the given key strokes.static byte[]
getBytes(java.lang.String str)
Returns bytes of string.private static char
getChar(int i)
static java.lang.String
getClassName(java.lang.Class clazz)
Get class name.static java.lang.String
getCurrentDateFormatted()
static <E> int
getDistance(E from, E to, java.util.function.Function<E,java.util.Collection<E>> connectedNodes)
Calculate minimal distance in graph.static java.lang.String
getFileExtension(java.io.File file)
Get The given file extension.static java.lang.String
getFileExtension(java.lang.String fileName)
Get the given file extension.static java.lang.String
getFileName(java.lang.String text)
static java.lang.String
getFileWithoutExtension(java.lang.String filename)
Returns file name without extension (removes chars from last "." to end of string)static java.lang.String
getFileWitoutExtention(java.lang.String filename)
Deprecated.type error in namestatic ResizableIcon
getGrayIcon(javax.swing.Icon icon)
Deprecated.static ResizableIcon
getGrayIcon(javax.swing.Icon icon, java.awt.Component component)
Deprecated.static java.lang.String
getHtmlPage(java.lang.String pageHttpAddress, java.lang.String parameters, ProxyServerData proxy)
Returns HTML pagestatic javax.swing.JMenuItem
getItemWithText(javax.swing.JPopupMenu menu, java.lang.String text)
Returns inner component (not recursively) with given text.static java.text.DateFormat
getSystemDateFormat(int style)
Returns system date format.static java.lang.String
getTempDir()
Returns System temp directory.static java.lang.String
getThreadsInfo()
private static int
getValue(char c)
static java.lang.String
getVersionFromInternal(int internal)
Convert internal MagicDraw style version to human version in 17.0.2 format.static java.lang.String
getVersionFromInternal(java.lang.String internal)
Convert internal MagicDraw style version to human version in 17.0.2 format.static boolean
hasExtension(java.lang.String name, java.lang.String extension)
Checks if given file name has given file extension.static boolean
hasExtension(java.lang.String name, java.util.List extensions)
Checks if given file name has one of given file extensions.static boolean
hasModalDialogs(java.awt.Window window)
Checks recursively if given window has modal dialog as child (or window itself is a modal dialog)static java.lang.String
implode(java.lang.String[] values, java.lang.String delimiter)
Deprecated.UseString.join(CharSequence, CharSequence...)
static java.lang.String
implode(java.util.Collection collection, java.lang.String delimiter)
Returns a new String composed of copies of the collection elements joined together with a copy of the specified delimiter.static java.lang.String
insertPeriodically(java.lang.String text, java.lang.String insert, int period)
static java.lang.String
insertSeparators(char[] chars, java.lang.String separator, int groupSize)
Constructs string from arrays of chars.static void
invokeAndWaitOnDispatcher(java.lang.Runnable r)
Executes given runnable on event dispatcher.static void
invokeAndWaitOnDispatcherEvenInterrupted(java.lang.Runnable r)
Executes given runnable on event dispatcher.static void
invokeLaterAfterCondition(java.lang.Runnable runnable, java.util.function.Supplier<java.lang.Boolean> condition)
Invokes runnable latter after condition is satisfied.static void
invokeLaterAfterCondition(java.lang.Runnable runnable, java.util.function.Supplier<java.lang.Boolean> condition, int conditionCheckAttemptCount)
Invokes runnable latter after condition is satisfied.static void
invokeOnDispatcherOrLater(java.lang.Runnable r)
If this thread is event dispatcher, than direct calls "run", else invoke on invoke laterstatic boolean
isAlphaNumeric(java.lang.String str)
static boolean
isFileNameValid(java.lang.String fileName)
Returns if given file name is valid to be created.static boolean
isHTMLText(java.lang.String s)
Check the given string to see if it should trigger the html rendering logic.static boolean
isNameValid(java.lang.String name)
static boolean
isPrintableChar(char c)
Checks if char is printable or not.static boolean
isStreamEmpty(java.net.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
main(java.lang.String[] args)
static void
makeEqual(java.util.List destination, java.util.List source)
Make destination the same as source with minimum changes to destinationstatic boolean
match(java.lang.String pattern, java.lang.String string)
Checks if given string matches given pattern with wild cards.static boolean
matchIncludingEmpty(java.lang.String pattern, java.lang.String string)
Checks if given string matches given pattern with wild cards.static <T> void
merge(java.util.List<T> source, java.util.List<T> v)
Merges two vector.static <T> java.util.List<T>
mergeLists(java.util.List<T> l1, java.util.List<T> l2)
Merges two lists into newly created one.static void
normalize(java.awt.Rectangle rect)
normalizes rectangle mRectToDraw;static void
normalize(java.awt.Rectangle rectangle, java.awt.Point firstCorner, java.awt.Point secondCorner)
Normalizes rectangle; Calculates rectangle size and location using firstCorner and secondCorner.static java.util.Collection
notDublicatedList(java.util.Collection col)
Deprecated.static java.net.HttpURLConnection
openHttpURLConnection(java.lang.String pageHttpAddress, ProxyServerData proxyServerData)
Opens HttpURLConnection according given page address and proxy server data.static java.lang.String[]
parseExceptQuotes(java.lang.String cmd)
parses string by standard tokens, except parts wrapped in quotesstatic java.lang.String
readFileSkipFirstLines(java.io.File file, int n)
Reads a file to string and skips a specified number of lines from the beginning.static java.lang.String
removeComments(java.lang.String body)
Removes / * * / comments from body.static java.lang.String
removeExtension(java.lang.String name, java.util.Collection<java.lang.String> extensions)
Removes file extension form given file name.static java.lang.String
removeNewLines(java.lang.String string)
Removes new lines from the string.static java.lang.String
removeNonUtf8CompliantCharacters(java.lang.String inString)
static java.lang.String
removeSeparators(java.lang.String str, java.lang.String separator)
Removes separators from specified strstatic java.lang.String
replace(java.lang.String src, java.lang.String pattern, java.lang.String replaceWith)
Replaces string fragment with another stringstatic java.lang.String
replaceEpsString(java.lang.String aStr)
Replace special char for Eps format stringstatic java.lang.String
reverseString(java.lang.String source)
Given a string, returns a string with reversed characters.static void
sendHttpParameters(java.net.HttpURLConnection connection, java.lang.String parameters)
Deprecated.useHttpUtilities.sendHttpParameters(HttpURLConnection, String)
static java.lang.String
sha1Hex(byte[] data)
Returns SHA-1 hash key that should be constructed from the specified data.static java.lang.String
sha1Hex(java.lang.String... strings)
Returns SHA-1 hash key that should be constructed from the specified strings.static void
sortStrings(java.util.Vector elem)
Sorts elements in strings' vectorstatic java.lang.String[]
splitString(java.lang.String str, java.lang.String delimiter, boolean returnDelimiter)
Splits stringstatic void
swapVector(java.util.List v)
Deprecated.useCollections.reverse(java.util.List<?>)
static void
synchronizeDirectories(java.io.File source, java.io.File destination)
Synchronize two directories.static byte[]
toByteArray(java.io.InputStream stream)
Copies the given file into the array of bytes.static byte[]
toByteArray(java.lang.String bytes)
Returns byte array from string formatted in toString(byte[]) method.static java.lang.String
toString(byte[] data)
Returns string representation of the given byte array.static java.lang.String
toString(java.io.InputStream inputStream)
Get String representation of inputStreamstatic java.lang.String
toString(java.util.Collection<java.lang.String> strings)
Get String representation of given strings collectionstatic java.lang.String
trim(java.lang.String src, java.lang.String trashBegin, java.lang.String trashEnd)
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.private static void
zipDir(java.io.File dir, java.util.zip.ZipOutputStream zos, int rootCanonicalPathLength)
static void
zipDir(java.lang.String dir2zip, java.util.zip.ZipOutputStream zos)
Compress specified directory recursively to the specified stream.-
Methods inherited from class com.nomagic.utils.CameoUtilities
copy, isEqual, isEqual, removeFromLine, replaceNewLine, toString
-
-
-
-
Field Detail
-
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
dateFormatSupplier
@CheckForNull private static java.util.function.Supplier<java.text.spi.DateFormatProvider> dateFormatSupplier
Provider for user configured date format
-
-
Method Detail
-
hasExtension
public static boolean hasExtension(java.lang.String name, java.util.List extensions)
Checks if given file name has one of given file extensions.
-
hasExtension
public static boolean hasExtension(java.lang.String name, java.lang.String extension)
Checks if given file name has given file extension.
-
removeExtension
public static java.lang.String removeExtension(java.lang.String name, java.util.Collection<java.lang.String> extensions)
Removes file extension form given file name.
-
createStringRepresentation
public static java.lang.String createStringRepresentation(java.util.Collection value)
-
deepPointsClone
public static java.util.List<java.awt.Point> deepPointsClone(java.util.List<java.awt.Point> v)
Makes a deep clone of vector that contains points.- Parameters:
v
- List of point.- Returns:
- vector
-
deepPointsClone
public static java.util.List<java.awt.Point> deepPointsClone(java.util.List<java.awt.Point> v, boolean cloneList)
Makes a deep clone of vector that contains points.- Parameters:
v
- List of point.cloneList
- True if clone to new list.- Returns:
- vector
-
replace
public static java.lang.String replace(java.lang.String src, java.lang.String pattern, java.lang.String replaceWith)
Replaces string fragment with another string- Parameters:
src
- Source string.pattern
- String pattern.replaceWith
- The another string.- Returns:
- string.
-
match
public static boolean match(java.lang.String pattern, java.lang.String string)
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
public static boolean matchIncludingEmpty(java.lang.String pattern, java.lang.String string)
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
public static void sortStrings(java.util.Vector elem)
Sorts elements in strings' vector- Parameters:
elem
- The given vector.
-
clearLine
public static java.lang.String clearLine(java.lang.String line, java.lang.String trash)
removes from line ends wanted characters- Parameters:
line
- The given line.trash
- characters as string.- Returns:
- String.
-
clearAllLine
public static java.lang.String clearAllLine(java.lang.String src, java.lang.String trash)
Removes all trash from string- Parameters:
src
- String that be removed trashtrash
- Trash string.- Returns:
- String.
-
merge
public static <T> void merge(java.util.List<T> source, java.util.List<T> v)
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> java.util.Collection<T> append(java.util.Collection<T> source, java.util.Collection<? extends T> v, boolean allowDublication)
-
append
@Deprecated public static <T> java.util.Collection<T> append(java.util.Collection<T> source, java.util.Iterator<? extends T> it, boolean allowDublication)
-
contains
@Deprecated public static boolean contains(java.util.Iterator it, java.lang.Object o)
Deprecated.
-
containsAny
@Deprecated public static boolean containsAny(java.util.Collection location, java.util.Collection what)
-
clearFromEveryLine
public static java.lang.String clearFromEveryLine(java.lang.String text, java.lang.String mask)
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
public static int countOccurrences(java.lang.String string, char c)
Returns the number of times the character c appears in a string.- Parameters:
string
- The given stringc
- character- Returns:
- number of time
-
removeNonUtf8CompliantCharacters
public static java.lang.String removeNonUtf8CompliantCharacters(java.lang.String inString)
-
fitInRectangle
public static java.awt.Rectangle fitInRectangle(java.awt.Rectangle small, java.awt.Rectangle big)
recalculate bounds to fit in rectangle- Parameters:
small
- Small rectanglebig
- Big rectangle- Returns:
- New rectangle
-
containsOnlyFiles
public static boolean containsOnlyFiles(java.util.List list)
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
public static boolean containsNonDirectory(java.util.List<java.io.File> fileList)
- Parameters:
fileList
- list of File objects- Returns:
- true if there is at least one file that is not a directory
-
coverRectangle
public static java.awt.Rectangle coverRectangle(java.awt.Rectangle inner, java.awt.Rectangle outer)
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
@CheckForNull public static java.awt.Rectangle createRectFromList(java.util.List<java.awt.Point> v)
Creates rectangle from vector of points.- Parameters:
v
- List of point- Returns:
- null if vector was empty
-
swapVector
@Deprecated public static void swapVector(java.util.List v)
Deprecated.useCollections.reverse(java.util.List<?>)
Swaps vector ( first element will be last, same with others elements)- Parameters:
v
- List that be swapped.
-
getFileWithoutExtension
public static java.lang.String getFileWithoutExtension(java.lang.String filename)
Returns file name without extension (removes chars from last "." to end of string)- Parameters:
filename
- The given file name
-
getFileWitoutExtention
@Deprecated public static java.lang.String getFileWitoutExtention(java.lang.String filename)
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:
getFileWithoutExtension(String)
-
getFileExtension
@CheckForNull public static java.lang.String getFileExtension(java.io.File file)
Get The given file extension.- Parameters:
file
- The given file- Returns:
- File extension
-
getFileExtension
@CheckForNull public static java.lang.String getFileExtension(java.lang.String fileName)
Get the given file extension.- Parameters:
fileName
- file name- Returns:
- File extension
-
getFileName
public static java.lang.String getFileName(java.lang.String text)
-
getCurrentDateFormatted
public static java.lang.String getCurrentDateFormatted()
-
removeComments
public static java.lang.String removeComments(java.lang.String body)
Removes / * * / comments from body.- Parameters:
body
- String body.- Returns:
- body without comment.
-
createCollection
@Deprecated public static <E extends java.util.Collection> E createCollection(java.lang.Class<E> collection, java.util.Iterator it)
Deprecated.
-
notDublicatedList
@Deprecated public static java.util.Collection notDublicatedList(java.util.Collection col)
Deprecated.
-
trim
public static java.lang.String trim(java.lang.String src, java.lang.String trashBegin, java.lang.String trashEnd)
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
public static java.lang.String replaceEpsString(java.lang.String aStr)
Replace special char for Eps format string- Parameters:
aStr
- The given string.- Returns:
- String
-
copy
public static void copy(java.io.InputStream input, java.io.OutputStream output, long crc, boolean closeInput) throws java.io.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:
java.io.IOException
-
copy
public static void copy(java.io.InputStream input, java.io.OutputStream output, @CheckForNull java.util.zip.Checksum checksum) throws java.io.IOException
Copies all bytes from InputStream into OutputStream- Parameters:
input
- the input stream.output
- the output stream.checksum
- checksum.- Throws:
java.io.IOException
- exception
-
copy
public static void copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
Copies all bytes from InputStream into OutputStream. Closes the streams.- Parameters:
input
- the input stream.output
- the output stream.- Throws:
java.io.IOException
-
copyFile
public static boolean copyFile(java.lang.String sourceName, java.lang.String dstName)
Copy source file to destination file.- Parameters:
sourceName
- Source file name.dstName
- destination file name.- Returns:
- True if work successful.
-
copyFile
public static boolean copyFile(java.io.File source, java.io.File destination)
Copy source file to destination file.- Parameters:
source
- Source file.destination
- destination file.- Returns:
- true if successful.
-
copyDirectory
public static boolean copyDirectory(java.io.File source, java.io.File destination)
Copy all directory recursively
-
extractZip
public static void extractZip(java.util.zip.ZipFile zipFile, java.lang.String dstDir) throws java.io.IOException
Extracts files from Zip archive- Parameters:
zipFile
- Zip archive filedstDir
- name of the destination directory- Throws:
java.io.IOException
-
extractZip
public static java.util.Collection<java.lang.String> extractZip(java.io.InputStream is, java.lang.String dstDir, java.util.Collection<java.lang.String> onlyTheseEntries, java.util.Collection<java.lang.String> skipTheseEntries) throws java.io.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:
java.io.IOException
-
toByteArray
public static byte[] toByteArray(java.io.InputStream stream)
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
public static javax.swing.JMenuItem getItemWithText(javax.swing.JPopupMenu menu, java.lang.String text)
Returns inner component (not recursively) with given text.- Parameters:
menu
- The given JPopupMenu.text
- The given text.- Returns:
- JMenuItem.
-
createCursor
public static java.awt.Cursor createCursor(java.awt.Image image, java.awt.Point pt, java.lang.String cursorName)
Creates the cursor for given image.- Parameters:
image
- the given image.pt
- the hot point.cursorName
- the cursor name.- Returns:
- Cursor.
-
createCursor
public static java.awt.Cursor createCursor(javax.swing.Icon icon, java.awt.Point pt, java.lang.String cursorName)
Creates the cursor for given icon.- Parameters:
icon
- the given icon.pt
- the hot point.cursorName
- the cursor name.- Returns:
- Cursor.
-
getAsStringKeyStrokes
public static java.lang.String getAsStringKeyStrokes(java.util.List shortcuts, java.lang.String bracketFirst, java.lang.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
public static java.lang.String getAsString(@CheckForNull javax.swing.KeyStroke e)
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
public static java.lang.String toString(byte[] data)
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
public static byte[] toByteArray(java.lang.String bytes)
Returns byte array from string formatted in toString(byte[]) method.- Parameters:
bytes
- the given string.- Returns:
- the byte array.
-
areChildrenDisabled
public static boolean areChildrenDisabled(javax.swing.JMenu menu)
Are all children disabled?- Parameters:
menu
- the menu- Returns:
- true, if all menu children are disabled
-
normalize
public static void normalize(java.awt.Rectangle rectangle, java.awt.Point firstCorner, java.awt.Point secondCorner)
Normalizes rectangle; Calculates rectangle size and location using firstCorner and secondCorner.- Parameters:
rectangle
- rectangle to normalizefirstCorner
- first cornersecondCorner
- second corner
-
normalize
public static void normalize(java.awt.Rectangle rect)
normalizes rectangle mRectToDraw;- Parameters:
rect
- rectangle to normalize
-
getTempDir
public static java.lang.String getTempDir()
Returns System temp directory.- Returns:
- string.
-
openHttpURLConnection
public static java.net.HttpURLConnection openHttpURLConnection(java.lang.String pageHttpAddress, ProxyServerData proxyServerData) throws java.io.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:
java.io.IOException
-
isUseProxy
public static boolean isUseProxy(ProxyServerData proxy)
Checks if use proxy server according given proxy server data- Parameters:
proxy
- proxy data.- Returns:
- true if use; otherwise - false
-
getHtmlPage
public static java.lang.String getHtmlPage(java.lang.String pageHttpAddress, java.lang.String parameters, ProxyServerData proxy) throws java.io.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:
java.io.IOException
-
toString
public static java.lang.String toString(java.io.InputStream inputStream) throws java.io.IOException
Get String representation of inputStream- Parameters:
inputStream
- The given inputStream- Returns:
- String representation.
- Throws:
java.io.IOException
-
toString
public static java.lang.String toString(java.util.Collection<java.lang.String> strings)
Get String representation of given strings collection- Parameters:
strings
- many strings- Returns:
- String representation.
-
sendHttpParameters
@Deprecated public static void sendHttpParameters(java.net.HttpURLConnection connection, java.lang.String parameters) throws java.io.IOException
Deprecated.useHttpUtilities.sendHttpParameters(HttpURLConnection, String)
Send Http Parameters.- Parameters:
connection
- HttpURLConnectionparameters
- Http Parameters.- Throws:
java.io.IOException
-
constructHttpParameter
public static java.lang.String constructHttpParameter(java.lang.String parameter, java.lang.String value)
Constructs http parameter- Parameters:
parameter
- parameter namevalue
- parameter value- Returns:
- constructed parameter
-
addHttpParameter
public static java.lang.String addHttpParameter(java.lang.String parameters, java.lang.String parameter, java.lang.String value)
Adds http parameter to given parameters string- Parameters:
parameters
- parametersparameter
- parameter name to addvalue
- parameter value to add- Returns:
- constructed parameters string
-
concatHttpParameter
public static java.lang.String concatHttpParameter(java.lang.String parameters1, java.lang.String parameters2)
Concatenate given http parameters- Parameters:
parameters1
-parameters2
-- Returns:
- concatenated parameters
-
insertSeparators
public static java.lang.String insertSeparators(char[] chars, java.lang.String separator, int groupSize)
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
public static java.lang.String removeSeparators(java.lang.String str, java.lang.String separator)
Removes separators from specified str- Parameters:
str
- string to uniteseparator
-- Returns:
- str without separators
-
getBytes
public static byte[] getBytes(java.lang.String str)
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
public static void invokeAndWaitOnDispatcher(java.lang.Runnable r) throws java.lang.RuntimeException
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:
java.lang.RuntimeException
-
invokeAndWaitOnDispatcherEvenInterrupted
public static void invokeAndWaitOnDispatcherEvenInterrupted(java.lang.Runnable r) throws java.lang.RuntimeException
Executes given runnable on event dispatcher. Waits until r is finished even current thread is interrupted.- Parameters:
r
- the given runnable- Throws:
java.lang.RuntimeException
-
invokeOnDispatcherOrLater
public static void invokeOnDispatcherOrLater(java.lang.Runnable r)
If this thread is event dispatcher, than direct calls "run", else invoke on invoke later- Parameters:
r
-
-
invokeLaterAfterCondition
public static void invokeLaterAfterCondition(java.lang.Runnable runnable, java.util.function.Supplier<java.lang.Boolean> condition)
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(java.lang.Runnable runnable, java.util.function.Supplier<java.lang.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
public static boolean compareStreams(java.io.InputStream oldStr, java.io.InputStream newStr) throws java.io.IOException
Compares two input streams.- Parameters:
oldStr
- First input stream.newStr
- Second input stream.- Returns:
- true if streams contains identical data.
- Throws:
java.io.IOException
-
compareFiles
public static boolean compareFiles(java.io.File f1, java.io.File f2) throws java.io.IOException
Compares two files- Parameters:
f1
- First file.f2
- Second file.- Returns:
- true if files contains identical data.
- Throws:
java.io.IOException
-
deleteTree
public static void deleteTree(@Nonnull java.io.File f)
Removes given directory and all its contents. File.delete fails if directory is not empty- Parameters:
f
- file to delete
-
deleteTreeOnExit
public static void deleteTreeOnExit(java.io.File f)
Removes given file (directory and all its contents) on exit. File.delete fails if directory is not empty- Parameters:
f
- file to delete
-
deleteDirContent
public static void deleteDirContent(java.io.File f)
Removes given directory contents. File.delete fails if directory is not empty- Parameters:
f
- file to delete
-
getGrayIcon
@Deprecated @CheckForNull public static ResizableIcon getGrayIcon(@CheckForNull javax.swing.Icon icon)
Deprecated.Returns grey(disabled) icon from given one.- Parameters:
icon
- the given icon.- Returns:
- disabled icon
-
getGrayIcon
@Deprecated @CheckForNull public static ResizableIcon getGrayIcon(@CheckForNull javax.swing.Icon icon, java.awt.Component component)
Deprecated.Returns grey(disabled) icon from given one.- Parameters:
icon
- the given icon.component
- component.- Returns:
- disabled icon
-
makeEqual
public static void makeEqual(java.util.List destination, java.util.List source)
Make destination the same as source with minimum changes to destination- Parameters:
destination
- Listsource
- List
-
getClassName
public static java.lang.String getClassName(java.lang.Class clazz)
Get class name.- Parameters:
clazz
- The given class.- Returns:
- Class name.
-
isAlphaNumeric
public static boolean isAlphaNumeric(java.lang.String str)
-
mergeLists
public static <T> java.util.List<T> mergeLists(java.util.List<T> l1, java.util.List<T> l2)
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
public static void synchronizeDirectories(java.io.File source, java.io.File destination) throws java.io.IOException
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:
java.io.IOException
-
splitString
public static java.lang.String[] splitString(java.lang.String str, java.lang.String delimiter, boolean returnDelimiter)
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
public static java.lang.String implode(java.util.Collection collection, java.lang.String delimiter)
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:
String.join(CharSequence, Iterable)
-
implode
@Deprecated public static java.lang.String implode(java.lang.String[] values, java.lang.String delimiter)
Deprecated.UseString.join(CharSequence, CharSequence...)
-
parseExceptQuotes
public static java.lang.String[] parseExceptQuotes(java.lang.String cmd)
parses string by standard tokens, except parts wrapped in quotes
-
readFileSkipFirstLines
public static java.lang.String readFileSkipFirstLines(java.io.File file, int n)
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
public static void zipDir(java.lang.String dir2zip, java.util.zip.ZipOutputStream zos) throws java.io.IOException
Compress specified directory recursively to the specified stream.- Parameters:
dir2zip
- directory to zip.zos
-ZipOutputStream
object.- Throws:
java.io.IOException
- if any occurs during
-
zipDir
private static void zipDir(java.io.File dir, java.util.zip.ZipOutputStream zos, int rootCanonicalPathLength) throws java.io.IOException
- Throws:
java.io.IOException
-
compressData
public static byte[] compressData(byte[] data, java.lang.String zipEntryName) throws java.io.IOException
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:
java.io.IOException
- if any occurs during compressing the data.
-
compressData
public static byte[] compressData(byte[] data) throws java.io.IOException
Compresses specified data using gzip output stream and returns the result as bytes array.- Parameters:
data
- a data.- Returns:
- compressed data.
- Throws:
java.io.IOException
- if any occurs during compressing the data.
-
uncompressData
public static byte[] uncompressData(byte[] data) throws java.io.IOException
Uncompresses specified data using gzip input stream and returns the result as bytes array.- Parameters:
data
- a data.- Returns:
- compressed data.
- Throws:
java.io.IOException
- if any occurs during compressing the data.
-
checkSystemProperty
public static boolean checkSystemProperty(java.lang.String property, boolean defaultValue)
Checks given system (boolean) property value- Parameters:
property
-defaultValue
-- Returns:
- value of the system property, or defaultValue if system property is not set
-
checkProperty
public static boolean checkProperty(java.util.Properties properties, java.lang.String property, boolean defaultValue)
-
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
public static void dumpThreads(java.io.PrintStream out)
Dumps all threads to given stream.
-
reverseString
public static java.lang.String reverseString(java.lang.String source)
Given a string, returns a string with reversed characters.- Parameters:
source
- string which has to be reversed.- Returns:
- a string with reversed characters.
-
calculateTextWidth
public static int calculateTextWidth(java.lang.String text, java.awt.FontMetrics metrics, int numberOfLines)
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
public static boolean isHTMLText(java.lang.String s)
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
public static <T> void ensureObjectIsInCollection(java.util.Collection<T> collection, T object)
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
public static java.lang.String encodeBase64(byte[] abyte0)
Encodes data using base64 encoding.- Parameters:
abyte0
- data for encoding- Returns:
- encoded string
-
encodeBlock
private static char[] encodeBlock(byte[] abyte0, int i)
-
getChar
private static char getChar(int i)
-
decodeBase64
public static byte[] decodeBase64(java.lang.String s)
Decode string using Base64 encoding.- Parameters:
s
- string for decoding- Returns:
- decoded data
-
getValue
private static int getValue(char c)
-
hasModalDialogs
public static boolean hasModalDialogs(java.awt.Window window)
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
public static java.lang.String removeNewLines(java.lang.String string)
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 java.lang.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 java.lang.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
public static void main(java.lang.String[] args)
-
getVersionFromInternal
public static java.lang.String getVersionFromInternal(java.lang.String internal) throws java.lang.NumberFormatException, java.lang.IndexOutOfBoundsException
Convert internal MagicDraw style version to human version in 17.0.2 format.- Parameters:
internal
- Internal version.- Returns:
- Human version
- Throws:
java.lang.NumberFormatException
- parse exception.java.lang.IndexOutOfBoundsException
- if internal version is negative.
-
getVersionFromInternal
public static java.lang.String getVersionFromInternal(int internal) throws java.lang.IndexOutOfBoundsException
Convert internal MagicDraw style version to human version in 17.0.2 format.- Parameters:
internal
- Internal version.- Returns:
- human version
- Throws:
java.lang.IndexOutOfBoundsException
- if internal version is negative.
-
containSameElements
public static boolean containSameElements(java.util.Collection<?> collection1, java.util.Collection<?> collection2)
-
arrayHash
public static int arrayHash(byte[] array)
Calculate hash code for array of bytes- Parameters:
array
- bytes- Returns:
- hash code
-
isStreamEmpty
public static boolean isStreamEmpty(java.net.URL url)
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
public static java.lang.String insertPeriodically(java.lang.String text, java.lang.String insert, int period)
-
sha1Hex
public static java.lang.String sha1Hex(java.lang.String... strings) throws java.security.NoSuchAlgorithmException
Returns SHA-1 hash key that should be constructed from the specified strings.- Parameters:
strings
- array of strings.- Returns:
- SHA-1 hash key.
- Throws:
java.security.NoSuchAlgorithmException
-
sha1Hex
public static java.lang.String sha1Hex(byte[] data) throws java.security.NoSuchAlgorithmException
Returns SHA-1 hash key that should be constructed from the specified data.- Parameters:
data
- array of bytes- Returns:
- SHA-1 hash key.
- Throws:
java.security.NoSuchAlgorithmException
-
getDistance
public static <E> int getDistance(E from, E to, java.util.function.Function<E,java.util.Collection<E>> connectedNodes)
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
public static boolean contentEquals(java.io.InputStream input1, java.io.InputStream input2)
Compare content of two streams.- Parameters:
input1
- first stream.input2
- another stream.- Returns:
- true if stream provides exactly same content.
-
getSystemDateFormat
public static java.text.DateFormat getSystemDateFormat(int style)
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
public static boolean isFileNameValid(java.lang.String fileName)
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
public static <T> java.util.Set<T> excludeCommonElements(java.util.Collection<T> first, java.util.Collection<T> second)
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
public static boolean isNameValid(@CheckForNull java.lang.String name)
-
getThreadsInfo
public static java.lang.String getThreadsInfo()
-
-