-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from linkedin/master
pull newest
- Loading branch information
Showing
26 changed files
with
1,138 additions
and
246 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
...bus-core/databus-core-impl/src/main/java/com/linkedin/databus/core/util/CompressUtil.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.linkedin.databus.core.util; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.zip.GZIPInputStream; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
public class CompressUtil | ||
{ | ||
public static String compress(String str) throws IOException | ||
{ | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
GZIPOutputStream gzip = new GZIPOutputStream(out); | ||
gzip.write(str.getBytes(Charset.defaultCharset())); | ||
gzip.close(); | ||
return BaseEncoding.base64().encode(out.toByteArray()); | ||
} | ||
|
||
public static String uncompress(String str) throws IOException | ||
{ | ||
byte[] encodeByteArr = BaseEncoding.base64().decode(str); | ||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
ByteArrayInputStream in = new ByteArrayInputStream(encodeByteArr); | ||
GZIPInputStream gunzip = new GZIPInputStream(in); | ||
byte[] buffer = new byte[256]; | ||
int n; | ||
while ((n = gunzip.read(buffer)) >= 0) | ||
{ | ||
out.write(buffer, 0, n); | ||
} | ||
return out.toString(Charset.defaultCharset().name()); | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.