KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > coldcore > coloradoftp > filesystem > FileSystem


1 package com.coldcore.coloradoftp.filesystem;
2
3 import com.coldcore.coloradoftp.session.Session;
4
5 import java.nio.channels.ReadableByteChannel JavaDoc;
6 import java.nio.channels.WritableByteChannel JavaDoc;
7 import java.util.Set JavaDoc;
8
9 /**
10  * Virtual filesystem.
11  *
12  * This filesystem can be mounted to a hard drive filesystem, to a database or
13  * to any other persistence file-like storage implementation.
14  *
15  * This class usually exists in single instance. Every user-ralated method takes
16  * a user session as an argument, so the filesystem knows which user requested a
17  * file operation.
18  *
19  * Some not critical methods may be left unimplemented (throwing an exception). And it is
20  * not a mandatory that all other methods must be implemented for every parameter user
21  * may supply.
22  *
23  * This class communicates back to command processor (to submit reply in case of invalid
24  * input for example) by using FailedActionException exceptions. Command processor
25  * treats FailedActionException separatly from all other exceptions producing replies
26  * that correspond to filesystem errors.
27  *
28  *
29  * ColoradoFTP - The Open Source FTP Server (http://cftp.coldcore.com)
30  */

31 public interface FileSystem {
32
33   /** Get user current directory.
34    * @param userSession User session
35    * @return Current directory (absolute form)
36    */

37   public String JavaDoc getCurrentDirectory(Session userSession) throws FailedActionException;
38
39
40   /** Convert path to an absolute form.
41    * This method must convert user input to an absolute form and return it even if
42    * the path does not exist or user does not have permissions to it.
43    * @param path Get parent path of this path (user input - absolute or relative)
44    * @param userSession User session
45    * @return Path (absolute form)
46    */

47   public String JavaDoc toAbsolute(String JavaDoc path, Session userSession) throws FailedActionException;
48
49
50   /** Get parent path.
51    * This method must convert user input to an absolute form and return the parent path even if
52    * the path does not exist or user does not have permissions to it. If a path already is a root
53    * folder then the root folder must be returned.
54    * @param path Get parent path of this path (user input - absolute or relative)
55    * @param userSession User session
56    * @return Parent path (absolute form)
57    */

58   public String JavaDoc getParent(String JavaDoc path, Session userSession) throws FailedActionException;
59
60
61   /** Get the list of all files and folders in directory.
62    * @param dir Directory (user input - absolute or relative)
63    * @param userSession User session
64    * @return Directory listing
65    */

66   public Set JavaDoc<ListingFile> listDirectory(String JavaDoc dir, Session userSession) throws FailedActionException;
67
68
69   /** Get path object.
70    * @param path Path (user input - absolute or relative)
71    * @param userSession User session
72    * @return Path object
73    */

74   public ListingFile getPath(String JavaDoc path, Session userSession) throws FailedActionException;
75
76
77   /** Change current user directory.
78    * @param dir New directory (user input - absolute or relative)
79    * @param userSession User session
80    * @return Absolute name of a new directory
81    */

82   public String JavaDoc changeDirectory(String JavaDoc dir, Session userSession) throws FailedActionException;
83
84
85   /** Delete path.
86    * @param path Path to remove (user input - absolute or relative)
87    * @param userSession User session
88    */

89   public void deletePath(String JavaDoc path, Session userSession) throws FailedActionException;
90
91
92   /** Create a new directory.
93    * @param dir Directory to create (user input - absolute or relative)
94    * @param userSession
95    * @throws FailedActionException
96    * @return Absolute name of a new directory
97    */

98   public String JavaDoc createDirectory(String JavaDoc dir, Session userSession) throws FailedActionException;
99
100
101   /** Rename path.
102    * @param from From name (user input - absolute or relative)
103    * @param to To name (user input - absolute or relative)
104    * @return Absolute name of a new path
105    */

106   public String JavaDoc renamePath(String JavaDoc from, String JavaDoc to, Session userSession) throws FailedActionException;
107
108
109   /** Read file data.
110    * @param filename Filename (user input - absolute or relative)
111    * @param position Start reading from this position in the file
112    * @param userSession User session
113    * @return Channel mounted to file the system can read data from (will be closed by the system)
114    */

115   public ReadableByteChannel JavaDoc readFile(String JavaDoc filename, long position, Session userSession) throws FailedActionException;
116
117
118   /** Write file data.
119    * @param filename Filename (user input - absolute or relative)
120    * @param append TRUE if file must be appended, FALSE if overwritten
121    * @param userSession User session
122    * @return Channel mounted to file the system can write data into (will be closed by the system)
123    */

124   public WritableByteChannel JavaDoc saveFile(String JavaDoc filename, boolean append, Session userSession) throws FailedActionException;
125
126
127   /** Return file separator.
128    * @return File separator (may have more than 1 character)
129    */

130   public String JavaDoc getFileSeparator();
131 }
132
Popular Tags