Skip to content

Commit 8e5e7f5

Browse files
authored
decompress log response (#79)
1 parent 894602f commit 8e5e7f5

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

client/src/main/java/com/regula/documentreader/webclient/model/ext/RecognitionResponse.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import com.google.gson.Gson;
44
import com.regula.documentreader.webclient.model.*;
55
import com.regula.documentreader.webclient.model.ext.authenticity.Authenticity;
6-
6+
import com.regula.documentreader.webclient.Base64;
77
import java.io.FileWriter;
88
import java.io.IOException;
9+
import java.nio.charset.StandardCharsets;
910
import java.util.ArrayList;
1011
import java.util.List;
12+
import java.util.zip.Inflater;
1113
import javax.annotation.Nullable;
1214

1315
public class RecognitionResponse {
@@ -45,6 +47,33 @@ public Text text() {
4547
return null;
4648
}
4749

50+
@Nullable
51+
public String GetLog() {
52+
String logBase64 = this.originalResponse.getLog();
53+
if (logBase64 == null){
54+
return null;
55+
}
56+
57+
byte[] buffer = Base64.decode(logBase64);
58+
Inflater inflater = new Inflater();
59+
inflater.setInput(buffer);
60+
byte[] decompressedBuffer = new byte[1024];
61+
StringBuilder logText = new StringBuilder();
62+
63+
try {
64+
while (!inflater.finished()) {
65+
int count = inflater.inflate(decompressedBuffer);
66+
logText.append(new String(decompressedBuffer, 0, count, StandardCharsets.UTF_8));
67+
}
68+
} catch (Exception e) {
69+
e.printStackTrace();
70+
} finally {
71+
inflater.end();
72+
}
73+
74+
return logText.toString();
75+
}
76+
4877
@Nullable
4978
public Images images() {
5079
ImagesResult result = resultByType(Result.IMAGES);

0 commit comments

Comments
 (0)