- Direct Known Subclasses:
FavoritesVFS
,FileRootsVFS
,FileVFS
,UrlVFS
,VFSAdapter
Plugins can provide virtual file systems by defining entries in their
services.xml
files like so:
<SERVICE CLASS="org.gjt.sp.jedit.io.VFS" NAME="name"> new MyVFS(); </SERVICE>URLs of the form
name:path
will then be handled
by the VFS named name
.
See ServiceManager
for details.
Session objects:
A session is used to persist things like login information, any network sockets, etc. File system implementations that do not need this kind of persistence return a dummy object as a session.Methods whose names are prefixed with "_" expect to be given a previously-obtained session object. A session must be obtained with this method:
That method should be called from the AWT (EDT) thread, unless the filesystem hasNON_AWT_SESSION_CAP
capability.
When done, the session must be disposed of using
_endVFSSession(Object,Component)
.
Thread safety:
The following methods cannot be called from an I/O thread:createVFSSession(String,Component)
- unlessNON_AWT_SESSION_CAP
capability is setinsert(View,Buffer,String)
load(View,Buffer,String,boolean)
save(View,Buffer,String)
Implementing a VFS
You can override as many or as few methods as you want. Make suregetCapabilities()
returns a value reflecting the functionality
implemented by your VFS.- Author:
- Slava Pestov, $Id: VFS.java 25330 2020-05-09 14:21:52Z kpouer $
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Implementation ofComparator
interface that comparesVFSFile
instances. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Browse capabilitystatic final int
Case insensitive file system capability.static final int
Delete file capability.static final String
File last modified date.static final String
File size.static final String
File status (read only, read write, etc).static final String
File type.static final int
static final int
Low latency capability.static final int
Make directory capability.static final int
Sessions created outside Event Dispatching Thread - file system capability.static final int
Read capability.static final int
Rename file capability.static final int
Write capability. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Backs up the specified file._canonPath
(Object session, String path, Component comp) Returns the canonical form of the specified path name._createInputStream
(Object session, String path, boolean ignoreErrors, Component comp) Creates an input stream._createOutputStream
(Object session, String path, Component comp) Creates an output stream.boolean
Deletes the specified URL.void
_endVFSSession
(Object session, Component comp) Finishes the specified VFS session.void
_finishTwoStageSave
(Object session, Buffer buffer, String path, Component comp) Called after a file has been saved and we use twoStageSave (first saving to another file).Returns the specified directory entry.String[]
_listDirectory
(Object session, String directory, String glob, boolean recursive, Component comp) A convenience method that matches file names against globs, and can optionally list the directory recursively.String[]
_listDirectory
(Object session, String directory, String glob, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) A convenience method that matches file names against globs, and can optionally list the directory recursively.String[]
_listDirectory
(Object session, String directory, VFSFileFilter filter, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) A convenience method that filters the directory listing according to a filter, and can optionally list the directory recursively.VFSFile[]
_listFiles
(Object session, String directory, Component comp) Lists the specified directory.boolean
Creates a new directory with the specified URL.boolean
Renames the specified URL.void
_saveComplete
(Object session, Buffer buffer, String path, Component comp) Called after a file has been saved.constructPath
(String parent, String path) Constructs a path from the specified directory and file name component.static boolean
copy
(ProgressObserver progress, String sourcePath, String targetPath, Component comp, boolean canStop) Copy a file to another using VFS.static boolean
copy
(ProgressObserver progress, String sourcePath, String targetPath, Component comp, boolean canStop, boolean sendVFSUpdate) Copy a file to another using VFS.static boolean
copy
(ProgressObserver progress, VFS sourceVFS, Object sourceSession, String sourcePath, VFS targetVFS, Object targetSession, String targetPath, Component comp, boolean canStop) Copy a file to another using VFS.static boolean
copy
(ProgressObserver progress, VFS sourceVFS, Object sourceSession, String sourcePath, VFS targetVFS, Object targetSession, String targetPath, Component comp, boolean canStop, boolean sendVFSUpdate) Copy a file to another using VFS.createVFSSession
(String path, Component comp) Creates a VFS session.createVFSSessionSafe
(String path, Component comp) Same ascreateVFSSession(java.lang.String, java.awt.Component)
, but may be called from any thread.int
Returns the capabilities of this VFS.static Color
getDefaultColorFor
(String name) Returns color of the specified file name, by matching it against user-specified regular expressions.getDefaultEncoding
(String path) String[]
Returns the extended attributes supported by this VFS.getFileName
(String path) Returns the file name component of the specified path.getFilePath
(String vfsPath) Returns the path component of the specified VFS path.char
Returns the file separator used by this VFS.getName()
Returns this VFS's name.getParentOfPath
(String path) Returns the parent of the specified path.getTwoStageSaveName
(String path) Returns a temporary file name based on the given path.boolean
Inserts a file into the specified buffer.boolean
Returns if an additional markers file can be saved by this VFS.boolean
Loads the specified buffer.void
reloadDirectory
(String path) Called before a directory is reloaded by the file system browser.boolean
Saves the specifies buffer.void
setEncoding
(String path, String encoding)
-
Field Details
-
READ_CAP
public static final int READ_CAPRead capability.- Since:
- jEdit 2.6pre2
- See Also:
-
WRITE_CAP
public static final int WRITE_CAPWrite capability.- Since:
- jEdit 2.6pre2
- See Also:
-
BROWSE_CAP
public static final int BROWSE_CAPBrowse capability- Since:
- jEdit 4.3pre11
This was the official API for adding items to a file
system browser's Plugins menu in jEdit 4.1 and earlier. In
jEdit 4.2, there is a different way of doing this, you must provide
a
browser.actions.xml
file in your plugin JAR, and defineplugin.class.browser-menu-item
orplugin.class.browser-menu
properties. SeeEditPlugin
for details. - See Also:
-
DELETE_CAP
public static final int DELETE_CAPDelete file capability.- Since:
- jEdit 2.6pre2
- See Also:
-
RENAME_CAP
public static final int RENAME_CAPRename file capability.- Since:
- jEdit 2.6pre2
- See Also:
-
MKDIR_CAP
public static final int MKDIR_CAPMake directory capability.- Since:
- jEdit 2.6pre2
- See Also:
-
LOW_LATENCY_CAP
public static final int LOW_LATENCY_CAPLow latency capability. If this is not set, then a confirm dialog will be shown before doing a directory search in this VFS.- Since:
- jEdit 4.1pre1
- See Also:
-
CASE_INSENSITIVE_CAP
public static final int CASE_INSENSITIVE_CAPCase insensitive file system capability.- Since:
- jEdit 4.1pre1
- See Also:
-
NON_AWT_SESSION_CAP
public static final int NON_AWT_SESSION_CAPSessions created outside Event Dispatching Thread - file system capability. Set for the file system that does not require thatcreateVFSSession
is called on edt. All systems that do not implementcreateVFSSession
should set it, but others may too.- Since:
- jEdit 5.0pre1
- See Also:
-
EA_TYPE
File type.- Since:
- jEdit 4.2pre1
- See Also:
-
EA_STATUS
File status (read only, read write, etc).- Since:
- jEdit 4.2pre1
- See Also:
-
EA_SIZE
File size.- Since:
- jEdit 4.2pre1
- See Also:
-
EA_MODIFIED
File last modified date.- Since:
- jEdit 4.2pre1
- See Also:
-
IOBUFSIZE
public static final int IOBUFSIZE- See Also:
-
-
Constructor Details
-
VFS
Creates a new virtual filesystem.- Parameters:
name
- The namecaps
- The capabilities
-
VFS
Creates a new virtual filesystem.- Parameters:
name
- The namecaps
- The capabilitiesextAttrs
- The extended attributes- Since:
- jEdit 4.2pre1
-
-
Method Details
-
getName
Returns this VFS's name. The name is used to obtain the label stored in thevfs.name.label
property. -
getCapabilities
public int getCapabilities()Returns the capabilities of this VFS.- Since:
- jEdit 2.6pre2
-
isMarkersFileSupported
public boolean isMarkersFileSupported()Returns if an additional markers file can be saved by this VFS. Default istrue
.- Since:
- jEdit 4.3pre10
-
getExtendedAttributes
Returns the extended attributes supported by this VFS.- Since:
- jEdit 4.2pre1
-
getFileName
Returns the file name component of the specified path.- Parameters:
path
- The path- Since:
- jEdit 3.1pre4
-
getFilePath
Returns the path component of the specified VFS path. The standard implementation cuts off the protocol and the protocol separator character and then delegates to eventually present sub-VFS-paths present in the VFS path like "jode:archive:/test.zip!/test.txt".If a VFS implementation can have additional information in the VFS path like username / password / host / port for FTP VFS or archive filename for archive VFS, this method should be overridden to remove those information also. The easiest would be to remove those additional information and then delegate to
super.getFilePath()
.- Parameters:
vfsPath
- The VFS path- Since:
- jEdit 4.5pre1
-
getParentOfPath
Returns the parent of the specified path. This must be overridden to return a non-null value for browsing of this filesystem to work.- Parameters:
path
- The path- Since:
- jEdit 2.6pre5
-
constructPath
Constructs a path from the specified directory and file name component. This must be overridden to return a non-null value, otherwise browsing this filesystem will not work.Unless you are writing a VFS, this method should not be called directly. To ensure correct behavior, you must call
MiscUtilities.constructPath(String,String)
instead.- Parameters:
parent
- The parent directorypath
- The path- Since:
- jEdit 2.6pre2
-
getFileSeparator
public char getFileSeparator()Returns the file separator used by this VFS.- Since:
- jEdit 2.6pre9
-
getTwoStageSaveName
Returns a temporary file name based on the given path. By default jEdit first saves a file to#name#save#
and then renames it to the original file. However some virtual file systems might not support the#
character in filenames, so this method permits the VFS to override this behavior. If this method returnsnull
, two stage save will not be used for that particular file (introduced in jEdit 4.3pre1).- Parameters:
path
- The path name- Since:
- jEdit 4.1pre7
-
reloadDirectory
Called before a directory is reloaded by the file system browser. Can be used to flush a cache, etc.- Since:
- jEdit 4.0pre3
-
createVFSSession
Creates a VFS session. This method is called from the AWT thread, so it should not do any I/O. It could, however, prompt for a login name and password, for example. A simpler filesystem may set theNON_AWT_SESSION_CAP
capability. When set, sessions may be obtained from any thread.- Parameters:
path
- The path in questioncomp
- The component that will parent any dialog boxes shown- Returns:
- The session. The session can be null if there were errors
- Since:
- jEdit 2.6pre3
-
createVFSSessionSafe
Same ascreateVFSSession(java.lang.String, java.awt.Component)
, but may be called from any thread. It first checks theNON_AWT_SESSION_CAP
capability and enters EDT thread if necessary. -
load
Loads the specified buffer. The default implementation posts an I/O request to the I/O thread.- Parameters:
view
- The viewbuffer
- The bufferpath
- The pathuntitled
- is the buffer untitled
-
save
Saves the specifies buffer. The default implementation posts an I/O request to the I/O thread.- Parameters:
view
- The viewbuffer
- The bufferpath
- The path
-
copy
public static boolean copy(ProgressObserver progress, VFS sourceVFS, Object sourceSession, String sourcePath, VFS targetVFS, Object targetSession, String targetPath, Component comp, boolean canStop) throws IOException Copy a file to another using VFS.- Parameters:
progress
- the progress observer. It could be null if you don't want to monitor progress. If not null you should probably launch this command in a WorkThreadsourceVFS
- the source VFSsourceSession
- the VFS sessionsourcePath
- the source path. It must be a file and must existstargetVFS
- the target VFStargetSession
- the target sessiontargetPath
- the target path. If it is a path, it must exists, if it is a file, the parent must existscomp
- The component that will parent error dialog boxescanStop
- could this copy be stopped ?- Returns:
- true if the copy was successful
- Throws:
IOException
- IOException If an I/O error occurs- Since:
- jEdit 4.3pre3
-
copy
public static boolean copy(ProgressObserver progress, VFS sourceVFS, Object sourceSession, String sourcePath, VFS targetVFS, Object targetSession, String targetPath, Component comp, boolean canStop, boolean sendVFSUpdate) throws IOException Copy a file to another using VFS.- Parameters:
progress
- the progress observer. It could be null if you don't want to monitor progress. If not null you should probably launch this command in a WorkThreadsourceVFS
- the source VFSsourceSession
- the VFS sessionsourcePath
- the source path. It must be a file and must existstargetVFS
- the target VFStargetSession
- the target sessiontargetPath
- the target path. If it is a path, it must exists, if it is a file, the parent must existscomp
- The component that will parent error dialog boxescanStop
- could this copy be stopped ?sendVFSUpdate
- true if you want to send a VFS update after the copy. False otherwise (if you do a lot of copy)- Returns:
- true if the copy was successful
- Throws:
IOException
- IOException If an I/O error occurs- Since:
- jEdit 5.0
-
copy
public static boolean copy(ProgressObserver progress, String sourcePath, String targetPath, Component comp, boolean canStop, boolean sendVFSUpdate) throws IOException Copy a file to another using VFS.- Parameters:
progress
- the progress observer. It could be null if you don't want to monitor progress. If not null you should probably launch this command in a WorkThreadsourcePath
- the source pathtargetPath
- the target pathcomp
- The component that will parent error dialog boxescanStop
- if true the copy can be stoppedsendVFSUpdate
- true if you want to send a VFS update after the copy. False otherwise (if you do a lot of copy)- Returns:
- true if the copy was successful
- Throws:
IOException
- IOException If an I/O error occurs- Since:
- jEdit 5.0
-
copy
public static boolean copy(ProgressObserver progress, String sourcePath, String targetPath, Component comp, boolean canStop) throws IOException Copy a file to another using VFS.- Parameters:
progress
- the progress observer. It could be null if you don't want to monitor progress. If not null you should probably launch this command in a WorkThreadsourcePath
- the source pathtargetPath
- the target pathcomp
- The component that will parent error dialog boxescanStop
- if true the copy can be stopped- Returns:
- true if the copy was successful
- Throws:
IOException
- IOException If an I/O error occurs- Since:
- jEdit 4.3pre3
-
insert
Inserts a file into the specified buffer. The default implementation posts an I/O request to the I/O thread.- Parameters:
view
- The viewbuffer
- The bufferpath
- The path
-
_canonPath
Returns the canonical form of the specified path name. For example,~
might be expanded to the user's home directory.- Parameters:
session
- The sessionpath
- The pathcomp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 4.0pre2
-
_listDirectory
public String[] _listDirectory(Object session, String directory, String glob, boolean recursive, Component comp) throws IOException A convenience method that matches file names against globs, and can optionally list the directory recursively.- Parameters:
session
- The sessiondirectory
- The directory. Note that this must be a full URL, including the host name, path name, and so on. The username and password (if needed by the VFS) is obtained from the session instance.glob
- Only file names matching this glob will be returnedrecursive
- If true, subdirectories will also be listed.comp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 4.1pre1
-
_listDirectory
public String[] _listDirectory(Object session, String directory, String glob, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) throws IOException A convenience method that matches file names against globs, and can optionally list the directory recursively.- Parameters:
session
- The sessiondirectory
- The directory. Note that this must be a full URL, including the host name, path name, and so on. The username and password (if needed by the VFS) is obtained from the session instance.glob
- Only file names matching this glob will be returnedrecursive
- If true, subdirectories will also be listed.comp
- The component that will parent error dialog boxesskipBinary
- ignore binary files (do not return them). This will slow down the process since it will open the filesskipHidden
- skips hidden files, directories, and backup files. Ignores any file beginning with . or #, or ending with ~ or .bak- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 4.3pre5
-
_listDirectory
public String[] _listDirectory(Object session, String directory, VFSFileFilter filter, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) throws IOException A convenience method that filters the directory listing according to a filter, and can optionally list the directory recursively.- Parameters:
session
- The sessiondirectory
- The directory. Note that this must be a full URL, including the host name, path name, and so on. The username and password (if needed by the VFS) is obtained from the session instance.filter
- TheVFSFileFilter
to use for filtering.recursive
- If true, subdirectories will also be listed.comp
- The component that will parent error dialog boxesskipBinary
- ignore binary files (do not return them). This will slow down the process since it will open the filesskipHidden
- skips hidden files, directories, and backup files. Ignores any file beginning with . or #, or ending with ~ or .bak- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 4.3pre7
-
_listFiles
Lists the specified directory.- Parameters:
session
- The sessiondirectory
- The directory. Note that this must be a full URL, including the host name, path name, and so on. The username and password (if needed by the VFS) is obtained from the session instance.comp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 4.3pre2
-
_getFile
Returns the specified directory entry.- Parameters:
session
- The session get it withcreateVFSSession(String, Component)
path
- The pathcomp
- The component that will parent error dialog boxes- Returns:
- The specified directory entry, or null if it doesn't exist.
- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 4.3pre2
-
_delete
Deletes the specified URL.- Parameters:
session
- The VFS sessionpath
- The pathcomp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurs- Since:
- jEdit 2.7pre1
-
_rename
Renames the specified URL. Some filesystems might support moving URLs between directories, however others may not. Do not rely on this behavior.- Parameters:
session
- The VFS sessionfrom
- The old pathto
- The new pathcomp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurs- Since:
- jEdit 2.7pre1
-
_mkdir
Creates a new directory with the specified URL.- Parameters:
session
- The VFS sessiondirectory
- The directorycomp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurs- Since:
- jEdit 2.7pre1
-
_backup
Backs up the specified file. Default implementation in 5.0pre1 copies the file to the backup directory. Before 5.0pre1 it was empty.- Parameters:
session
- The VFS sessionpath
- The pathcomp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurs- Since:
- jEdit 3.2pre2
-
_createInputStream
public InputStream _createInputStream(Object session, String path, boolean ignoreErrors, Component comp) throws IOException Creates an input stream. This method is called from the I/O thread.- Parameters:
session
- the VFS sessionpath
- The pathignoreErrors
- If true, file not found errors should be ignoredcomp
- The component that will parent error dialog boxes- Returns:
- an inputstream or
null
if there was a problem - Throws:
IOException
- If an I/O error occurs- Since:
- jEdit 2.7pre1
-
_createOutputStream
public OutputStream _createOutputStream(Object session, String path, Component comp) throws IOException Creates an output stream. This method is called from the I/O thread.- Parameters:
session
- the VFS sessionpath
- The pathcomp
- The component that will parent error dialog boxes- Throws:
IOException
- If an I/O error occurs- Since:
- jEdit 2.7pre1
-
_saveComplete
public void _saveComplete(Object session, Buffer buffer, String path, Component comp) throws IOException Called after a file has been saved.- Parameters:
session
- The VFS sessionbuffer
- The bufferpath
- The path the buffer was saved to (can be different fromBuffer.getPath()
if the user invoked the Save a Copy As command, for example).comp
- The component that will parent error dialog boxes- Throws:
IOException
- If an I/O error occurs- Since:
- jEdit 4.1pre9
-
_finishTwoStageSave
public void _finishTwoStageSave(Object session, Buffer buffer, String path, Component comp) throws IOException Called after a file has been saved and we use twoStageSave (first saving to another file). This should re-apply permissions for example.- Parameters:
session
- The VFS sessionbuffer
- The bufferpath
- The path the buffer was saved to (can be different fromBuffer.getPath()
if the user invoked the Save a Copy As command, for example).comp
- The component that will parent error dialog boxes- Throws:
IOException
- If an I/O error occurs- Since:
- jEdit 4.3pre4
-
_endVFSSession
Finishes the specified VFS session. This must be called after all I/O with this VFS is complete, to avoid leaving stale network connections and such.- Parameters:
session
- The VFS sessioncomp
- The component that will parent error dialog boxes- Throws:
IOException
- if an I/O error occurred- Since:
- jEdit 2.7pre1
-
getDefaultColorFor
Returns color of the specified file name, by matching it against user-specified regular expressions.- Since:
- jEdit 4.0pre1
-
getDefaultEncoding
-
setEncoding
-