Skip to content

Commit d3f390e

Browse files
committed
Additional removal of readAllBytes
1 parent e82df67 commit d3f390e

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

API/src/main/java/org/ohnlp/backbone/api/components/xlang/python/PythonBridge.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,24 @@ private void extractPythonResourcesIfNotExists() {
164164
env.completeExceptionally(new IllegalArgumentException("Could not find module " + this.bundleIdentifier));
165165
return;
166166
}
167-
ZipInputStream zis = new ZipInputStream(is);
168-
// - Now actually copy the resources over
169-
ZipEntry entry;
170-
while ((entry = zis.getNextEntry()) != null) {
171-
if (entry.isDirectory()) {
172-
continue;
173-
}
174-
String pathRelative = entry.getName();
175-
File pathInTmp = new File(workDir, pathRelative);
176-
byte[] contents = zis.readAllBytes();
177-
try (FileOutputStream fos = new FileOutputStream(pathInTmp)) {
178-
fos.write(contents);
179-
fos.flush();
167+
try (ZipInputStream zis = new ZipInputStream(is)) {
168+
// - Now actually copy the resources over
169+
ZipEntry entry;
170+
while ((entry = zis.getNextEntry()) != null) {
171+
if (entry.isDirectory()) {
172+
continue;
173+
}
174+
File pathInTmp = new File(workDir, entry.getName());
175+
pathInTmp.getParentFile().mkdirs();
176+
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(pathInTmp))) {
177+
byte[] buffer = new byte[8192];
178+
int len;
179+
while ((len = zis.read(buffer)) > 0) {
180+
bos.write(buffer, 0, len);
181+
}
182+
}
180183
}
181184
}
182-
zis.close();
183185
} catch (IOException e) {
184186
env.completeExceptionally(e);
185187
return;

0 commit comments

Comments
 (0)