Class StaticUtils


  • public final class StaticUtils
    extends java.lang.Object
    Static functions taken from CommandThread to reduce file size.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String TAG_REPLACEMENT  
      static char TAG_REPLACEMENT_CHAR
      Char which should be used instead protected parts.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <T> boolean arraysMatchAt​(T[] needles, T[] haystack, int offset)
      Check to see if an array contains another array.
      static java.lang.String downloadFileToString​(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.String getConfigDir()
      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 int getMB​(long bytes)
      Convert bytes into Megabytes
      static java.lang.String getScriptDir()  
      static java.lang.String getSupportInfo()  
      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.
      static java.lang.String installDir()
      Returns OmegaT installation directory.
      static boolean isKey​(java.awt.event.KeyEvent e, int code, int modifiers)
      Check if specified key pressed.
      static boolean isProjectDir​(java.io.File f)  
      static java.lang.String makeFilenameRelative​(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.String uuencode​(byte[] buf)
      Encodes the array of bytes to store them in a plain text file.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • 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 event
        code - required key code
        modifiers - 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 spaceMatchesNbsp is true, non-breaking spaces (U+00A0) will also be considered whitespace.

        • ? is translated to \S (or [^\s ])
        • * is translated to \S* (or [^\s ]*)
        • If spaceMatchesNbsp is true, then ' ' is translated to ( | )
        • All other special regex characters are escaped as literals
        Parameters:
        text - The text to escape
        spaceMatchesNbsp - 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.IOException
        Deprecated.
        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.IOException
        Extracts files from an InputStream representing a zip archive to the specified destination path.
        Parameters:
        in - InputStream representing a zip archive
        destination - Path where archive entries will be saved
        filenameFilter - 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 array
        haystack - The containing array
        offset - The offset of haystack at which to start checking
        Returns:
        Whether or not haystack contains needles at offset
        Throws:
        java.lang.ArrayIndexOutOfBoundsException - If offset is not a valid index in haystack
      • getSupportInfo

        public static java.lang.String getSupportInfo()
      • getMB

        public static int getMB​(long bytes)
        Convert bytes into Megabytes