1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.transport.file; |
12 | |
|
13 | |
import org.mule.api.MessagingException; |
14 | |
import org.mule.api.MuleRuntimeException; |
15 | |
import org.mule.api.ThreadSafeAccess; |
16 | |
import org.mule.config.i18n.CoreMessages; |
17 | |
import org.mule.util.IOUtils; |
18 | |
|
19 | |
import java.io.FileInputStream; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class FileContentsMessageAdapter extends FileMessageAdapter |
28 | |
{ |
29 | |
|
30 | |
|
31 | |
|
32 | |
private static final long serialVersionUID = 7368719494535568721L; |
33 | |
|
34 | 27 | private byte[] contents = null; |
35 | |
|
36 | |
public FileContentsMessageAdapter(Object message) throws MessagingException |
37 | |
{ |
38 | 27 | super(message); |
39 | 27 | this.getPayload(); |
40 | 26 | } |
41 | |
|
42 | |
public FileContentsMessageAdapter(FileContentsMessageAdapter template) |
43 | |
{ |
44 | 0 | super(template); |
45 | 0 | contents = template.contents; |
46 | 0 | this.getPayload(); |
47 | 0 | } |
48 | |
|
49 | |
public Object getPayload() |
50 | |
{ |
51 | 149 | if (contents == null) |
52 | |
{ |
53 | 27 | synchronized (this) |
54 | |
{ |
55 | |
try |
56 | |
{ |
57 | 27 | if (fileInputStream == null) |
58 | |
{ |
59 | 27 | fileInputStream = new FileInputStream(file); |
60 | |
} |
61 | 26 | contents = IOUtils.toByteArray(fileInputStream); |
62 | 26 | fileInputStream.close(); |
63 | |
} |
64 | 1 | catch (Exception noPayloadException) |
65 | |
{ |
66 | 1 | throw new MuleRuntimeException(CoreMessages.failedToReadPayload(), noPayloadException); |
67 | 26 | } |
68 | 26 | } |
69 | |
} |
70 | 148 | return contents; |
71 | |
} |
72 | |
|
73 | |
public ThreadSafeAccess newThreadCopy() |
74 | |
{ |
75 | 0 | return new FileContentsMessageAdapter(this); |
76 | |
} |
77 | |
} |