Whitespace and formatting fixes.
[jSite.git] / src / de / todesbaum / util / freenet / fcp2 / Connection.java
index 9c6b74d..3fd39f6 100644 (file)
@@ -71,6 +71,9 @@ public class Connection {
        /** The NodeHello message sent by the node on connect. */
        protected Message nodeHello;
 
+       /** The temp directory to use. */
+       private String tempDirectory;
+
        /**
         * Creates a new connection to the specified node with the specified name.
         *
@@ -113,7 +116,7 @@ public class Connection {
         *            The received message
         */
        protected void fireMessageReceived(Message message) {
-               for (ConnectionListener connectionListener: connectionListeners) {
+               for (ConnectionListener connectionListener : connectionListeners) {
                        connectionListener.messageReceived(this, message);
                }
        }
@@ -122,7 +125,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);
                }
        }
@@ -137,6 +140,17 @@ public class Connection {
        }
 
        /**
+        * Sets the temp directory to use for creation of temporary files.
+        *
+        * @param tempDirectory
+        *            The temp directory to use, or {@code null} to use the default
+        *            temp directory
+        */
+       public void setTempDirectory(String tempDirectory) {
+               this.tempDirectory = tempDirectory;
+       }
+
+       /**
         * Connects to the node.
         *
         * @return <code>true</code> if the connection succeeded and the node
@@ -313,7 +327,7 @@ public class Connection {
                                                /* need to read message from stream now */
                                                File tempFile = null;
                                                try {
-                                                       tempFile = File.createTempFile("fcpv2", "data");
+                                                       tempFile = File.createTempFile("fcpv2", "data", (tempDirectory != null) ? new File(tempDirectory) : null);
                                                        tempFile.deleteOnExit();
                                                        FileOutputStream tempFileOutputStream = new FileOutputStream(tempFile);
                                                        long dataLength = Long.parseLong(message.get("DataLength"));