Package org.omegat.util
Class StaticUtils
- java.lang.Object
-
- org.omegat.util.StaticUtils
-
public final class StaticUtils extends java.lang.ObjectStatic functions taken from CommandThread to reduce file size.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringTAG_REPLACEMENTstatic charTAG_REPLACEMENT_CHARChar which should be used instead protected parts.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> booleanarraysMatchAt(T[] needles, T[] haystack, int offset)Check to see if an array contains another array.static java.lang.StringdownloadFileToString(java.net.URL url, int timeout)Deprecated.static java.util.List<java.lang.String>extractFromZip(java.io.InputStream in, java.io.File destination, java.util.function.Predicate<java.lang.String> filenameFilter)Extracts files from an InputStream representing a zip archive to the specified destination path.static java.lang.StringgetConfigDir()Returns the location of the configuration directory, depending on the user's platform.static java.lang.String[]getFontNames()Returns the names of all font families available.static intgetMB(long bytes)Convert bytes into Megabytesstatic java.lang.StringgetScriptDir()static java.lang.StringgetSupportInfo()static java.lang.StringglobToRegex(java.lang.String text, boolean spaceMatchesNbsp)Translates a string containing word-processing "glob"-style wildcards (?matches a single non-whitespace character,*matches zero or more non-whitespace characters) to standard regex.static java.lang.StringinstallDir()Returns OmegaT installation directory.static booleanisKey(java.awt.event.KeyEvent e, int code, int modifiers)Check if specified key pressed.static booleanisProjectDir(java.io.File f)static java.lang.StringmakeFilenameRelative(java.lang.String filename, java.lang.String path)Makes the file name relative to the given path.static java.lang.String[]parseCLICommand(java.lang.String cmd)Parse a command line string into arguments, interpreting double and single quotes as Bash does.static byte[]uudecode(java.lang.String buf)Decodes the array of bytes that was stored in a plain text file as a string, back to array of bytes.static java.lang.Stringuuencode(byte[] buf)Encodes the array of bytes to store them in a plain text file.
-
-
-
Field Detail
-
TAG_REPLACEMENT_CHAR
public static final char TAG_REPLACEMENT_CHAR
Char which should be used instead protected parts. It should be non-letter char, to be able to have correct words counter. This char can be placed around protected text for separate words inside protected text and words outside if there are no spaces between they.- See Also:
- Constant Field Values
-
TAG_REPLACEMENT
public static final java.lang.String TAG_REPLACEMENT
- See Also:
- Constant Field Values
-
-
Method Detail
-
isKey
public static boolean isKey(java.awt.event.KeyEvent e, int code, int modifiers)Check if specified key pressed.- Parameters:
e- pressed key eventcode- required key codemodifiers- required modifiers- Returns:
- true if checked key pressed
-
getFontNames
public static java.lang.String[] getFontNames()
Returns the names of all font families available.
-
installDir
public static java.lang.String installDir()
Returns OmegaT installation directory.
-
getConfigDir
public static java.lang.String getConfigDir()
Returns the location of the configuration directory, depending on the user's platform. Also creates the configuration directory, if necessary. If any problems occur while the location of the configuration directory is being determined, an empty string will be returned, resulting in the current working directory being used.- Windows XP: <Documents and Settings>\<User name>\Application Data\OmegaT
- Windows Vista: User\<User name>\AppData\Roaming
- Linux: ~/.omegat
- Solaris/SunOS: ~/.omegat
- FreeBSD: ~/.omegat
- Mac OS X: ~/Library/Preferences/OmegaT
- Other: User home directory
- Returns:
- The full path of the directory containing the OmegaT configuration files, including trailing path separator.
-
getScriptDir
public static java.lang.String getScriptDir()
-
uuencode
public static java.lang.String uuencode(byte[] buf)
Encodes the array of bytes to store them in a plain text file.
-
uudecode
public static byte[] uudecode(java.lang.String buf)
Decodes the array of bytes that was stored in a plain text file as a string, back to array of bytes.
-
makeFilenameRelative
public static java.lang.String makeFilenameRelative(java.lang.String filename, java.lang.String path)Makes the file name relative to the given path.
-
globToRegex
public static java.lang.String globToRegex(java.lang.String text, boolean spaceMatchesNbsp)Translates a string containing word-processing "glob"-style wildcards (?matches a single non-whitespace character,*matches zero or more non-whitespace characters) to standard regex.If
spaceMatchesNbspistrue, non-breaking spaces (U+00A0) will also be considered whitespace.?is translated to\S(or[^\s ])*is translated to\S*(or[^\s ]*)- If
spaceMatchesNbspistrue, then '' is translated to( | ) - All other special regex characters are escaped as literals
- Parameters:
text- The text to escapespaceMatchesNbsp- Whether to consider regular spaces to also match non-breaking spaces- Returns:
- The escaped text
-
downloadFileToString
@Deprecated public static java.lang.String downloadFileToString(java.net.URL url, int timeout) throws java.io.IOExceptionDeprecated.Download a file to memory.- Throws:
java.io.IOException
-
extractFromZip
public static java.util.List<java.lang.String> extractFromZip(java.io.InputStream in, java.io.File destination, java.util.function.Predicate<java.lang.String> filenameFilter) throws java.io.IOExceptionExtracts files from an InputStream representing a zip archive to the specified destination path.- Parameters:
in- InputStream representing a zip archivedestination- Path where archive entries will be savedfilenameFilter- Filter for entry names. Return false to skip extracting an entry- Returns:
- List of extracted entry names
- Throws:
java.io.IOException
-
parseCLICommand
public static java.lang.String[] parseCLICommand(java.lang.String cmd)
Parse a command line string into arguments, interpreting double and single quotes as Bash does.- Parameters:
cmd- Command string- Returns:
- Array of arguments
-
isProjectDir
public static boolean isProjectDir(java.io.File f)
-
arraysMatchAt
public static <T> boolean arraysMatchAt(T[] needles, T[] haystack, int offset)Check to see if an array contains another array.- Parameters:
needles- The contained arrayhaystack- The containing arrayoffset- The offset ofhaystackat which to start checking- Returns:
- Whether or not
haystackcontainsneedlesatoffset - Throws:
java.lang.ArrayIndexOutOfBoundsException- Ifoffsetis not a valid index inhaystack
-
getSupportInfo
public static java.lang.String getSupportInfo()
-
getMB
public static int getMB(long bytes)
Convert bytes into Megabytes
-
-