Skip to content

Commit 06c51ac

Browse files
committed
Fix error on InputStream conversion
1 parent 81ca3eb commit 06c51ac

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

examples/src/main/java/com/convertapi/examples/ConvertStream.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public static void main(String[] args) throws ExecutionException, InterruptedExc
2525
Config.setDefaultApiCredentials(getenv("API_TOKEN")); // Get your api token at https://www.convertapi.com/a/authentication
2626

2727
// Creating file data stream
28-
InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath());
29-
30-
System.out.println("Converting stream of DOCX data to PDF");
31-
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf",
28+
try (InputStream stream = Files.newInputStream(new File("src/main/resources/test.docx").toPath())) {
29+
System.out.println("Converting stream of DOCX data to PDF");
30+
CompletableFuture<ConversionResult> result = ConvertApi.convert("docx", "pdf",
3231
new Param("file", stream, "test.docx")
33-
);
32+
);
3433

35-
Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
36-
result.get().saveFile(pdfFile).get();
34+
Path pdfFile = Paths.get(System.getProperty("java.io.tmpdir") + "/myfile.pdf");
35+
result.get().saveFile(pdfFile).get();
3736

38-
System.out.println("PDF file saved to: " + pdfFile.toString());
37+
System.out.println("PDF file saved to: " + pdfFile.toString());
38+
}
3939
}
4040
}

src/main/java/com/convertapi/client/RequestBodyStream.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ public MediaType contentType() {
1919
return mediaType;
2020
}
2121

22-
@Override
23-
public long contentLength() {
24-
try {
25-
return inputStream.available();
26-
} catch (IOException e) {
27-
return 0;
28-
}
29-
}
30-
3122
@Override
3223
public void writeTo(BufferedSink sink) throws IOException {
3324
Source source = null;

0 commit comments

Comments
 (0)