mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Added finish() methods to transport readers/writers, and added a
readerFinished() callback method to FilePlugin.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user