@OpenApiAll public class Utilities extends CameoUtilities
Constructor and Description |
---|
Utilities() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
addHttpParameter(java.lang.String parameters,
java.lang.String parameter,
java.lang.String value)
Adds http parameter to given parameters string
|
static boolean |
areChildrenDisabled(javax.swing.JMenu menu)
Are all children disabled?
|
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 throws
IllegalStateException |
static boolean |
checkSystemProperty(java.lang.String property,
boolean defaultValue)
Checks given system (boolean) property value
|
static java.lang.String |
clearAllLine(java.lang.String src,
java.lang.String trash)
Removes all trash from string
|
static java.lang.String |
clearLine(java.lang.String line,
java.lang.String trash)
removes from line ends wanted characters
|
static int |
collectInteger(byte[] bytes)
Makes int value from array of bytes
|
static boolean |
compareFiles(java.io.File f1,
java.io.File f2)
Compares two files
|
static 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)
Concant given http parameters
|
static java.lang.String |
constructHttpParameter(java.lang.String parameter,
java.lang.String value)
Constructs http parameter
|
static boolean |
containsOnlyFiles(java.util.List list)
Indicates if given list contains only file objects.
|
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)
Copies all bytes from InputStream into OutputStream.
|
static boolean |
copyDirectory(java.io.File source,
java.io.File destination)
copy all directory recursivelly
|
static boolean |
copyFile(java.io.File source,
java.io.File dst)
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 rectengle in such way that it must cover inner one (if outer is smaller than inner resizes outer).
|
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.Rectangle |
createRectFromList(java.util.List v)
Creates rectangle from vector of points.
|
static java.lang.String |
createStringRepresentation(java.util.Collection value) |
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 |
extractZip(java.util.zip.ZipFile zipFile,
java.lang.String dstDir)
Extracts files from Zip archive
|
static java.awt.Rectangle |
fitInRectangle(java.awt.Rectangle small,
java.awt.Rectangle big)
recalculate bounds to fit in rectangle
|
static 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.
|
static java.lang.String |
getClassName(java.lang.Class clazz)
Get class name.
|
static java.lang.String |
getFileExtension(java.io.File file)
Get The given file extension.
|
static java.lang.String |
getFileName(java.lang.String text) |
static java.lang.String |
getFileWitoutExtention(java.lang.String filename)
Returns file name without extention (removes chars from last "." to end of string)
|
static java.lang.String |
getHtmlPage(java.lang.String pageHttpAddress,
java.lang.String parameters,
ProxyServerData proxy)
Deprecated.
use
HttpUtilities.getHtmlPage(String, String, com.nomagic.utils.http.HttpProxyServerData, int) |
static javax.swing.JMenuItem |
getItemWithText(javax.swing.JPopupMenu menu,
java.lang.String text)
Returns inner component (not recursively) with given text.
|
static java.lang.String |
getTempDir()
Returns directory can be used for writing temporary files.
|
static boolean |
hasExtension(java.lang.String name,
java.util.List extensions)
Checks if given file name has one of given file extensions.
|
static boolean |
hasExtension(java.lang.String name,
java.lang.String extension)
Checks if given file name has given file extension.
|
static java.lang.String |
implode(java.util.Collection collection,
java.lang.String delimiter) |
static java.lang.String |
implode(java.lang.String[] values,
java.lang.String delimiter) |
static java.lang.String |
insertSeparators(char[] chars,
java.lang.String separator,
int groupSize)
Constructs string from arrays of chars.
|
static java.util.List |
internString(java.util.List strings)
Replace all strings in given collection with String.intern().
|
static boolean |
isAlphaNumeric(java.lang.String str) |
static boolean |
isUseProxy(ProxyServerData proxy)
Checks if use proxy server according given proxy server data
|
static boolean |
isValidKeyCode(int keyCode)
Checks if given code is correct one or not.
|
static boolean |
match(java.lang.String pattern,
java.lang.String string)
algorithm for searching with wildcards.
|
static boolean |
matchEmpty(java.lang.String patter,
java.lang.String string)
Matches empty string also
|
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 mRectToDraw,
java.awt.Point mFirstCorner,
java.awt.Point mSecondCorner)
normalizes rectangle mRectToDraw; Calculates rectangle size and
location using mFirstCorner and mSecondCorner.
|
static java.net.HttpURLConnection |
openHttpURLConnection(java.lang.String pageHttpAddress,
ProxyServerData proxyServerData)
Deprecated.
use
HttpJavaUtilities.openHttpURLConnection(String, String, com.nomagic.utils.http.HttpProxyServerData, int, long) |
static java.lang.String[] |
parseExceptQuotes(java.lang.String cmd)
parses string by standard tokens, except parts wrapped in quotes
|
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.
|
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 |
removeFromLine(java.lang.String line,
java.lang.String trash)
Removes from line trash line
|
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 str
|
static java.lang.String |
replace(java.lang.String src,
java.lang.String pattern,
java.lang.String replaceWith)
Replaces string fragment with another string
|
static java.lang.String |
replaceEpsString(java.lang.String aStr)
Replace special char for Eps format string
|
static 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.
use
HttpJavaUtilities.sendHttpParameters(java.net.HttpURLConnection, String) |
static void |
sortStrings(java.util.Vector elem)
Sorts elements in strings' vector
|
static java.lang.String[] |
splitString(java.lang.String str,
java.lang.String delim,
boolean returnDelims)
Splits string
|
static void |
swapVector(java.util.List v)
Swaps vector ( first element will be last, same with others elements)
|
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 formated 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 inputStream
|
static 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.
|
static void |
zipDir(java.lang.String dir2zip,
java.util.zip.ZipOutputStream zos)
Compress specified directory recursivelly to the specified stream.
|
copy, isEqual, isEqual, replaceNewLine, toString
public static boolean hasExtension(java.lang.String name, java.util.List extensions)
name
- extensions
- public static boolean hasExtension(java.lang.String name, java.lang.String extension)
name
- extension
- public static java.lang.String removeExtension(java.lang.String name, java.util.Collection<java.lang.String> extensions)
name
- extensions
- extensionspublic static java.lang.String createStringRepresentation(java.util.Collection value)
public static java.util.List<java.awt.Point> deepPointsClone(java.util.List<java.awt.Point> v)
v
- List of point.public static java.util.List<java.awt.Point> deepPointsClone(java.util.List<java.awt.Point> v, boolean cloneList)
v
- List of point.cloneList
- True if clone to new list.public static java.lang.String replace(java.lang.String src, java.lang.String pattern, java.lang.String replaceWith)
src
- Source string.pattern
- String pattern.replaceWith
- The another string.public static boolean match(java.lang.String pattern, java.lang.String string)
pattern
- The given pattern.string
- String.public static boolean matchEmpty(java.lang.String patter, java.lang.String string)
patter
- The given pattern.string
- The given string.public static void sortStrings(java.util.Vector elem)
elem
- The given vector.public static java.lang.String clearLine(java.lang.String line, java.lang.String trash)
line
- The given line.trash
- characters as string.public static java.lang.String clearAllLine(java.lang.String src, java.lang.String trash)
src
- String that be removed trashtrash
- Trash string.public static java.lang.String removeFromLine(java.lang.String line, java.lang.String trash)
line
- the given line.trash
- characters as string.public static int countOccurrences(java.lang.String string, char c)
string
- The given string.c
- character.public static java.lang.String removeNonUtf8CompliantCharacters(java.lang.String inString)
public static java.awt.Rectangle fitInRectangle(java.awt.Rectangle small, java.awt.Rectangle big)
small
- Small rectangle.big
- Big rectangle.public static boolean containsOnlyFiles(java.util.List list)
list
- list to check.public static java.awt.Rectangle coverRectangle(java.awt.Rectangle inner, java.awt.Rectangle outer)
inner
- Inner rectangle.outer
- Outer rectangle.public static java.awt.Rectangle createRectFromList(java.util.List v)
v
- List of point.public static void swapVector(java.util.List v)
v
- List that be swaped.public static java.lang.String getFileWitoutExtention(java.lang.String filename)
filename
- The given file name.public static java.lang.String getFileExtension(java.io.File file)
file
- The given file.public static java.lang.String getFileName(java.lang.String text)
public static java.lang.String removeComments(java.lang.String body)
body
- String body.public static java.lang.String trim(java.lang.String src, java.lang.String trashBegin, java.lang.String trashEnd)
src
- The given string.trashBegin
- Trash string that is a beginning.trashEnd
- Trash string that is a ending.public static java.lang.String replaceEpsString(java.lang.String aStr)
aStr
- The given string.public static void copy(java.io.InputStream input, java.io.OutputStream output, long crc) throws java.io.IOException
input
- the inputstream.output
- the output stream.crc
- crc to check. -1 if do not check crc.java.io.IOException
public static void copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOException
input
- the inputstream.output
- the output stream.java.io.IOException
public static boolean copyFile(java.lang.String sourceName, java.lang.String dstName)
sourceName
- Source file name.dstName
- destination file name.public static boolean copyFile(java.io.File source, java.io.File dst)
source
- Source file.dst
- destination file.public static boolean copyDirectory(java.io.File source, java.io.File destination)
source
- destination
- public static void extractZip(java.util.zip.ZipFile zipFile, java.lang.String dstDir) throws java.io.IOException
zipFile
- Zip archive filedstDir
- name of the destination directoryjava.io.IOException
public static byte[] toByteArray(java.io.InputStream stream)
stream
- the given file.public static javax.swing.JMenuItem getItemWithText(javax.swing.JPopupMenu menu, java.lang.String text)
menu
- The given JPopupMenu.text
- The given text.public static java.awt.Cursor createCursor(java.awt.Image image, java.awt.Point pt, java.lang.String cursorName)
image
- the given image.pt
- the hot point.cursorName
- the cursor name.public static java.lang.String getAsStringKeyStrokes(java.util.List shortcuts, java.lang.String bracketFirst, java.lang.String bracketSecond)
shortcuts
- The given key strokes.bracketFirst
- Open bracket.bracketSecond
- Close bracket.public static java.lang.String getAsString(javax.swing.KeyStroke e)
e
- the given key stroke.public static boolean isValidKeyCode(int keyCode)
keyCode
- The given key code.public static java.lang.String toString(byte[] data)
data
- the given bytes array.public static byte[] toByteArray(java.lang.String bytes)
bytes
- the given string.public static boolean areChildrenDisabled(javax.swing.JMenu menu)
menu
- the menupublic static void normalize(java.awt.Rectangle mRectToDraw, java.awt.Point mFirstCorner, java.awt.Point mSecondCorner)
mRectToDraw
- rectangle to normalizemFirstCorner
- first cornermSecondCorner
- second cornerpublic static void normalize(java.awt.Rectangle rect)
rect
- rectangle to normalizepublic static java.lang.String getTempDir()
@Deprecated public static java.net.HttpURLConnection openHttpURLConnection(java.lang.String pageHttpAddress, ProxyServerData proxyServerData) throws java.io.IOException
HttpJavaUtilities.openHttpURLConnection(String, String, com.nomagic.utils.http.HttpProxyServerData, int, long)
pageHttpAddress
- page address with protocol e.g "http://www.magicdraw.com"
proxyServerData
- proxy server datajava.io.IOException
public static boolean isUseProxy(ProxyServerData proxy)
proxy
- proxy data.@Deprecated public static java.lang.String getHtmlPage(java.lang.String pageHttpAddress, java.lang.String parameters, ProxyServerData proxy) throws java.io.IOException
HttpUtilities.getHtmlPage(String, String, com.nomagic.utils.http.HttpProxyServerData, int)
pageHttpAddress
- page address with protocol e.g "http://www.magicdraw.com"
parameters
- parameters for POST method (null if no data to POST)proxy
- proxy server datajava.io.IOException
public static java.lang.String toString(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- The given inputStreamjava.io.IOException
@Deprecated public static void sendHttpParameters(java.net.HttpURLConnection connection, java.lang.String parameters) throws java.io.IOException
HttpJavaUtilities.sendHttpParameters(java.net.HttpURLConnection, String)
connection
- HttpURLConnectionparameters
- Http Parameters.java.io.IOException
public static java.lang.String constructHttpParameter(java.lang.String parameter, java.lang.String value)
parameter
- parameter namevalue
- parameter valuepublic static java.lang.String addHttpParameter(java.lang.String parameters, java.lang.String parameter, java.lang.String value)
parameters
- parametersparameter
- parameter name to addvalue
- parameter value to addpublic static java.lang.String concatHttpParameter(java.lang.String parameters1, java.lang.String parameters2)
parameters1
- parameters2
- public static java.lang.String insertSeparators(char[] chars, java.lang.String separator, int groupSize)
chars
- array of characters to divideseparator
- group separatorgroupSize
- size if the grouppublic static java.lang.String removeSeparators(java.lang.String str, java.lang.String separator)
str
- string to uniteseparator
- public static byte[] getBytes(java.lang.String str)
str
- public static byte[] distributeInteger(int intValue, int size)
intValue
- int intValue to distributesize
- size of result arraypublic static int collectInteger(byte[] bytes)
bytes
- array of bytespublic static boolean compareStreams(java.io.InputStream oldStr, java.io.InputStream newStr) throws java.io.IOException
oldStr
- First input stream.newStr
- Second input stream.java.io.IOException
public static boolean compareFiles(java.io.File f1, java.io.File f2) throws java.io.IOException
f1
- First file.f2
- Second file.java.io.IOException
public static void deleteTree(java.io.File f)
f
- file to deletepublic static void deleteTreeOnExit(java.io.File f)
f
- file to deletepublic static void deleteDirContent(java.io.File f)
f
- file to deletepublic static java.lang.String getClassName(java.lang.Class clazz)
clazz
- The given class.public static boolean isAlphaNumeric(java.lang.String str)
public static <T> java.util.List<T> mergeLists(java.util.List<T> l1, java.util.List<T> l2)
l1
- first list.l2
- second list.public static java.lang.String[] splitString(java.lang.String str, java.lang.String delim, boolean returnDelims)
str
- string to splitdelim
- delimiterreturnDelims
- flag indicating whether to return the delimiters with stringpublic static java.lang.String implode(java.util.Collection collection, java.lang.String delimiter)
public static java.lang.String implode(java.lang.String[] values, java.lang.String delimiter)
public static java.lang.String[] parseExceptQuotes(java.lang.String cmd)
cmd
- public static java.lang.String readFileSkipFirstLines(java.io.File file, int n)
file
- - file to read.n
- - number of lines to skip from the beginning.public static void zipDir(java.lang.String dir2zip, java.util.zip.ZipOutputStream zos) throws java.io.IOException
dir2zip
- directory to zip.zos
- ZipOutputStream
object.java.io.IOException
- if any occurs duringpublic static byte[] compressData(byte[] data, java.lang.String zipEntryName) throws java.io.IOException
data
- a data.zipEntryName
- name of how the data will be named in the archive.java.io.IOException
- if any occurs during compressing the data.public static byte[] compressData(byte[] data) throws java.io.IOException
data
- a data.java.io.IOException
- if any occurs during compressing the data.public static byte[] uncompressData(byte[] data) throws java.io.IOException
data
- a data.java.io.IOException
- if any occurs during compressing the data.public static boolean checkSystemProperty(java.lang.String property, boolean defaultValue)
property
- defaultValue
- public static boolean checkProperty(java.util.Properties properties, java.lang.String property, boolean defaultValue)
public static boolean checkResolvableException(boolean rule)
IllegalStateException
rule
- public static java.util.List internString(java.util.List strings)
strings
- collection of object. Strings among these objects will be interned, other objects will remain.public static void dumpThreads()
public static java.lang.String reverseString(java.lang.String source)
source
- string which has to be reversed.