Created
June 13, 2019 16:24
-
-
Save cnmoro/f4c6459f0a82101be9284fb1431b0f27 to your computer and use it in GitHub Desktop.
Java GZip String Compression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author https://stackoverflow.com/users/1964272/dropout | |
*/ | |
public static String compress(String str) throws IOException { | |
if (str == null || str.length() == 0) { | |
return str; | |
} | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
GZIPOutputStream gzip = new GZIPOutputStream(out); | |
gzip.write(str.getBytes()); | |
gzip.close(); | |
String outStr = out.toString("UTF-8"); | |
return outStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment