1 package net.sourceforge.blogentis.slide;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.io.ByteArrayInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.InputStream;
28 import java.util.Date;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 import net.sourceforge.blogentis.om.Blog;
33 import net.sourceforge.blogentis.storage.AbstractFileResource;
34
35 /***
36 * A memory-based AbstractFileResource. It is mainly used for saving to the
37 * slide store.
38 *
39 * @author abas
40 */
41 public class SlideMemoryFile
42 implements AbstractFileResource {
43 private byte[] byteSource = null;
44 private InputStream streamSource = null;
45 private int length = 0;
46 private String path;
47 private Blog blog;
48 private String mimeType = null;
49 private Date lastModified = null;
50 Map properties = new HashMap();
51
52 public SlideMemoryFile(Blog blog, String path) {
53 this.blog = blog;
54 this.path = path;
55 }
56
57 public void setContents(byte[] contents) {
58 byteSource = contents;
59 streamSource = null;
60 length = contents.length;
61 }
62
63 public void setContents(InputStream contents) {
64 byteSource = null;
65 streamSource = contents;
66 length = -1;
67 }
68
69 public String getPath() {
70 return path;
71 }
72
73 public boolean exists() {
74 return false;
75 }
76
77 public int getSize() {
78 return length;
79 }
80
81 public Date getLastModified() {
82 return lastModified;
83 }
84
85 public String getMimeType() {
86 return mimeType;
87 }
88
89 public InputStream getFileAsInputStream()
90 throws FileNotFoundException {
91 if (streamSource != null)
92 return streamSource;
93 if (byteSource != null)
94 return new ByteArrayInputStream(byteSource);
95 throw new FileNotFoundException("No input set!");
96 }
97
98 public String getFileAsString()
99 throws FileNotFoundException {
100 return null;
101 }
102
103 public Blog getBlog() {
104 return blog;
105 }
106
107 public void setLastModified(Date lastModified) {
108 this.lastModified = lastModified;
109 }
110
111 public void setMimeType(String mimeType) {
112 this.mimeType = mimeType;
113 }
114
115 public boolean isOriginal() {
116 return false;
117 }
118
119 public String getProperty(String propertyName) {
120 return (String)properties.get(propertyName);
121 }
122
123 public void setProperty(String propertyName, String propertyContents) {
124 properties.put(propertyName, propertyContents);
125 }
126
127 public boolean isDirectory() {
128 return false;
129 }
130 }