1
2
3
4
5
6
7
8
9
10
11 package org.mule.transport.file;
12
13 import org.mule.api.DefaultMuleException;
14 import org.mule.transport.file.i18n.FileMessages;
15 import org.mule.util.FileUtils;
16
17 import java.io.File;
18 import java.io.FileInputStream;
19 import java.io.FileNotFoundException;
20 import java.io.IOException;
21
22
23
24
25
26 class ReceiverFileInputStream extends FileInputStream
27 {
28 private File currentFile;
29 private boolean deleteOnClose;
30 private File moveToOnClose;
31
32 public ReceiverFileInputStream(File currentFile, boolean deleteOnClose, File moveToOnClose)
33 throws FileNotFoundException
34 {
35 super(currentFile);
36 this.currentFile = currentFile;
37 this.deleteOnClose = deleteOnClose;
38 this.moveToOnClose = moveToOnClose;
39 }
40
41 @Override
42 public void close() throws IOException
43 {
44 super.close();
45
46 if (moveToOnClose != null)
47 {
48 FileUtils.moveFileWithCopyFallback(currentFile, moveToOnClose);
49 }
50 else if (deleteOnClose)
51 {
52 if (!currentFile.delete())
53 {
54 try
55 {
56 throw new DefaultMuleException(FileMessages.failedToDeleteFile(currentFile));
57 }
58 catch (DefaultMuleException e)
59 {
60 IOException e2 = new IOException();
61 e2.initCause(e);
62 throw e2;
63 }
64 }
65 }
66 }
67
68 public File getCurrentFile()
69 {
70 return currentFile;
71 }
72 }