01: package org.mule.transport.file;
02:
03: import org.mule.api.DefaultMuleException;
04: import org.mule.transport.file.i18n.FileMessages;
05: import org.mule.util.FileUtils;
06:
07: import java.io.File;
08: import java.io.FileInputStream;
09: import java.io.FileNotFoundException;
10: import java.io.IOException;
11:
12: /**
13: * This implementation is used when streaming and will move or delete the source file
14: * when the stream is closed.
15: */
16: class ReceiverFileInputStream extends FileInputStream {
17: private File currentFile;
18: private boolean deleteOnClose;
19: private File moveToOnClose;
20:
21: public ReceiverFileInputStream(File currentFile,
22: boolean deleteOnClose, File moveToOnClose)
23: throws FileNotFoundException {
24: super (currentFile);
25: this .currentFile = currentFile;
26: this .deleteOnClose = deleteOnClose;
27: this .moveToOnClose = moveToOnClose;
28: }
29:
30: public void close() throws IOException {
31: super .close();
32:
33: if (moveToOnClose != null) {
34: FileUtils.moveFile(currentFile, moveToOnClose);
35: } else if (deleteOnClose) {
36: if (!currentFile.delete()) {
37: try {
38: throw new DefaultMuleException(FileMessages
39: .failedToDeleteFile(currentFile
40: .getAbsolutePath()));
41: } catch (DefaultMuleException e) {
42: IOException e2 = new IOException();
43: e2.initCause(e);
44: throw e2;
45: }
46: }
47: }
48: }
49:
50: public File getCurrentFile() {
51: return currentFile;
52: }
53:
54: }
|