|
6 | 6 | import com.amadeus.resources.Resource; |
7 | 7 | import com.amadeus.resources.TripDetail; |
8 | 8 | import com.google.gson.JsonObject; |
9 | | -import com.sun.org.apache.xerces.internal.impl.dv.util.Base64; |
10 | | - |
11 | 9 | import java.io.File; |
| 10 | +import java.io.FileInputStream; |
12 | 11 | import java.io.IOException; |
13 | | -import java.nio.file.Files; |
| 12 | +import java.util.Base64; |
14 | 13 |
|
15 | 14 | /** |
16 | 15 | * <p> |
@@ -89,12 +88,21 @@ public TripDetail post(String body) throws ResponseException { |
89 | 88 | */ |
90 | 89 | public TripDetail post(File file) throws ResponseException, IOException { |
91 | 90 | // Base64 encode file and create request body |
92 | | - String b64Encoded = Base64.encode(Files.readAllBytes(file.toPath())); |
93 | | - JsonObject body = new JsonObject(); |
94 | | - body.addProperty("payload", b64Encoded); |
| 91 | + try (FileInputStream fileInputStreamReader = new FileInputStream(file)) { |
| 92 | + byte[] bytes = new byte[(int)file.length()]; |
| 93 | + int count = 0; |
| 94 | + if (fileInputStreamReader.read(bytes) > 0) { |
| 95 | + String encodedFile; |
| 96 | + encodedFile = Base64.getEncoder().encodeToString(bytes); |
| 97 | + JsonObject body = new JsonObject(); |
| 98 | + body.addProperty("payload", encodedFile); |
| 99 | + count = count + fileInputStreamReader.read(bytes); |
95 | 100 |
|
96 | | - Response response = client.post("/v3/travel/trip-parser", body); |
97 | | - return (TripDetail) Resource.fromObject(response, TripDetail.class); |
| 101 | + Response response = client.post("/v3/travel/trip-parser", body); |
| 102 | + return (TripDetail) Resource.fromObject(response, TripDetail.class); |
| 103 | + } |
| 104 | + } |
| 105 | + return null; |
98 | 106 | } |
99 | 107 |
|
100 | 108 | /** |
|
0 commit comments