mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-17 13:19:52 +01:00
Added finish() methods to transport readers/writers, and added a
readerFinished() callback method to FilePlugin.
This commit is contained in:
@@ -13,9 +13,14 @@ public interface BatchTransportReader {
|
|||||||
InputStream getInputStream();
|
InputStream getInputStream();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the reader and disposes of any associated state. This method must
|
* Finishes reading from the transport. This method should be called after
|
||||||
* be called even if the reader is not used, or if an exception is thrown
|
* closing the input stream.
|
||||||
* while using the reader.
|
*/
|
||||||
|
void finish() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of any associated state. This method must be called even if the
|
||||||
|
* reader is not used, or if an exception is thrown while using the reader.
|
||||||
*/
|
*/
|
||||||
void dispose() throws IOException;
|
void dispose() throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,9 +18,15 @@ public interface StreamTransportConnection {
|
|||||||
OutputStream getOutputStream() throws IOException;
|
OutputStream getOutputStream() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the connection and disposes of any associated state. This method
|
* Finishes using the transport. This method should be called after closing
|
||||||
* must be called even if the connection is not used, or if an exception
|
* the input and output streams.
|
||||||
* is thrown while using the connection.
|
*/
|
||||||
|
void finish() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disposes of any associated state. This method must be called even if the
|
||||||
|
* connection is not used, or if an exception is thrown while using the
|
||||||
|
* connection.
|
||||||
*/
|
*/
|
||||||
void close() throws IOException;
|
void close() throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ abstract class FilePlugin implements BatchTransportPlugin {
|
|||||||
|
|
||||||
protected abstract File chooseOutputDirectory();
|
protected abstract File chooseOutputDirectory();
|
||||||
protected abstract void writerFinished(File f);
|
protected abstract void writerFinished(File f);
|
||||||
|
protected abstract void readerFinished(File f);
|
||||||
|
|
||||||
FilePlugin(Executor executor) {
|
FilePlugin(Executor executor) {
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
@@ -138,7 +139,8 @@ abstract class FilePlugin implements BatchTransportPlugin {
|
|||||||
if(f.length() < TransportConstants.MIN_CONNECTION_LENGTH) return;
|
if(f.length() < TransportConstants.MIN_CONNECTION_LENGTH) return;
|
||||||
try {
|
try {
|
||||||
FileInputStream in = new FileInputStream(f);
|
FileInputStream in = new FileInputStream(f);
|
||||||
callback.readerCreated(new FileTransportReader(f, in));
|
callback.readerCreated(new FileTransportReader(f, in,
|
||||||
|
FilePlugin.this));
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,14 @@ class FileTransportReader implements BatchTransportReader {
|
|||||||
|
|
||||||
private final File file;
|
private final File file;
|
||||||
private final InputStream in;
|
private final InputStream in;
|
||||||
|
private final FilePlugin plugin;
|
||||||
|
|
||||||
private boolean streamInUse = false;
|
private boolean streamInUse = false;
|
||||||
|
|
||||||
FileTransportReader(File file, InputStream in) {
|
FileTransportReader(File file, InputStream in, FilePlugin plugin) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.in = in;
|
this.in = in;
|
||||||
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
@@ -23,6 +25,11 @@ class FileTransportReader implements BatchTransportReader {
|
|||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void finish() throws IOException {
|
||||||
|
streamInUse = false;
|
||||||
|
plugin.readerFinished(file);
|
||||||
|
}
|
||||||
|
|
||||||
public void dispose() throws IOException {
|
public void dispose() throws IOException {
|
||||||
if(streamInUse) in.close();
|
if(streamInUse) in.close();
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ implements RemovableDriveMonitor.Callback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void readerFinished(File f) {
|
||||||
|
callback.showMessage("REMOVABLE_DRIVE_READ_FINISHED");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void writerFinished(File f) {
|
protected void writerFinished(File f) {
|
||||||
callback.showMessage("REMOVABLE_DRIVE_WRITE_FINISHED");
|
callback.showMessage("REMOVABLE_DRIVE_WRITE_FINISHED");
|
||||||
|
|||||||
Reference in New Issue
Block a user