View Javadoc

1   package net.sourceforge.blogentis.storage;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: AbstractFileResource.java,v 1.1 2004/10/22 17:34:11 tassos Exp $
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 }