@Override public byte[] fromString(final String str) { if (StringUtils.isEmpty(str) == true || XmlConstants.NULL_IDENTIFIER.equals(str) == true) { return null; } try { final byte[] bytes = (byte[]) Base64Helper.decodeObject(str); return bytes; } catch (final IOException ex) { log.error("Error while uncompressing string: " + ex.getMessage(), ex); return null; } catch (final ClassNotFoundException ex) { log.error("Error while uncompressing string: " + ex.getMessage(), ex); return null; } }
/** * @param base64ByteArray * @return */ public static String uncompress(final String base64ByteArray) { if (base64ByteArray == null || base64ByteArray.length() == 0) { return base64ByteArray; } try { final byte[] byteArray = (byte[]) Base64Helper.decodeObject(base64ByteArray); final ByteArrayInputStream in = new ByteArrayInputStream(byteArray); final GZIPInputStream gzip = new GZIPInputStream(in); final ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtils.copy(gzip, out); gzip.close(); return out.toString(); } catch (final IOException ex) { log.error("Error while uncompressing string: " + ex.getMessage(), ex); return null; } catch (final ClassNotFoundException ex) { log.error("Error while uncompressing string: " + ex.getMessage(), ex); return null; } } }