Package com.nomagic.rcpf.product.utils
Class Utilities
java.lang.Object
com.nomagic.license.utils.CameoUtilities
com.nomagic.rcpf.product.utils.Utilities
General purpose utilities.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
areChildrenDisabled
(JMenu menu) Are all children disabled?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
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 boolean
containsOnlyFiles
(List list) Indicates if given list contains only file objects.static void
copy
(InputStream input, OutputStream output) Copies all bytes from InputStream into OutputStream.static void
copy
(InputStream input, OutputStream output, long crc) Copies all bytes from InputStream into OutputStream.static boolean
copyDirectory
(File source, File destination) copy all directory recursivellystatic 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 rectengle in such way that it must cover inner one (if outer is smaller than inner resizes outer).static Cursor
createCursor
(Image image, Point pt, String cursorName) Creates the cursor for given image.static Rectangle
Creates rectangle from vector of points.static String
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
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 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
getFileExtension
(File file) Get The given file extension.static String
getFileName
(String text) static String
getFileWitoutExtention
(String filename) Returns file name without extention (removes chars from last "." to end of string)static JMenuItem
getItemWithText
(JPopupMenu menu, String text) Returns inner component (not recursively) with given text.static String
Returns directory can be used for writing temporary files.static boolean
hasExtension
(String name, String extension) Checks if given file name has given file extension.static boolean
hasExtension
(String name, List extensions) Checks if given file name has one of given file extensions.static String
static String
implode
(Collection collection, String delimiter) static String
insertSeparators
(char[] chars, String separator, int groupSize) Constructs string from arrays of chars.static List
internString
(List strings) Replace all strings in given collection with String.intern().static boolean
isAlphaNumeric
(String str) static boolean
isValidKeyCode
(int keyCode) Checks if given code is correct one or not.static boolean
algorithm for searching with wildcards.static boolean
matchEmpty
(String patter, String string) Matches empty string alsostatic <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 mRectToDraw; Calculates rectangle size and location using mFirstCorner and mSecondCorner.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
removeExtension
(String name, Collection<String> extensions) Removes file extension form given file name.static String
removeFromLine
(String line, String trash) Removes from line trash linestatic 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
sortStrings
(Vector elem) Sorts elements in strings' vectorstatic String[]
splitString
(String str, String delim, boolean returnDelims) Splits stringstatic void
swapVector
(List v) Swaps vector ( first element will be last, same with others elements)static byte[]
toByteArray
(InputStream stream) Copies the given file into the array of bytes.static byte[]
toByteArray
(String bytes) Returns byte array from string formated 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
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 recursivelly to the specified stream.Methods inherited from class com.nomagic.license.utils.CameoUtilities
copy, isEqual, isEqual, replaceNewLine, toString
-
Constructor Details
-
Utilities
public Utilities()
-
-
Method Details
-
hasExtension
Checks if given file name has one of given file extensions.- Parameters:
name
-extensions
-- Returns:
-
hasExtension
Checks if given file name has given file extension.- Parameters:
name
-extension
-- Returns:
-
removeExtension
Removes file extension form given file name.- Parameters:
name
-extensions
- extensions- Returns:
-
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
algorithm for searching with wildcards.- Parameters:
pattern
- The given pattern.string
- String.- Returns:
- boolean expression.
-
matchEmpty
Matches empty string also- Parameters:
patter
- The given pattern.string
- The given string.- Returns:
- boolean
-
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.
-
removeFromLine
Removes from line trash line- Parameters:
line
- the given line.trash
- characters as string.- Returns:
- The given string without From Line.
-
countOccurrences
Returns the number of times the character c appears in a string.- Parameters:
string
- The given string.c
- character.- Returns:
- number of time.
-
removeNonUtf8CompliantCharacters
-
fitInRectangle
recalculate bounds to fit in rectangle- Parameters:
small
- Small rectangle.big
- 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.
-
coverRectangle
Moves outer rectengle 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
Swaps vector ( first element will be last, same with others elements)- Parameters:
v
- List that be swaped.
-
getFileWitoutExtention
Returns file name without extention (removes chars from last "." to end of string)- Parameters:
filename
- The given file name.
-
getFileExtension
Get The given file extension.- Parameters:
file
- The given file.- Returns:
- File extension.
-
getFileName
-
removeComments
Removes / * * / comments from body.- Parameters:
body
- String body.- Returns:
- body without comment.
-
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
Copies all bytes from InputStream into OutputStream. Closes the streams.- Parameters:
input
- the inputstream.output
- the output stream.crc
- crc to check. -1 if do not check crc.- Throws:
IOException
-
copy
Copies all bytes from InputStream into OutputStream. Closes the streams.- Parameters:
input
- the inputstream.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.dst
- destination file.- Returns:
- True if work successful.
-
copyDirectory
copy all directory recursivelly- Parameters:
source
-destination
-
-
extractZip
Extracts files from Zip archive- Parameters:
zipFile
- Zip archive filedstDir
- name of the destination directory- 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:
- Curser.
-
getAsStringKeyStrokes
public static String getAsStringKeyStrokes(List 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.
-
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 formated 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 mRectToDraw; Calculates rectangle size and location using mFirstCorner and mSecondCorner. This method is useful when resizing a shape and only opposite corners are known.- Parameters:
mRectToDraw
- rectangle to normalizemFirstCorner
- first cornermSecondCorner
- second corner
-
normalize
normalizes rectangle mRectToDraw;- Parameters:
rect
- rectangle to normalize
-
getTempDir
Returns directory can be used for writing temporary files.- Returns:
- string.
-
toString
Get String representation of inputStream- Parameters:
inputStream
- The given inputStream- Returns:
- String representation.
- Throws:
IOException
-
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.- Parameters:
str
-
-
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
-
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
-
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.
-
splitString
Splits string- Parameters:
str
- string to splitdelim
- delimiterreturnDelims
- flag indicating whether to return the delimiters with string- Returns:
- array of strings
-
implode
-
implode
-
parseExceptQuotes
parses string by standard tokens, except parts wrapped in quotes- Parameters:
cmd
-- Returns:
-
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 recursivelly 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
- Parameters:
rule
-- Returns:
- rule
-
internString
Replace all strings in given collection with String.intern().- Parameters:
strings
- collection of object. Strings among these objects will be interned, other objects will remain.- Returns:
- the same collection as given
-
dumpThreads
public static void dumpThreads()Dumps all threads to system out. -
reverseString
Given a string, returns a string with reversed characters.- Parameters:
source
- string which has to be reversed.- Returns:
- a string with reversed characters.
-