[Minor] Code cleanup

This commit is contained in:
Robert von Burg 2023-04-04 07:21:21 +02:00
parent d6bc44bcca
commit 13eda97b16
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 11 additions and 12 deletions

View File

@ -28,10 +28,9 @@ import org.slf4j.LoggerFactory;
public class FileStreamProgressWatcher implements Runnable { public class FileStreamProgressWatcher implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(FileStreamProgressWatcher.class); private static final Logger logger = LoggerFactory.getLogger(FileStreamProgressWatcher.class);
private ProgressableFileInputStream inputStream; private final ProgressableFileInputStream inputStream;
private boolean run = false; private final FileProgressListener progressListener;
private FileProgressListener progressListener; private final long millis;
private long millis;
public FileStreamProgressWatcher(long millis, FileProgressListener progressListener, public FileStreamProgressWatcher(long millis, FileProgressListener progressListener,
ProgressableFileInputStream inputStream) { ProgressableFileInputStream inputStream) {
@ -42,36 +41,36 @@ public class FileStreamProgressWatcher implements Runnable {
@Override @Override
public void run() { public void run() {
this.run = true; boolean run = true;
this.progressListener.begin(this.inputStream.getPercentComplete(), this.inputStream.getBytesRead(), this.progressListener.begin(this.inputStream.getPercentComplete(), this.inputStream.getBytesRead(),
this.inputStream.getFileSize()); this.inputStream.getFileSize());
while (this.run) { while (run) {
try { try {
int percentComplete = this.inputStream.getPercentComplete(); int percentComplete = this.inputStream.getPercentComplete();
if (this.inputStream.isClosed()) { if (this.inputStream.isClosed()) {
logger.info(MessageFormat.format("Input Stream is closed at: {0}%", percentComplete)); //$NON-NLS-1$ logger.info(MessageFormat.format("Input Stream is closed at: {0}%", percentComplete)); //$NON-NLS-1$
this.run = false; run = false;
this.progressListener.end(percentComplete, this.inputStream.getBytesRead()); this.progressListener.end(percentComplete, this.inputStream.getBytesRead());
} else if (percentComplete < 100) { } else if (percentComplete < 100) {
this.progressListener.progress(percentComplete, this.inputStream.getBytesRead()); this.progressListener.progress(percentComplete, this.inputStream.getBytesRead());
} else if (percentComplete >= 100) { } else {
this.run = false; run = false;
this.progressListener.end(percentComplete, this.inputStream.getBytesRead()); this.progressListener.end(percentComplete, this.inputStream.getBytesRead());
} }
if (this.run) if (run)
Thread.sleep(this.millis); Thread.sleep(this.millis);
} catch (InterruptedException e) { } catch (InterruptedException e) {
this.run = false; run = false;
int percentComplete = this.inputStream.getPercentComplete(); int percentComplete = this.inputStream.getPercentComplete();
if (percentComplete != 100) if (percentComplete != 100)
logger.info(MessageFormat.format("Work stopped: {0}", e.getLocalizedMessage())); //$NON-NLS-1$ logger.info(MessageFormat.format("Work stopped: {0}", e.getLocalizedMessage())); //$NON-NLS-1$
this.progressListener.end(percentComplete, this.inputStream.getBytesRead()); this.progressListener.end(percentComplete, this.inputStream.getBytesRead());
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
this.run = false; run = false;
int percentComplete = this.inputStream.getPercentComplete(); int percentComplete = this.inputStream.getPercentComplete();
this.progressListener.end(percentComplete, Long.MAX_VALUE); this.progressListener.end(percentComplete, Long.MAX_VALUE);
} }