Converted {Incoming,Outgoing}BatchConnection into Runnables.

Also changed the dispose() method of readers/writers/connections to
swallow any exceptions that occur, since the caller can't do anything
except log them.
This commit is contained in:
akwizgran
2011-10-14 16:14:29 +01:00
parent 55182528cf
commit d48c7b6900
14 changed files with 290 additions and 92 deletions

View File

@@ -3,6 +3,8 @@ package net.sf.briar.plugins.bluetooth;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.io.StreamConnection;
@@ -10,6 +12,9 @@ import net.sf.briar.api.transport.StreamTransportConnection;
class BluetoothTransportConnection implements StreamTransportConnection {
private static final Logger LOG =
Logger.getLogger(BluetoothTransportConnection.class.getName());
private final StreamConnection stream;
BluetoothTransportConnection(StreamConnection stream) {
@@ -24,7 +29,11 @@ class BluetoothTransportConnection implements StreamTransportConnection {
return stream.openOutputStream();
}
public void dispose(boolean success) throws IOException {
stream.close();
public void dispose(boolean success) {
try {
stream.close();
} catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
}
}
}

View File

@@ -3,11 +3,16 @@ package net.sf.briar.plugins.file;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.briar.api.transport.BatchTransportReader;
class FileTransportReader implements BatchTransportReader {
private static final Logger LOG =
Logger.getLogger(FileTransportReader.class.getName());
private final File file;
private final InputStream in;
private final FilePlugin plugin;
@@ -22,12 +27,15 @@ class FileTransportReader implements BatchTransportReader {
return in;
}
public void dispose(boolean success) throws IOException {
public void dispose(boolean success) {
try {
in.close();
if(success) plugin.readerFinished(file);
} finally {
} catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
}
if(success) {
file.delete();
plugin.readerFinished(file);
}
}
}

View File

@@ -3,11 +3,16 @@ package net.sf.briar.plugins.file;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.briar.api.transport.BatchTransportWriter;
class FileTransportWriter implements BatchTransportWriter {
private static final Logger LOG =
Logger.getLogger(FileTransportWriter.class.getName());
private final File file;
private final OutputStream out;
private final long capacity;
@@ -29,12 +34,13 @@ class FileTransportWriter implements BatchTransportWriter {
return out;
}
public void dispose(boolean success) throws IOException {
public void dispose(boolean success) {
try {
out.close();
if(success) plugin.writerFinished(file);
} finally {
file.delete();
} catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
}
if(success) plugin.writerFinished(file);
else file.delete();
}
}

View File

@@ -4,11 +4,16 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.briar.api.transport.StreamTransportConnection;
class SocketTransportConnection implements StreamTransportConnection {
private static final Logger LOG =
Logger.getLogger(SocketTransportConnection.class.getName());
private final Socket socket;
SocketTransportConnection(Socket socket) {
@@ -23,7 +28,11 @@ class SocketTransportConnection implements StreamTransportConnection {
return socket.getOutputStream();
}
public void dispose(boolean success) throws IOException {
socket.close();
public void dispose(boolean success) {
try {
socket.close();
} catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.getMessage());
}
}
}