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 public void close() throws IOException
42 {
43 super.close();
44
45 if (moveToOnClose != null)
46 {
47 FileUtils.moveFile(currentFile, moveToOnClose);
48 }
49 else if (deleteOnClose)
50 {
51 if (!currentFile.delete())
52 {
53 try
54 {
55 throw new DefaultMuleException(
56 FileMessages.failedToDeleteFile(currentFile.getAbsolutePath()));
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
73 }