X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fde%2Ftodesbaum%2Futil%2Ffreenet%2Ffcp2%2FConnection.java;h=d8a8b2d0796fff54dacae1bbe7b486c1b7e310a8;hb=4aa8626a4290644be70b2fe35de7c9d392d4574f;hp=951b534c97e630e38e706634c756cdfadae774f5;hpb=4307e3f23f6b88b68e4e5db1dcc54d5f1e04193e;p=jSite.git diff --git a/src/de/todesbaum/util/freenet/fcp2/Connection.java b/src/de/todesbaum/util/freenet/fcp2/Connection.java index 951b534..d8a8b2d 100644 --- a/src/de/todesbaum/util/freenet/fcp2/Connection.java +++ b/src/de/todesbaum/util/freenet/fcp2/Connection.java @@ -34,6 +34,7 @@ import java.util.List; import de.todesbaum.util.io.Closer; import de.todesbaum.util.io.LineInputStream; import de.todesbaum.util.io.StreamCopier; +import de.todesbaum.util.io.StreamCopier.ProgressListener; import de.todesbaum.util.io.TempFileInputStream; /** @@ -116,7 +117,7 @@ public class Connection { * The received message */ protected void fireMessageReceived(Message message) { - for (ConnectionListener connectionListener: connectionListeners) { + for (ConnectionListener connectionListener : connectionListeners) { connectionListener.messageReceived(this, message); } } @@ -125,7 +126,7 @@ public class Connection { * Notifies listeners about the loss of the connection. */ protected void fireConnectionTerminated() { - for (ConnectionListener connectionListener: connectionListeners) { + for (ConnectionListener connectionListener : connectionListeners) { connectionListener.connectionTerminated(this); } } @@ -215,34 +216,15 @@ public class Connection { * Disconnects from the node. */ public void disconnect() { - if (nodeWriter != null) { - try { - nodeWriter.close(); - } catch (IOException ioe1) { - } - nodeWriter = null; - } - if (nodeOutputStream != null) { - try { - nodeOutputStream.close(); - } catch (IOException ioe1) { - } - nodeOutputStream = null; - } - if (nodeInputStream != null) { - try { - nodeInputStream.close(); - } catch (IOException ioe1) { - } - nodeInputStream = null; - } - if (nodeSocket != null) { - try { - nodeSocket.close(); - } catch (IOException ioe1) { - } - nodeSocket = null; - } + Closer.close(nodeWriter); + nodeWriter = null; + Closer.close(nodeOutputStream); + nodeOutputStream = null; + Closer.close(nodeInputStream); + nodeInputStream = null; + nodeInputStream = null; + Closer.close(nodeSocket); + nodeSocket = null; synchronized (this) { notify(); } @@ -260,6 +242,22 @@ public class Connection { * if an I/O error occurs */ public synchronized void execute(Command command) throws IllegalStateException, IOException { + execute(command, null); + } + + /** + * Executes the specified command. + * + * @param command + * The command to execute + * @param progressListener + * A progress listener for a payload transfer + * @throws IllegalStateException + * if the connection is not connected + * @throws IOException + * if an I/O error occurs + */ + public synchronized void execute(Command command, ProgressListener progressListener) throws IllegalStateException, IOException { if (nodeSocket == null) { throw new IllegalStateException("connection is not connected"); } @@ -271,7 +269,7 @@ public class Connection { InputStream payloadInputStream = null; try { payloadInputStream = command.getPayload(); - StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength()); + StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength(), progressListener); } finally { Closer.close(payloadInputStream); } @@ -307,6 +305,7 @@ public class Connection { * Main loop of the reader. Lines are read and converted into * {@link Message} objects. */ + @SuppressWarnings("synthetic-access") public void run() { LineInputStream nodeReader = null; try {