1 package net.sourceforge.blogentis.storage;
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.FileNotFoundException;
26 import java.io.InputStream;
27 import java.util.Date;
28
29 /***
30 * Interface for abstract files.
31 *
32 * @author abas
33 */
34 public interface AbstractFileResource {
35 /***
36 * Get the the path that this file has.
37 *
38 * @return the path of the file.
39 */
40 public String getPath();
41
42 /***
43 * Check whether the file exists.
44 *
45 * @return true if the file exists and is a file, false otherwise.
46 */
47 public boolean exists();
48
49 /***
50 * Get the size of the file.
51 *
52 * @return the size of the file in bytes.
53 */
54 public int getSize();
55
56 /***
57 * Get the last modification time of the file.
58 *
59 * @return the last modification time of the file.
60 */
61 public Date getLastModified();
62
63 /***
64 * Get the stored mime-type of the file or compute it.
65 *
66 * @return the mime-type of the file.
67 */
68 public String getMimeType();
69
70 /***
71 *
72 * @return @throws
73 * FileNotFoundException if exists() is false.
74 */
75 public InputStream getFileAsInputStream()
76 throws FileNotFoundException;
77
78 /***
79 * Get the contents of the file as a string.
80 *
81 * @return @throws
82 * FileNotFoundException if exists() is false.
83 */
84 public String getFileAsString()
85 throws FileNotFoundException;
86
87 /***
88 * Check whether this file has not been modified by the user.
89 *
90 * Only files that return this as false will be backed up.
91 *
92 * @return true if the file has not been modified by the user and is the
93 * original file distributed.
94 */
95 public boolean isOriginal();
96
97 /***
98 * Determine if this is a directory.
99 *
100 * @return true if a directory
101 */
102 public boolean isDirectory();
103
104 /***
105 * Retrieve a property of the file. Properties are String/String key/value
106 * pairs. Implementation is optional.
107 *
108 * @param propertyName
109 * the name of the property to fetch.
110 * @return the property or null of the property does not exist or the file
111 * does not support properties.
112 */
113 public String getProperty(String propertyName);
114
115 /***
116 * Set a property on a file. This method can fail silently if the file does
117 * not support properties. If the property exists, its contents will be
118 * overwritten.
119 *
120 * @param propertyName
121 * the name of the property.
122 * @param propertyContents
123 * the contents of the property.
124 */
125 public void setProperty(String propertyName, String propertyContents);
126 }