Return String from zibBase64
currently returned object can not be serialized to JSON
also add docstrings to (un)zipBase64 methods
Change-Id: I2dd606e2eae666fc41c0662877fb34d486d4965a
diff --git a/src/com/mirantis/mcp/Common.groovy b/src/com/mirantis/mcp/Common.groovy
index 7a29432..df3ef30 100644
--- a/src/com/mirantis/mcp/Common.groovy
+++ b/src/com/mirantis/mcp/Common.groovy
@@ -204,6 +204,12 @@
}
+/**
+ * Compress a string with Gzip and encode result with Base64 encoding,
+ * useful for wire transfer of large text data over text-based protocols like HTTP
+ * @param s string to encode
+ * @return base64-encoded gzipped string
+*/
def zipBase64(String s){
def targetStream = new ByteArrayOutputStream()
def zipStream = new GZIPOutputStream(targetStream)
@@ -211,9 +217,14 @@
zipStream.close()
def zippedBytes = targetStream.toByteArray()
targetStream.close()
- return zippedBytes.encodeBase64()
+ return zippedBytes.encodeBase64().toString()
}
+/**
+ * De-compress a base64-encoded gzipped string, reverts result of zipBase64
+ * @param compressed base64-endcoded gzipped string
+ * @return decoded decompressed string
+*/
def unzipBase64(String compressed){
def inflaterStream = new GZIPInputStream(new ByteArrayInputStream(compressed.decodeBase64()))
def uncompressedStr = inflaterStream.getText('UTF-8')