Skip to content

Commit f55161c

Browse files
committed
add try to fileInputStreamReader
1 parent 5a5f6de commit f55161c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/main/java/com/amadeus/travel/TripParser.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ public TripDetail post(String body) throws ResponseException {
8888
*/
8989
public TripDetail post(File file) throws ResponseException, IOException {
9090
// Base64 encode file and create request body
91-
FileInputStream fileInputStreamReader = new FileInputStream(file);
92-
byte[] bytes = new byte[(int)file.length()];
93-
fileInputStreamReader.read(bytes);
94-
String encodedFile = Base64.getEncoder().encodeToString(bytes);
95-
JsonObject body = new JsonObject();
96-
body.addProperty("payload", encodedFile);
91+
try (FileInputStream fileInputStreamReader = new FileInputStream(file)) {
92+
byte[] bytes = new byte[(int)file.length()];
93+
fileInputStreamReader.read(bytes);
94+
String encodedFile = Base64.getEncoder().encodeToString(bytes);
95+
JsonObject body = new JsonObject();
96+
body.addProperty("payload", encodedFile);
9797

98-
Response response = client.post("/v3/travel/trip-parser", body);
99-
return (TripDetail) Resource.fromObject(response, TripDetail.class);
98+
Response response = client.post("/v3/travel/trip-parser", body);
99+
return (TripDetail) Resource.fromObject(response, TripDetail.class);
100+
}
100101
}
101102

102103
/**

0 commit comments

Comments
 (0)