Skip to content

Utility classes

There are several utilitity classes which you can use at anywhere you want.

HTTP connection utility

When you need to interact with web servers, you can use HTTP connection utility. If you want remote resource as String, HttpConnectionUtils#getURL is what you need. There are two variants;

getURL(URL url)

and

getURL(URL url, int timeout)

A default timeout is 10 seconds.

When you need to download binary file from remote, you can use downloadBinary utility method.

downloadBinaryFile(URL fileURL, Map<String, String> headers,
    Set<String> expectedMime, File saveFilePath)

It will return true when successfully download the file. You should provide headers, and expected MIME types.

When you need to download zip file from remote and extract its contents, use can use downloadZipAndExtract

downloadZipFileAndExtract(URL url, File dir, List<String> expectedFiles)

It takes target directory and expected filename list.

These utilities use URL#openConnection method. It looks system property for proxy connections.

There are also some primitive connection utilities. There are get, post, and postJson.

HTML Utilities

When you handle HTML text, you will need to convert HTML excape characters into UTF-8. HTMLUtils#entitiesToChars is what you want.

There is also a HTMLUtils#charsToEntities which does reverse things.

Encoding Detector

When we read arbitrary text files from disk, we sometimes need to detect character encodings. EncodingDetector#detectEncoding is one we used in glossary reader. When there are enough characters, it detects an encoding correctly. There are also a variant detectEndocingDefault that accept default encoding.

Json Parser

There is a json parser based on Java internal Nashorn javascript scripting engine. Because Java 17 removes javascript engine from JVM, the parser is deprecated. You are recommended to use Jackson JSON parser instead.

StaticUtils

There are some small utilities in StaticUtils class.

  • getConfigDir: get omegat configuration directory such as $HOME/.omegat/
  • installDir: get omegat installation directory where OmegaT.jar exists.
  • getScriptDir: get directory where scripts are installed.

StringUtil

There are several must use utility methods in StringUtil class.

  • isEmpty(@Nullable String str): check string is null or empty string("")
  • isLowerCase
  • isUpperCase
  • isMixedCase
  • isTitleCase
  • isWhiteSpace
  • isCJK: return true when string has characters in Chinese, Japanese, or Korean.
  • capitalizeFirst: convert string with First character as upper case.
  • toTitleCase: convert string as title case.

Platform

When you need to detect a platform where OmegaT running on, such as Windows, macOS or Linux. There is a utility class Platform for the purpose. There are boolean constants to indicate the platform type.

  • Platform.isMacOS
  • Platform.isWindows
  • Platform.isLinux

There are also some informational constants.

  • Platform.osVersion
  • Platform.isWindows_10_orLater
  • Platform.isWindows_11_orLater
  • Platform.isMacOS_10_14_Mojave_orLater
  • Platform.isMacOS_10_15_Catalina_orLater

It also provides hints about an architecture.

  • Platform.isX86
  • Platform.isX86_64
  • Platform.isAARCH64

It must be useful.

  • Platform.javaVersion
  • Platform.isJava11_or_later
  • Platform.isJava17_or_later

Also provide some functions.

Platform.is64Bit(): true when OemgaT run on 64bit OS platform.