GZIPHelper.javaCompresses and decompresses strings using GZIP + Base64 encoding. Solves two problems: (1) some database fields have limited character length (e.g. VARCHAR(4000)), and (2) storing large JSON blobs in database columns wastes space. This utility compresses the string with GZIP, then Base64-encodes the binary result so it can be stored as a plain string in a database VARCHAR or TEXT column. The decompression reverses the process: Base64 decode → GZIP decompress → original string.
Why Base64 after GZIP? GZIP produces binary bytes — not safe for storage in text-based database columns (which use character encodings like UTF-8 that may interpret certain byte values as control characters). Base64 converts binary data into a pure ASCII string (using 64 safe characters: A-Z, a-z, 0-9, +, /) — guaranteed safe for any text storage.
compress(String str) → StringTakes any string (null-safe — returns null for null/empty input). Wraps user preference XML, JSON configuration blobs, and large text fields for database storage. Algorithm:
str.getBytes() — converts to platform-default charset bytes. Warning: uses the JVM's default charset (typically UTF-8 on modern systems but could be different on legacy setups). If the original string contains non-ASCII characters, different JVMs could produce different compressed resultsGZIPOutputStream — the Java standard library GZIP implementation (RFC 1952)ByteArrayOutputStreamnull. The caller must handle null — most callers treat null the same as empty string.
uncompress(String base64ByteArray) → StringReverses compress(). Takes a Base64-encoded compressed string, returns the original. Algorithm:
Base64Helper.decodeObject(base64ByteArray) — decodes Base64 to raw bytes (cast from Object to byte[] — note the unchecked cast. The decodeObject method returns Object for historical XStream compatibility)GZIPInputStream — decompresses the GZIP dataIOUtils.copy(gzip, out) (Apache Commons IO) to stream decompressed data into a ByteArrayOutputStreamout.toString() — converts bytes back to string using the platform default charset (same charset assumption as compress)IOException and ClassNotFoundException (the latter from Base64Helper.decodeObject() which uses Java object deserialization under the hood — a potential security issue if malicious Base64 data is passed). Returns null on any error.Used by two key components:
GZIPHelper.compress() and stored as a Base64 string in the UserPrefDO entity. On load, uncompress() restores the original XMLexternal_access_logs column on t_plugin_datatransfer_area (see #105) stores a JSON-serialized list of access events. With frequent external access, this string could exceed the VARCHAR(10000) limit — GZIP compression reduces its size significantlyNotably, this is not used for the license key BLOB storage (LicenseDO) — binary files use direct JDBC BLOB columns, not text compression.
str.getBytes() and out.toString() without specifying a charset. This means the compression round-trip is only guaranteed if compress and uncompress run on the same JVM. If compressed data is moved to a different server with a different default charset, the decompressed string could be corrupted. In practice, all modern JVMs default to UTF-8 (since Java 18), so this is rarely an issue in productionnull for null input — callers don't need to pre-check. But callers do need to handle null returns (when compression/decompression fails) — treating null as empty string is typicalByteArrayInputStream/OutputStream objects — no shared state, fully thread-safeBase64Helper.decodeObject() uses Java's ObjectInputStream, which can deserialize arbitrary Java objects (a known security vulnerability). If an attacker can inject Base64 data that gets passed to uncompress(), they could potentially execute arbitrary code. In practice, the data only comes from the database and is generated by compress(), so the attack surface is limited to database compromise scenarios