Skip to content

Commit f221f24

Browse files
committed
feat: optimize save file with zero-copy
1 parent 3b9a277 commit f221f24

File tree

6 files changed

+10
-7
lines changed

6 files changed

+10
-7
lines changed

api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.83</version>
9+
<version>0.23.84</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212
<artifactId>openai-api</artifactId>

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.83</version>
9+
<version>0.23.84</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212

example/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>io.github.ke</groupId>
88
<artifactId>example</artifactId>
9-
<version>0.23.83</version>
9+
<version>0.23.84</version>
1010
<name>example</name>
1111

1212
<properties>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>top.bella</groupId>
77
<artifactId>openai-java</artifactId>
8-
<version>0.23.83</version>
8+
<version>0.23.84</version>
99
<packaging>pom</packaging>
1010
<description>openai java 版本</description>
1111
<name>openai-java</name>

service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>top.bella</groupId>
88
<artifactId>openai-java</artifactId>
9-
<version>0.23.83</version>
9+
<version>0.23.84</version>
1010
</parent>
1111
<packaging>jar</packaging>
1212

service/src/main/java/com/theokanning/openai/service/OpenAiService.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,15 @@ public void retrieveFileContentAndSave(String fileId, String filePath) throws IO
286286
}
287287

288288
public void retrieveFileContentAndSave(String fileId, Path filePath) throws IOException {
289-
InputStream inputStream = execute(api.retrieveFileContent(fileId)).byteStream();
289+
ResponseBody responseBody = execute(api.retrieveFileContent(fileId));
290290
Path parentDir = filePath.getParent();
291291
if (parentDir != null) {
292292
Files.createDirectories(parentDir);
293293
}
294-
Files.copy(inputStream, filePath, StandardCopyOption.REPLACE_EXISTING);
294+
295+
try (BufferedSink sink = Okio.buffer(Okio.sink(filePath.toFile()))) {
296+
sink.writeAll(responseBody.source());
297+
}
295298
}
296299

297300
public ResponseBody retrieveDomTreeContent(String fileId) {

0 commit comments

Comments
 (0)