/*
- * todesbaum-lib -
+ * todesbaum-lib -
* Copyright (C) 2006 David Roden
*
* This program is free software; you can redistribute it and/or modify
/**
* Implementation of the <code>ClientPutComplexDir</code> command. This
* command can be used to insert directories that do not exist on disk.
- *
+ *
* @author David Roden <droden@gmail.com>
* @version $Id$
*/
/** The file entries of this directory. */
private List<FileEntry> fileEntries = new ArrayList<FileEntry>();
-
+
/** Whether this request has payload. */
private boolean hasPayload = false;
-
+
/** The input streams for the payload. */
private File payloadFile;
-
+
/** The total number of bytes of the payload. */
private long payloadLength = 0;
* @param fileEntry The file entry to add to the directory
*/
public void addFileEntry(FileEntry fileEntry) {
- if (payloadFile == null){
- try {
- payloadFile = File.createTempFile("payload", ".dat");
- payloadFile.deleteOnExit();
- } catch (IOException e) {
+ if (fileEntry instanceof DirectFileEntry) {
+ if (payloadFile == null){
+ try {
+ payloadFile = File.createTempFile("payload", ".dat");
+ payloadFile.deleteOnExit();
+ } catch (IOException e) {
+ }
}
- }
- if (payloadFile != null) {
- InputStream payloadInputStream = ((DirectFileEntry) fileEntry).getDataInputStream();
- FileOutputStream payloadOutputStream = null;
- try {
- payloadOutputStream = new FileOutputStream(payloadFile, true);
- byte[] buffer = new byte[65536];
- int read = 0;
- while ((read = payloadInputStream.read(buffer)) != -1) {
- payloadOutputStream.write(buffer, 0, read);
+ if (payloadFile != null) {
+ InputStream payloadInputStream = ((DirectFileEntry) fileEntry).getDataInputStream();
+ FileOutputStream payloadOutputStream = null;
+ try {
+ payloadOutputStream = new FileOutputStream(payloadFile, true);
+ byte[] buffer = new byte[65536];
+ int read = 0;
+ while ((read = payloadInputStream.read(buffer)) != -1) {
+ payloadOutputStream.write(buffer, 0, read);
+ }
+ payloadOutputStream.flush();
+ fileEntries.add(fileEntry);
+ } catch (IOException ioe1) {
+ /* hmm, ignore? */
+ } finally {
+ Closer.close(payloadOutputStream);
+ Closer.close(payloadInputStream);
}
- payloadOutputStream.flush();
- fileEntries.add(fileEntry);
- } catch (IOException ioe1) {
- /* hmm, ignore? */
- } finally {
- Closer.close(payloadOutputStream);
- Closer.close(payloadInputStream);
}
+ } else {
+ fileEntries.add(fileEntry);
}
}