/*
- * todesbaum-lib -
+ * todesbaum-lib -
* Copyright (C) 2006 David Roden
*
* This program is free software; you can redistribute it and/or modify
/**
* A physical connection to a Freenet node.
- *
+ *
* @author David Roden <droden@gmail.com>
* @version $Id$
*/
/** 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.
- *
+ *
* @param node
* The node to connect to
* @param name
/**
* Adds a listener that gets notified on connection events.
- *
+ *
* @param connectionListener
* The listener to add
*/
/**
* Removes a listener from the list of registered listeners. Only the first
* matching listener is removed.
- *
+ *
* @param connectionListener
* The listener to remove
* @see List#remove(java.lang.Object)
/**
* Notifies listeners about a received message.
- *
+ *
* @param message
* The received message
*/
protected void fireMessageReceived(Message message) {
- for (ConnectionListener connectionListener: connectionListeners) {
+ for (ConnectionListener connectionListener : connectionListeners) {
connectionListener.messageReceived(this, message);
}
}
* Notifies listeners about the loss of the connection.
*/
protected void fireConnectionTerminated() {
- for (ConnectionListener connectionListener: connectionListeners) {
+ for (ConnectionListener connectionListener : connectionListeners) {
connectionListener.connectionTerminated(this);
}
}
/**
* Returns the name of the connection.
- *
+ *
* @return The name of the connection
*/
public String getName() {
}
/**
+ * 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
* returned a NodeHello message
* @throws IOException
/**
* Returns whether this connection is still connected to the node.
- *
+ *
* @return <code>true</code> if this connection is still valid,
* <code>false</code> otherwise
*/
/**
* Returns the NodeHello message the node sent on connection.
- *
+ *
* @return The NodeHello message of the node
*/
public Message getNodeHello() {
/**
* Executes the specified command.
- *
+ *
* @param command
* The command to execute
* @throws IllegalStateException
* The reader thread for this connection. This is essentially a thread that
* reads lines from the node, creates messages from them and notifies
* listeners about the messages.
- *
+ *
* @author David Roden <droden@gmail.com>
* @version $Id$
*/
/**
* Creates a new reader that reads from the specified input stream.
- *
+ *
* @param nodeInputStream
* The input stream to read from
*/
/* 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"));