Skip to content

Commit e53f6ac

Browse files
committed
check ready bytes
1 parent f55161c commit e53f6ac

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,19 @@ public TripDetail post(File file) throws ResponseException, IOException {
9090
// Base64 encode file and create request body
9191
try (FileInputStream fileInputStreamReader = new FileInputStream(file)) {
9292
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);
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);
97100

98-
Response response = client.post("/v3/travel/trip-parser", body);
99-
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+
}
100104
}
105+
return null;
101106
}
102107

103108
/**

0 commit comments

Comments
 (0)