Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 19 additions & 14 deletions java/src/processing/mode/java/JavaBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,9 @@ protected void addClasses(ZipOutputStream zos, File dir, String rootPath) throws
ZipEntry entry = new ZipEntry(relativePath);
zos.putNextEntry(entry);
//zos.write(Base.loadBytesRaw(sub));
PApplet.saveStream(zos, new FileInputStream(sub));
try (InputStream fis = new FileInputStream(sub)) {
PApplet.saveStream(zos, fis);
}
zos.closeEntry();
}
}
Expand All @@ -1241,7 +1243,9 @@ protected void addDataFolder(ZipOutputStream zos) throws IOException {
ZipEntry entry = new ZipEntry(path.substring(offset));
zos.putNextEntry(entry);
//zos.write(Base.loadBytesRaw(dataFile));
PApplet.saveStream(zos, new FileInputStream(dataFile));
try (InputStream fis = new FileInputStream(dataFile)) {
PApplet.saveStream(zos, fis);
}
zos.closeEntry();
}
}
Expand All @@ -1266,8 +1270,7 @@ protected void packClassPathIntoZipFile(String path,
// is it a jar file or directory?
if (piece.toLowerCase().endsWith(".jar") ||
piece.toLowerCase().endsWith(".zip")) {
try {
ZipFile file = new ZipFile(piece);
try (ZipFile file = new ZipFile(piece)) {
Enumeration<?> entries = file.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
Expand All @@ -1284,22 +1287,22 @@ protected void packClassPathIntoZipFile(String path,

zos.putNextEntry(entree);
byte[] buffer = new byte[(int) entry.getSize()];
InputStream is = file.getInputStream(entry);

int offset = 0;
int remaining = buffer.length;
while (remaining > 0) {
int count = is.read(buffer, offset, remaining);
offset += count;
remaining -= count;
try (InputStream is = file.getInputStream(entry)) {
int offset = 0;
int remaining = buffer.length;
while (remaining > 0) {
int count = is.read(buffer, offset, remaining);
if (count == -1) break;
offset += count;
remaining -= count;
}
}

zos.write(buffer);
zos.flush();
zos.closeEntry();
}
}
file.close();

} catch (IOException e) {
System.err.println("Error in file " + piece);
Expand Down Expand Up @@ -1348,7 +1351,9 @@ static protected void packClassPathIntoZipFileRecursive(File dir,
ZipEntry entry = new ZipEntry(nowfar);
zos.putNextEntry(entry);
//zos.write(Base.loadBytesRaw(sub));
PApplet.saveStream(zos, new FileInputStream(sub));
try (InputStream fis = new FileInputStream(sub)) {
PApplet.saveStream(zos, fis);
}
zos.closeEntry();
}
}
Expand Down