-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: SKFP-1025 add compression of token before encrypt it (#298)
- Loading branch information
1 parent
470111e
commit a302074
Showing
9 changed files
with
162 additions
and
21 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
48 changes: 48 additions & 0 deletions
48
src/main/java/io/kidsfirst/core/service/StringCompressService.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,48 @@ | ||
package io.kidsfirst.core.service; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.*; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.zip.GZIPInputStream; | ||
import java.util.zip.GZIPOutputStream; | ||
|
||
@Slf4j | ||
public class StringCompressService { | ||
|
||
public static String compress(String str) { | ||
if (str == null || str.isEmpty()) { | ||
return str; | ||
} | ||
|
||
ByteArrayOutputStream out = new ByteArrayOutputStream(); | ||
|
||
try (GZIPOutputStream gzip = new GZIPOutputStream(out)) { | ||
gzip.write(str.getBytes()); | ||
gzip.close(); | ||
return out.toString(StandardCharsets.ISO_8859_1); | ||
} catch (IOException e) { | ||
log.error("Error during string compress", e); | ||
return str; | ||
} | ||
} | ||
|
||
public static String decompress(String str) { | ||
if (str == null || str.isEmpty()) { | ||
return str; | ||
} | ||
|
||
try(GZIPInputStream gis = new GZIPInputStream(new ByteArrayInputStream(str.getBytes(StandardCharsets.ISO_8859_1))); | ||
BufferedReader bf = new BufferedReader(new InputStreamReader(gis, "ISO_8859_1"))) { | ||
StringBuilder outStr = new StringBuilder(); | ||
String line; | ||
while ((line = bf.readLine()) != null) { | ||
outStr.append(line); | ||
} | ||
return outStr.toString(); | ||
} catch (IOException e) { | ||
log.error("Error during string decompress", e); | ||
return str; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.