mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-01-10 06:27:59 -05:00
GP-6152 allow cancelling via taskmonitor in streamcopy
This commit is contained in:
@@ -38,6 +38,7 @@ import ghidra.formats.gfilesystem.fileinfo.FileType;
|
||||
import ghidra.util.*;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
import ghidra.util.exception.CryptoException;
|
||||
import ghidra.util.task.CancelledListener;
|
||||
import ghidra.util.task.TaskMonitor;
|
||||
import util.CollectionUtils;
|
||||
import utilities.util.FileUtilities;
|
||||
@@ -373,14 +374,21 @@ public class FSUtilities {
|
||||
byte buffer[] = new byte[FileUtilities.IO_BUFFER_SIZE];
|
||||
int bytesRead;
|
||||
long totalBytesCopied = 0;
|
||||
while ((bytesRead = is.read(buffer)) > 0) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
totalBytesCopied += bytesRead;
|
||||
monitor.setProgress(totalBytesCopied);
|
||||
monitor.checkCancelled();
|
||||
CancelledListener l = () -> FSUtilities.uncheckedClose(is, null);
|
||||
monitor.addCancelledListener(l);
|
||||
try {
|
||||
while ((bytesRead = is.read(buffer)) > 0) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
totalBytesCopied += bytesRead;
|
||||
monitor.setProgress(totalBytesCopied);
|
||||
monitor.checkCancelled();
|
||||
}
|
||||
os.flush();
|
||||
return totalBytesCopied;
|
||||
}
|
||||
finally {
|
||||
monitor.removeCancelledListener(l);
|
||||
}
|
||||
os.flush();
|
||||
return totalBytesCopied;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user