Added finish() methods to transport readers/writers, and added a

readerFinished() callback method to FilePlugin.
This commit is contained in:
akwizgran
2011-10-05 18:59:30 +01:00
parent 775d76d040
commit 80cba1e7f7
5 changed files with 33 additions and 8 deletions

View File

@@ -32,6 +32,7 @@ abstract class FilePlugin implements BatchTransportPlugin {
protected abstract File chooseOutputDirectory();
protected abstract void writerFinished(File f);
protected abstract void readerFinished(File f);
FilePlugin(Executor executor) {
this.executor = executor;
@@ -138,7 +139,8 @@ abstract class FilePlugin implements BatchTransportPlugin {
if(f.length() < TransportConstants.MIN_CONNECTION_LENGTH) return;
try {
FileInputStream in = new FileInputStream(f);
callback.readerCreated(new FileTransportReader(f, in));
callback.readerCreated(new FileTransportReader(f, in,
FilePlugin.this));
} catch(IOException e) {
return;
}

View File

@@ -10,12 +10,14 @@ class FileTransportReader implements BatchTransportReader {
private final File file;
private final InputStream in;
private final FilePlugin plugin;
private boolean streamInUse = false;
FileTransportReader(File file, InputStream in) {
FileTransportReader(File file, InputStream in, FilePlugin plugin) {
this.file = file;
this.in = in;
this.plugin = plugin;
}
public InputStream getInputStream() {
@@ -23,6 +25,11 @@ class FileTransportReader implements BatchTransportReader {
return in;
}
public void finish() throws IOException {
streamInUse = false;
plugin.readerFinished(file);
}
public void dispose() throws IOException {
if(streamInUse) in.close();
file.delete();

View File

@@ -65,6 +65,11 @@ implements RemovableDriveMonitor.Callback {
}
}
@Override
protected void readerFinished(File f) {
callback.showMessage("REMOVABLE_DRIVE_READ_FINISHED");
}
@Override
protected void writerFinished(File f) {
callback.showMessage("REMOVABLE_DRIVE_WRITE_FINISHED");