GP-6152 allow cancelling via taskmonitor in streamcopy

This commit is contained in:
dev747368
2025-11-20 22:31:14 +00:00
parent 6406339043
commit b19c04f729

View File

@@ -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;
}
/**