mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 11:49:04 +01:00
Merged transports' finish() and dispose() methods.
This commit is contained in:
@@ -12,8 +12,6 @@ class FileTransportReader implements BatchTransportReader {
|
||||
private final InputStream in;
|
||||
private final FilePlugin plugin;
|
||||
|
||||
private boolean streamInUse = false;
|
||||
|
||||
FileTransportReader(File file, InputStream in, FilePlugin plugin) {
|
||||
this.file = file;
|
||||
this.in = in;
|
||||
@@ -21,17 +19,15 @@ class FileTransportReader implements BatchTransportReader {
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
streamInUse = true;
|
||||
return in;
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
streamInUse = false;
|
||||
plugin.readerFinished(file);
|
||||
}
|
||||
|
||||
public void dispose() throws IOException {
|
||||
if(streamInUse) in.close();
|
||||
file.delete();
|
||||
public void dispose(boolean success) throws IOException {
|
||||
try {
|
||||
in.close();
|
||||
if(success) plugin.readerFinished(file);
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,6 @@ class FileTransportWriter implements BatchTransportWriter {
|
||||
private final long capacity;
|
||||
private final FilePlugin plugin;
|
||||
|
||||
private boolean streamInUse = false;
|
||||
|
||||
FileTransportWriter(File file, OutputStream out, long capacity,
|
||||
FilePlugin plugin) {
|
||||
this.file = file;
|
||||
@@ -28,17 +26,15 @@ class FileTransportWriter implements BatchTransportWriter {
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() {
|
||||
streamInUse = true;
|
||||
return out;
|
||||
}
|
||||
|
||||
public void finish() {
|
||||
streamInUse = false;
|
||||
plugin.writerFinished(file);
|
||||
}
|
||||
|
||||
public void dispose() throws IOException {
|
||||
if(streamInUse) out.close();
|
||||
file.delete();
|
||||
public void dispose(boolean success) throws IOException {
|
||||
try {
|
||||
out.close();
|
||||
if(success) plugin.writerFinished(file);
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.concurrent.Executor;
|
||||
import net.sf.briar.api.ContactId;
|
||||
import net.sf.briar.api.TransportId;
|
||||
|
||||
public class SimpleSocketPlugin extends SocketPlugin {
|
||||
class SimpleSocketPlugin extends SocketPlugin {
|
||||
|
||||
public static final int TRANSPORT_ID = 1;
|
||||
|
||||
|
||||
@@ -135,6 +135,7 @@ implements StreamTransportPlugin {
|
||||
}
|
||||
|
||||
public synchronized void poll() {
|
||||
// Subclasses may not support polling
|
||||
if(!shouldPoll()) throw new UnsupportedOperationException();
|
||||
if(!started) return;
|
||||
for(ContactId c : remoteProperties.keySet()) {
|
||||
|
||||
@@ -11,28 +11,19 @@ class SocketTransportConnection implements StreamTransportConnection {
|
||||
|
||||
private final Socket socket;
|
||||
|
||||
private boolean streamInUse = false;
|
||||
|
||||
SocketTransportConnection(Socket socket) {
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
public InputStream getInputStream() throws IOException {
|
||||
streamInUse = true;
|
||||
return socket.getInputStream();
|
||||
}
|
||||
|
||||
public OutputStream getOutputStream() throws IOException {
|
||||
streamInUse = true;
|
||||
return socket.getOutputStream();
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
// FIXME: Tell the plugin?
|
||||
streamInUse = false;
|
||||
}
|
||||
|
||||
public void dispose() throws IOException {
|
||||
if(streamInUse) socket.close();
|
||||
public void dispose(boolean success) throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user