1
- package com .optimizely .ab .android .event_handler ;
2
-
3
- import static java .util .zip .Deflater .BEST_COMPRESSION ;
1
+ /****************************************************************************
2
+ * Copyright 2022, Optimizely, Inc. and contributors *
3
+ * *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); *
5
+ * you may not use this file except in compliance with the License. *
6
+ * You may obtain a copy of the License at *
7
+ * *
8
+ * http://www.apache.org/licenses/LICENSE-2.0 *
9
+ * *
10
+ * Unless required by applicable law or agreed to in writing, software *
11
+ * distributed under the License is distributed on an "AS IS" BASIS, *
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13
+ * See the License for the specific language governing permissions and *
14
+ * limitations under the License. *
15
+ ***************************************************************************/
4
16
5
- import android . os . Build ;
17
+ package com . optimizely . ab . android . event_handler ;
6
18
7
19
import androidx .annotation .NonNull ;
8
- import androidx .annotation .RequiresApi ;
9
- import androidx .annotation .VisibleForTesting ;
10
20
11
21
import org .apache .commons .codec .binary .Base64 ;
12
22
13
- import java .io .ByteArrayInputStream ;
14
23
import java .io .ByteArrayOutputStream ;
15
24
import java .io .IOException ;
16
- import java .nio .charset .Charset ;
17
- import java .nio .charset .StandardCharsets ;
18
25
import java .util .zip .Deflater ;
19
- import java .util .zip .GZIPInputStream ;
20
- import java .util .zip .GZIPOutputStream ;
21
26
import java .util .zip .Inflater ;
22
27
23
28
public class EventHandlerUtils {
@@ -42,6 +47,9 @@ public static String compress(@NonNull String decompressed) throws IOException {
42
47
// encoded to Base64 (instead of byte[] since WorkManager.Data size is unexpectedly expanded with byte[]).
43
48
return encodeToBase64 (bytes );
44
49
}
50
+ finally {
51
+ deflater .end ();
52
+ }
45
53
}
46
54
47
55
public static String decompress (@ NonNull String base64 ) throws Exception {
@@ -59,6 +67,9 @@ public static String decompress(@NonNull String base64) throws Exception {
59
67
60
68
return outputStream .toString ();
61
69
}
70
+ finally {
71
+ inflater .end ();
72
+ }
62
73
}
63
74
64
75
static String encodeToBase64 (byte [] bytes ) {
0 commit comments