try to close all streams as soon as possible to prevent leaks (inserting large sites...
[jSite.git] / src / de / todesbaum / util / freenet / fcp2 / Connection.java
index 1109aec..9932d25 100644 (file)
@@ -31,6 +31,7 @@ import java.nio.charset.Charset;
 import java.util.ArrayList;
 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.TempFileInputStream;
@@ -253,7 +254,13 @@ public class Connection {
                nodeWriter.write("EndMessage" + Command.LINEFEED);
                nodeWriter.flush();
                if (command.hasPayload()) {
-                       StreamCopier.copy(command.getPayload(), nodeOutputStream, command.getPayloadLength());
+                       InputStream payloadInputStream = null;
+                       try {
+                               payloadInputStream = command.getPayload();
+                               StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength());
+                       } finally {
+                               Closer.close(payloadInputStream);
+                       }
                        nodeOutputStream.flush();
                }
        }
@@ -294,7 +301,7 @@ public class Connection {
                                Message message = null;
                                while (line != null) {
                                        line = nodeReader.readLine();
-                                        System.err.println("> " + line);
+                                       // System.err.println("> " + line);
                                        if (line == null) {
                                                break;
                                        }