Skip to content

Commit

Permalink
avoid using file input stream
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jul 20, 2023
1 parent 220acd1 commit 3e80975
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 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,7 @@
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.function.Predicate;
Expand Down Expand Up @@ -77,8 +78,8 @@ private static void zip(File fileToZip, String fileName, ZipOutputStream zipOut,
}
ZipEntry zipEntry = new ZipEntry(fileName);
zipOut.putNextEntry(zipEntry);
FileInputStream fis = new FileInputStream(fileToZip);
FileChannel fc = fis.getChannel();
RandomAccessFile reader = new RandomAccessFile(fileToZip, "r");
FileChannel fc = reader.getChannel();
int bufferSize = 1024;
if (bufferSize > fc.size()) {
bufferSize = (int) fc.size();
Expand All @@ -88,7 +89,7 @@ private static void zip(File fileToZip, String fileName, ZipOutputStream zipOut,
zipOut.write(bb.array(), 0, bb.position());
bb.clear();
}
fis.close();
reader.close();
}

public static void unzip(File src, File dest) {
Expand Down

0 comments on commit 3e80975

Please sign in to comment.