public static String encodeCompressBinary(@Nonnull final byte[] bytes) { try { final ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length); final GZIPOutputStream gos = new GZIPOutputStream(bos); gos.write(bytes); gos.close(); final byte[] gzippedBytes = bos.toByteArray(); final boolean useCompressioon = gzippedBytes.length < bytes.length; final StringBuilder str = new StringBuilder(); str.append(useCompressioon ? 'Z' : '-'); str.append(Base43.encode(useCompressioon ? gzippedBytes : bytes)); return str.toString(); } catch (final IOException x) { throw new RuntimeException(x); } }
public static String encodeBinary(@Nonnull final byte[] bytes) { return Base43.encode(bytes); }