X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fde%2Ftodesbaum%2Futil%2Ffreenet%2Ffcp2%2FClientPutComplexDir.java;h=4be7528459df98f533422f4917730e2e523a3b15;hb=e2dd2e8bb5771f1ae859b15fab1c4eefa31faf0e;hp=12d963d7b53768b94a3c949b6446ee6973996d74;hpb=7bd75673638ec38307005f5cef154116dab30491;p=jSite.git
diff --git a/src/de/todesbaum/util/freenet/fcp2/ClientPutComplexDir.java b/src/de/todesbaum/util/freenet/fcp2/ClientPutComplexDir.java
index 12d963d..4be7528 100644
--- a/src/de/todesbaum/util/freenet/fcp2/ClientPutComplexDir.java
+++ b/src/de/todesbaum/util/freenet/fcp2/ClientPutComplexDir.java
@@ -32,8 +32,8 @@ import java.util.List;
import de.todesbaum.util.io.Closer;
/**
- * Implementation of the ClientPutComplexDir
command. This
- * command can be used to insert directories that do not exist on disk.
+ * Implementation of the ClientPutComplexDir
command. This command
+ * can be used to insert directories that do not exist on disk.
*
* @author David Roden <droden@gmail.com>
* @version $Id$
@@ -52,26 +52,55 @@ public class ClientPutComplexDir extends ClientPutDir {
/** The total number of bytes of the payload. */
private long payloadLength = 0;
+ /** The temp directory to use. */
+ private final String tempDirectory;
+
/**
- * Creates a new ClientPutComplexDir
command with the specified identifier and URI.
- * @param identifier The identifier of the command
- * @param uri The URI of the command
+ * Creates a new ClientPutComplexDir
command with the specified
+ * identifier and URI.
+ *
+ * @param identifier
+ * The identifier of the command
+ * @param uri
+ * The URI of the command
*/
public ClientPutComplexDir(String identifier, String uri) {
+ this(identifier, uri, null);
+ }
+
+ /**
+ * Creates a new ClientPutComplexDir
command with the specified
+ * identifier and URI.
+ *
+ * @param identifier
+ * The identifier of the command
+ * @param uri
+ * The URI of the command
+ * @param tempDirectory
+ * The temp directory to use, or {@code null} to use the default
+ * temp directory
+ */
+ public ClientPutComplexDir(String identifier, String uri, String tempDirectory) {
super("ClientPutComplexDir", identifier, uri);
+ this.tempDirectory = tempDirectory;
}
/**
* Adds a file to the directory inserted by this request.
- * @param fileEntry The file entry to add to the directory
+ *
+ * @param fileEntry
+ * The file entry to add to the directory
+ * @throws IOException
+ * if an I/O error occurs when creating the payload stream
*/
- public void addFileEntry(FileEntry fileEntry) {
+ public void addFileEntry(FileEntry fileEntry) throws IOException {
if (fileEntry instanceof DirectFileEntry) {
- if (payloadFile == null){
+ if (payloadFile == null) {
try {
- payloadFile = File.createTempFile("payload", ".dat");
+ payloadFile = File.createTempFile("payload", ".dat", (tempDirectory != null) ? new File(tempDirectory) : null);
payloadFile.deleteOnExit();
} catch (IOException e) {
+ /* ignore. */
}
}
if (payloadFile != null) {
@@ -87,7 +116,8 @@ public class ClientPutComplexDir extends ClientPutDir {
payloadOutputStream.flush();
fileEntries.add(fileEntry);
} catch (IOException ioe1) {
- /* hmm, ignore? */
+ payloadFile.delete();
+ throw ioe1;
} finally {
Closer.close(payloadOutputStream);
Closer.close(payloadInputStream);
@@ -105,7 +135,7 @@ public class ClientPutComplexDir extends ClientPutDir {
protected void write(Writer writer) throws IOException {
super.write(writer);
int fileIndex = 0;
- for (FileEntry fileEntry: fileEntries) {
+ for (FileEntry fileEntry : fileEntries) {
writer.write("Files." + fileIndex + ".Name=" + fileEntry.getFilename() + LINEFEED);
if (fileEntry.getContentType() != null) {
writer.write("Files." + fileIndex + ".Metadata.ContentType=" + fileEntry.getContentType() + LINEFEED);