Skip to content

Commit

Permalink
use nio for some operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jul 20, 2023
1 parent 334e689 commit 220acd1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions karate-core/src/main/java/com/intuit/karate/job/JobUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
Expand Down Expand Up @@ -76,10 +78,15 @@ private static void zip(File fileToZip, String fileName, ZipOutputStream zipOut,
ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
FileInputStream fis = new FileInputStream(fileToZip);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
FileChannel fc = fis.getChannel();
int bufferSize = 1024;
if (bufferSize > fc.size()) {
bufferSize = (int) fc.size();
}
ByteBuffer bb = ByteBuffer.allocate(bufferSize);
while (fc.read(bb) > 0) {
zipOut.write(bb.array(), 0, bb.position());
bb.clear();
}
fis.close();
}
Expand Down

0 comments on commit 220acd1

Please sign in to comment.