VFS.java

Index Score
org.gjt.sp.jedit.io
jEdit

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
DECL_COMMENTSComments in declarations
DOC_COMMENTNumber of javadoc comment lines
PARAMSNumber of formal parameter declarations
JAVA0173JAVA0173 Unused method parameter
COMMENTSComment lines
LINE_COMMENTNumber of line comments
JAVA0034JAVA0034 Missing braces in if statement
INTERFACE_COMPLEXITYInterface complexity
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
SIZESize of the file in bytes
LINESNumber of lines in the source file
JAVA0160JAVA0160 Method does not throw specified exception
RETURNSNumber of return points from functions
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0018JAVA0018 Method name does not have required form
LOCLines of code
CYCLOMATICCyclomatic complexity
ELOCEffective lines of code
FUNCTIONSNumber of function declarations
OPERANDSNumber of operands
EXITSProcedure exits
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
COMPARISONSNumber of comparison operators
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
BLOCKSNumber of blocks
JAVA0138JAVA0138 N parameters defined for method (maximum: M)
LOGICAL_LINESNumber of statements
JAVA0145JAVA0145 Tab character used in source file
UNIQUE_OPERATORSNumber of unique operators
JAVA0036JAVA0036 Missing braces in while statement
NEST_DEPTHMaximum nesting depth
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
/* * VFS.java - Virtual filesystem implementation * :tabSize=8:indentSize=8:noTabs=false: * :folding=explicit:collapseFolds=1: * * Copyright (C) 2000, 2003 Slava Pestov * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ package org.gjt.sp.jedit.io; //{{{ Imports import java.awt.Color; import java.awt.Component; import java.io.*; import java.util.*; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import org.gjt.sp.jedit.msg.PropertiesChanged; import org.gjt.sp.jedit.*; import org.gjt.sp.jedit.bufferio.BufferLoadRequest; import org.gjt.sp.jedit.bufferio.BufferSaveRequest; import org.gjt.sp.jedit.bufferio.BufferInsertRequest; import org.gjt.sp.jedit.bufferio.BufferIORequest; import org.gjt.sp.util.Log; import org.gjt.sp.util.ProgressObserver; import org.gjt.sp.util.IOUtilities; import org.gjt.sp.util.StandardUtilities; import org.gjt.sp.util.WorkThread; //}}} /** * A virtual filesystem implementation.<p> * * Plugins can provide virtual file systems by defining entries in their * <code>services.xml</code> files like so: * * <pre>&lt;SERVICE CLASS="org.gjt.sp.jedit.io.VFS" NAME="<i>name</i>"&gt; * new <i>MyVFS</i>(); *&lt;/SERVICE&gt;</pre> * * URLs of the form <code><i>name</i>:<i>path</i></code> will then be handled * by the VFS named <code><i>name</i></code>.<p> * * See {@link org.gjt.sp.jedit.ServiceManager} for details.<p> * * <h3>Session objects:</h3> * * 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.<p> * * Methods whose names are prefixed with "_" expect to be given a * previously-obtained session object. A session must be obtained from the AWT * thread in one of two ways: * * <ul> * <li>{@link #createVFSSession(String,Component)}</li> * <li>{@link #showBrowseDialog(Object[],Component)}</li> * </ul> * * When done, the session must be disposed of using * {@link #_endVFSSession(Object,Component)}.<p> * * <h3>Thread safety:</h3> * * The following methods cannot be called from an I/O thread: * * <ul> * <li>{@link #createVFSSession(String,Component)}</li> * <li>{@link #insert(View,Buffer,String)}</li> * <li>{@link #load(View,Buffer,String)}</li> * <li>{@link #save(View,Buffer,String)}</li> * <li>{@link #showBrowseDialog(Object[],Component)}</li> * </ul> * * All remaining methods are required to be thread-safe in subclasses. * * <h3>Implementing a VFS</h3> * * You can override as many or as few methods as you want. Make sure * {@link #getCapabilities()} returns a value reflecting the functionality * implemented by your VFS. * * @see VFSManager#getVFSForPath(String) * @see VFSManager#getVFSForProtocol(String) * * @author Slava Pestov * @author $Id: VFS.java 12964 2008-06-29 01:44:01Z vanza $ */ public abstract class VFS { //{{{ Capabilities /** * Read capability. * @since jEdit 2.6pre2 */ public static final int READ_CAP = 1 << 0; /** * Write capability. * @since jEdit 2.6pre2 */ public static final int WRITE_CAP = 1 << 1; /** * Browse capability * @since jEdit 4.3pre11 * * This was the official API for adding items to a file * system browser's <b>Plugins</b> menu in jEdit 4.1 and earlier. In * jEdit 4.2, there is a different way of doing this, you must provide * a <code>browser.actions.xml</code> file in your plugin JAR, and * define <code>plugin.<i>class</i>.browser-menu-item</code> * or <code>plugin.<i>class</i>.browser-menu</code> properties. * See {@link org.gjt.sp.jedit.EditPlugin} for details. */ public static final int BROWSE_CAP = 1 << 2; /** * Delete file capability. * @since jEdit 2.6pre2 */ public static final int DELETE_CAP = 1 << 3; /** * Rename file capability. * @since jEdit 2.6pre2 */ public static final int RENAME_CAP = 1 << 4; /** * Make directory capability. * @since jEdit 2.6pre2 */ public static final int MKDIR_CAP = 1 << 5; /** * Low 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 */ public static final int LOW_LATENCY_CAP = 1 << 6; /** * Case insensitive file system capability. * @since jEdit 4.1pre1 */ public static final int CASE_INSENSITIVE_CAP = 1 << 7; //}}} //{{{ Extended attributes /** * File type. * @since jEdit 4.2pre1 */ public static final String EA_TYPE = "type"; /** * File status (read only, read write, etc). * @since jEdit 4.2pre1 */ public static final String EA_STATUS = "status"; /** * File size. * @since jEdit 4.2pre1 */ public static final String EA_SIZE = "size"; /** * File last modified date. * @since jEdit 4.2pre1 */ public static final String EA_MODIFIED = "modified"; //}}} public static int IOBUFSIZE = 32678; //{{{ VFS constructors /** * @deprecated Use the form where the constructor takes a capability * list. */ @Deprecated protected VFS(String name) { this(name,0); } /** * Creates a new virtual filesystem. * @param name The name * @param caps The capabilities */ protected VFS(String name, int caps) { this.name = name; this.caps = caps; // reasonable defaults (?) this.extAttrs = new String[] { EA_SIZE, EA_TYPE }; } /** * Creates a new virtual filesystem. * @param name The name * @param caps The capabilities * @param extAttrs The extended attributes * @since jEdit 4.2pre1 */ protected VFS(String name, int caps, String[] extAttrs) { this.name = name; this.caps = caps; this.extAttrs = extAttrs; } //}}} //{{{ getName() method /** * Returns this VFS's name. The name is used to obtain the * label stored in the <code>vfs.<i>name</i>.label</code> * property. */ public String getName() { return name; } //}}} //{{{ getCapabilities() method /** * Returns the capabilities of this VFS. * @since jEdit 2.6pre2 */ public int getCapabilities() { return caps; } //}}} //{{{ isMarkersFileSupported() method /** * Returns if an additional markers file can be saved by this VFS. * Default is {@code true}. * * @since jEdit 4.3pre10 */ public boolean isMarkersFileSupported() { return true; } //}}} //{{{ getExtendedAttributes() method /** * Returns the extended attributes supported by this VFS. * @since jEdit 4.2pre1 */ public String[] getExtendedAttributes() { return extAttrs; } //}}} //{{{ showBrowseDialog() method /** * Displays a dialog box that should set up a session and return * the initial URL to browse. * @param session Where the VFS session will be stored * @param comp The component that will parent error dialog boxes * @return The URL * @since jEdit 2.7pre1 * @deprecated This function is not used in the jEdit core anymore, * so it doesn't have to be provided anymore. If you want * to use it for another purpose like in the FTP plugin, * feel free to do so. */ @Deprecated public String showBrowseDialog(Object[] session, Component comp) { return null; } //}}} //{{{ getFileName() method /** * Returns the file name component of the specified path. * @param path The path * @since jEdit 3.1pre4 */ public String getFileName(String path) { if(path.equals("/")) return path; while(path.endsWith("/") || path.endsWith(File.separator)) path = path.substring(0,path.length() - 1); int index = Math.max(path.lastIndexOf('/'), path.lastIndexOf(File.separatorChar)); if(index == -1) index = path.indexOf(':'); // don't want getFileName("roots:") to return "" if(index == -1 || index == path.length() - 1) return path; return path.substring(index + 1); } //}}} //{{{ getParentOfPath() method /** * Returns the parent of the specified path. This must be * overridden to return a non-null value for browsing of this * filesystem to work. * @param path The path * @since jEdit 2.6pre5 */ public String getParentOfPath(String path) { // ignore last character of path to properly handle // paths like /foo/bar/ int lastIndex = path.length() - 1; while(lastIndex > 0 && (path.charAt(lastIndex) == File.separatorChar || path.charAt(lastIndex) == '/')) { lastIndex--; } int count = Math.max(0,lastIndex); int index = path.lastIndexOf(File.separatorChar,count); if(index == -1) index = path.lastIndexOf('/',count); if(index == -1) { // this ensures that getFileParent("protocol:"), for // example, is "protocol:" and not "". index = path.lastIndexOf(':'); } return path.substring(0,index + 1); } //}}} //{{{ constructPath() method /** * 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.<p> * * Unless you are writing a VFS, this method should not be called * directly. To ensure correct behavior, you <b>must</b> call * {@link org.gjt.sp.jedit.MiscUtilities#constructPath(String,String)} * instead. * * @param parent The parent directory * @param path The path * @since jEdit 2.6pre2 */ public String constructPath(String parent, String path) { return parent + path; } //}}} //{{{ getFileSeparator() method /** * Returns the file separator used by this VFS. * @since jEdit 2.6pre9 */ public char getFileSeparator() { return '/'; } //}}} //{{{ getTwoStageSaveName() method /** * Returns a temporary file name based on the given path. * * By default jEdit first saves a file to <code>#<i>name</i>#save#</code> * and then renames it to the original file. However some virtual file * systems might not support the <code>#</code> character in filenames, * so this method permits the VFS to override this behavior. * * If this method returns <code>null</code>, two stage save will not * be used for that particular file (introduced in jEdit 4.3pre1). * * @param path The path name * @since jEdit 4.1pre7 */ public String getTwoStageSaveName(String path) { return MiscUtilities.constructPath(getParentOfPath(path), '#' + getFileName(path) + "#save#"); } //}}} //{{{ reloadDirectory() method /** * Called before a directory is reloaded by the file system browser. * Can be used to flush a cache, etc. * @since jEdit 4.0pre3 */ public void reloadDirectory(String path) {} //}}} //{{{ createVFSSession() method /** * 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. * @param path The path in question * @param comp The component that will parent any dialog boxes shown * @return The session. The session can be null if there were errors * @since jEdit 2.6pre3 */ public Object createVFSSession(String path, Component comp) { return new Object(); } //}}} //{{{ load() method /** * Loads the specified buffer. The default implementation posts * an I/O request to the I/O thread. * @param view The view * @param buffer The buffer * @param path The path */ public boolean load(View view, Buffer buffer, String path) { if((getCapabilities() & READ_CAP) == 0) { VFSManager.error(view,path,"vfs.not-supported.load",new String[] { name }); return false; } Object session = createVFSSession(path,view); if(session == null) return false; if((getCapabilities() & WRITE_CAP) == 0) buffer.setReadOnly(true); BufferIORequest request = new BufferLoadRequest( view,buffer,session,this,path); if(buffer.isTemporary()) // this makes HyperSearch much faster request.run(); else VFSManager.runInWorkThread(request); return true; } //}}} //{{{ save() method /** * Saves the specifies buffer. The default implementation posts * an I/O request to the I/O thread. * @param view The view * @param buffer The buffer * @param path The path */ public boolean save(View view, Buffer buffer, String path) { if((getCapabilities() & WRITE_CAP) == 0) { VFSManager.error(view,path,"vfs.not-supported.save",new String[] { name }); return false; } Object session = createVFSSession(path,view); if(session == null) return false; /* When doing a 'save as', the path to save to (path) * will not be the same as the buffer's previous path * (buffer.getPath()). In that case, we want to create * a backup of the new path, even if the old path was * backed up as well (BACKED_UP property set) */ if(!path.equals(buffer.getPath())) buffer.unsetProperty(Buffer.BACKED_UP); VFSManager.runInWorkThread(new BufferSaveRequest( view,buffer,session,this,path)); return true; } //}}} //{{{ copy() methods /** * Copy a file to another using VFS. * * @param 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 WorkThread * @param sourceVFS the source VFS * @param sourceSession the VFS session * @param sourcePath the source path * @param targetVFS the target VFS * @param targetSession the target session * @param targetPath the target path * @param comp comp The component that will parent error dialog boxes * @param canStop could this copy be stopped ? * @return true if the copy was successful * @throws IOException IOException If an I/O error occurs * @since jEdit 4.3pre3 */ public static boolean copy(ProgressObserver progress, VFS sourceVFS, Object sourceSession,String sourcePath, VFS targetVFS, Object targetSession,String targetPath, Component comp, boolean canStop) throws IOException { if (progress != null) progress.setStatus("Initializing"); InputStream in = null; OutputStream out = null; try { VFSFile sourceVFSFile = sourceVFS._getFile(sourceSession, sourcePath, comp); if (sourceVFSFile == null) throw new FileNotFoundException(sourcePath); if (progress != null) { progress.setMaximum(sourceVFSFile.getLength()); } VFSFile targetVFSFile = targetVFS._getFile(targetSession, targetPath, comp); if (targetVFSFile.getType() == VFSFile.DIRECTORY) { if (targetVFSFile.getPath().equals(sourceVFSFile.getPath())) return false; targetPath = MiscUtilities.constructPath(targetPath, sourceVFSFile.getName()); } in = new BufferedInputStream(sourceVFS._createInputStream(sourceSession, sourcePath, false, comp)); out = new BufferedOutputStream(targetVFS._createOutputStream(targetSession, targetPath, comp)); boolean copyResult = IOUtilities.copyStream(IOBUFSIZE, progress, in, out, canStop); VFSManager.sendVFSUpdate(targetVFS, targetPath, true); return copyResult; } finally { IOUtilities.closeQuietly(in); IOUtilities.closeQuietly(out); } } /** * Copy a file to another using VFS. * * @param 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 WorkThread * @param sourcePath the source path * @param targetPath the target path * @param comp comp The component that will parent error dialog boxes * @param canStop if true the copy can be stopped * @return true if the copy was successful * @throws IOException IOException If an I/O error occurs * @since jEdit 4.3pre3 */ public static boolean copy(ProgressObserver progress, String sourcePath,String targetPath, Component comp, boolean canStop) throws IOException { VFS sourceVFS = VFSManager.getVFSForPath(sourcePath); Object sourceSession = sourceVFS.createVFSSession(sourcePath, comp); if (sourceSession == null) { Log.log(Log.WARNING, VFS.class, "Unable to get a valid session from " + sourceVFS + " for path " + sourcePath); return false; } VFS targetVFS = VFSManager.getVFSForPath(targetPath); Object targetSession = targetVFS.createVFSSession(targetPath, comp); if (targetSession == null) { Log.log(Log.WARNING, VFS.class, "Unable to get a valid session from " + targetVFS + " for path " + targetPath); return false; } return copy(progress, sourceVFS, sourceSession, sourcePath, targetVFS, targetSession, targetPath, comp,canStop); } //}}} //{{{ insert() method /** * Inserts a file into the specified buffer. The default implementation * posts an I/O request to the I/O thread. * @param view The view * @param buffer The buffer * @param path The path */ public boolean insert(View view, Buffer buffer, String path) { if((getCapabilities() & READ_CAP) == 0) { VFSManager.error(view,path,"vfs.not-supported.load",new String[] { name }); return false; } Object session = createVFSSession(path,view); if(session == null) return false; VFSManager.runInWorkThread(new BufferInsertRequest( view,buffer,session,this,path)); return true; } //}}} // A method name that starts with _ requires a session object //{{{ _canonPath() method /** * Returns the canonical form of the specified path name. For example, * <code>~</code> might be expanded to the user's home directory. * @param session The session * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @since jEdit 4.0pre2 */ public String _canonPath(Object session, String path, Component comp) throws IOException { return path; } //}}} //{{{ _listDirectory() method /** * A convinience method that matches file names against globs, and can * optionally list the directory recursively. * @param session The session * @param directory 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. * @param glob Only file names matching this glob will be returned * @param recursive If true, subdirectories will also be listed. * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @since jEdit 4.1pre1 */ public String[] _listDirectory(Object session, String directory, String glob, boolean recursive, Component comp ) throws IOException { String[] retval = _listDirectory(session, directory, glob, recursive, comp, true, false); return retval; } //}}} //{{{ _listDirectory() method /** * A convinience method that matches file names against globs, and can * optionally list the directory recursively. * @param session The session * @param directory 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. * @param glob Only file names matching this glob will be returned * @param recursive If true, subdirectories will also be listed. * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @param skipBinary ignore binary files (do not return them). * This will slow down the process since it will open the files * @param skipHidden skips hidden files, directories, and * backup files. Ignores any file beginning with . or #, or ending with ~ * or .bak * * * @since jEdit 4.3pre5 */ public String[] _listDirectory(Object session, String directory, String glob, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) throws IOException { VFSFileFilter filter = new GlobVFSFileFilter(glob); return _listDirectory(session, directory, filter, recursive, comp, skipBinary, skipHidden); } //}}} //{{{ _listDirectory() method /** * A convinience method that filters the directory listing * according to a filter, and can optionally list the directory * recursively. * @param session The session * @param directory 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. * @param filter The {@link VFSFileFilter} to use for filtering. * @param recursive If true, subdirectories will also be listed. * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @param skipBinary ignore binary files (do not return them). * This will slow down the process since it will open the files * @param skipHidden skips hidden files, directories, and * backup files. Ignores any file beginning with . or #, or ending with ~ * or .bak * * @since jEdit 4.3pre7 */ public String[] _listDirectory(Object session, String directory, VFSFileFilter filter, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) throws IOException { Log.log(Log.DEBUG,this,"Listing " + directory); List<String> files = new ArrayList<String>(100); listFiles(session,new HashSet<String>(), files,directory,filter, recursive, comp, skipBinary, skipHidden); String[] retVal = files.toArray(new String[files.size()]); Arrays.sort(retVal,new StandardUtilities.StringCompare(true)); return retVal; } //}}} //{{{ _listFiles() method /** * Lists the specified directory. * @param session The session * @param directory 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. * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @since jEdit 4.3pre2 */ public VFSFile[] _listFiles(Object session, String directory, Component comp) throws IOException { return _listDirectory(session,directory,comp); } //}}} //{{{ _listDirectory() method /** * @deprecated Use <code>_listFiles()</code> instead. */ @Deprecated public DirectoryEntry[] _listDirectory(Object session, String directory, Component comp) throws IOException { VFSManager.error(comp,directory,"vfs.not-supported.list",new String[] { name }); return null; } //}}} //{{{ _getFile() method /** * Returns the specified directory entry. * @param session The session get it with {@link VFS#createVFSSession(String, Component)} * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @return The specified directory entry, or null if it doesn't exist. * @since jEdit 4.3pre2 */ public VFSFile _getFile(Object session, String path, Component comp) throws IOException { return _getDirectoryEntry(session,path,comp); } //}}} //{{{ _getDirectoryEntry() method /** * Returns the specified directory entry. * @param session The session get it with {@link VFS#createVFSSession(String, Component)} * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @return The specified directory entry, or null if it doesn't exist. * @since jEdit 2.7pre1 * @deprecated Use <code>_getFile()</code> instead. */ @Deprecated public DirectoryEntry _getDirectoryEntry(Object session, String path, Component comp) throws IOException { return null; } //}}} //{{{ DirectoryEntry class /** * @deprecated Use <code>VFSFile</code> instead. */ @Deprecated public static class DirectoryEntry extends VFSFile { //{{{ DirectoryEntry constructor /** * @since jEdit 4.2pre2 */ public DirectoryEntry() { } //}}} //{{{ DirectoryEntry constructor public DirectoryEntry(String name, String path, String deletePath, int type, long length, boolean hidden) { this.name = name; this.path = path; this.deletePath = deletePath; this.symlinkPath = path; this.type = type; this.length = length; this.hidden = hidden; if(path != null) { // maintain backwards compatibility VFS vfs = VFSManager.getVFSForPath(path); canRead = ((vfs.getCapabilities() & READ_CAP) != 0); canWrite = ((vfs.getCapabilities() & WRITE_CAP) != 0); } } //}}} } //}}} //{{{ _delete() method /** * Deletes the specified URL. * @param session The VFS session * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurs * @since jEdit 2.7pre1 */ public boolean _delete(Object session, String path, Component comp) throws IOException { return false; } //}}} //{{{ _rename() method /** * Renames the specified URL. Some filesystems might support moving * URLs between directories, however others may not. Do not rely on * this behavior. * @param session The VFS session * @param from The old path * @param to The new path * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurs * @since jEdit 2.7pre1 */ public boolean _rename(Object session, String from, String to, Component comp) throws IOException { return false; } //}}} //{{{ _mkdir() method /** * Creates a new directory with the specified URL. * @param session The VFS session * @param directory The directory * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurs * @since jEdit 2.7pre1 */ public boolean _mkdir(Object session, String directory, Component comp) throws IOException { return false; } //}}} //{{{ _backup() method /** * Backs up the specified file. This should only be overriden by * the local filesystem VFS. * @param session The VFS session * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurs * @since jEdit 3.2pre2 */ public void _backup(Object session, String path, Component comp) throws IOException { } //}}} //{{{ _createInputStream() method /** * Creates an input stream. This method is called from the I/O * thread. * @param session the VFS session * @param path The path * @param ignoreErrors If true, file not found errors should be * ignored * @param comp The component that will parent error dialog boxes * @return an inputstream or <code>null</code> if there was a problem * @exception IOException If an I/O error occurs * @since jEdit 2.7pre1 */ public InputStream _createInputStream(Object session, String path, boolean ignoreErrors, Component comp) throws IOException { VFSManager.error(comp,path,"vfs.not-supported.load",new String[] { name }); return null; } //}}} //{{{ _createOutputStream() method /** * Creates an output stream. This method is called from the I/O * thread. * @param session the VFS session * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException If an I/O error occurs * @since jEdit 2.7pre1 */ public OutputStream _createOutputStream(Object session, String path, Component comp) throws IOException { VFSManager.error(comp,path,"vfs.not-supported.save",new String[] { name }); return null; } //}}} //{{{ _saveComplete() method /** * Called after a file has been saved. * @param session The VFS session * @param buffer The buffer * @param path The path the buffer was saved to (can be different from * {@link org.gjt.sp.jedit.Buffer#getPath()} if the user invoked the * <b>Save a Copy As</b> command, for example). * @param comp The component that will parent error dialog boxes * @exception IOException If an I/O error occurs * @since jEdit 4.1pre9 */ public void _saveComplete(Object session, Buffer buffer, String path, Component comp) throws IOException {} //}}} //{{{ _finishTwoStageSave() method /** * Called after a file has been saved and we use twoStageSave (first saving to * another file). This should re-apply permissions for example. * @param session The VFS session * @param buffer The buffer * @param path The path the buffer was saved to (can be different from * {@link org.gjt.sp.jedit.Buffer#getPath()} if the user invoked the * <b>Save a Copy As</b> command, for example). * @param comp The component that will parent error dialog boxes * @exception IOException If an I/O error occurs * @since jEdit 4.3pre4 */ public void _finishTwoStageSave(Object session, Buffer buffer, String path, Component comp) throws IOException { } //}}} //{{{ _endVFSSession() method /** * 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. * @param session The VFS session * @param comp The component that will parent error dialog boxes * @exception IOException if an I/O error occurred * @since jEdit 2.7pre1 */ public void _endVFSSession(Object session, Component comp) throws IOException { } //}}} //{{{ getDefaultColorFor() method /** * Returns color of the specified file name, by matching it against * user-specified regular expressions. * @since jEdit 4.0pre1 */ public static Color getDefaultColorFor(String name) { synchronized(lock) { if(colors == null) loadColors(); for(int i = 0; i < colors.size(); i++) { ColorEntry entry = colors.get(i); if(entry.re.matcher(name).matches()) return entry.color; } return null; } } //}}} //{{{ DirectoryEntryCompare class /** * Implementation of {@link Comparator} * interface that compares {@link VFS.DirectoryEntry} instances. * @since jEdit 4.2pre1 */ public static class DirectoryEntryCompare implements Comparator<VFSFile> { private boolean sortIgnoreCase, sortMixFilesAndDirs; /** * Creates a new <code>DirectoryEntryCompare</code>. * @param sortMixFilesAndDirs If false, directories are * put at the top of the listing. * @param sortIgnoreCase If false, upper case comes before * lower case. */ public DirectoryEntryCompare(boolean sortMixFilesAndDirs, boolean sortIgnoreCase) { this.sortMixFilesAndDirs = sortMixFilesAndDirs; this.sortIgnoreCase = sortIgnoreCase; } public int compare(VFSFile file1, VFSFile file2) { if(!sortMixFilesAndDirs) { if(file1.getType() != file2.getType()) return file2.getType() - file1.getType(); } return StandardUtilities.compareStrings(file1.getName(), file2.getName(),sortIgnoreCase); } } //}}} //{{{ Private members private String name; private int caps; private String[] extAttrs; private static List<ColorEntry> colors; private static final Object lock = new Object(); //{{{ Class initializer static { EditBus.addToBus(new EBComponent() { public void handleMessage(EBMessage msg) { if(msg instanceof PropertiesChanged) { synchronized(lock) { colors = null; } } } }); } //}}} //{{{ recursive listFiles() method private void listFiles(Object session, Collection<String> stack, List<String> files, String directory, VFSFileFilter filter, boolean recursive, Component comp, boolean skipBinary, boolean skipHidden) throws IOException { String resolvedPath = directory; if (recursive && !MiscUtilities.isURL(directory)) { // resolve symlinks to avoid loops resolvedPath = MiscUtilities.resolveSymlinks(directory); } if(stack.contains(resolvedPath)) { Log.log(Log.ERROR,this, "Recursion in _listDirectory(): " + directory); return; } stack.add(resolvedPath); Thread ct = Thread.currentThread(); WorkThread wt = null; if (ct instanceof WorkThread) { wt = (WorkThread) ct; } VFSFile[] _files = _listFiles(session,directory, comp); if(_files == null || _files.length == 0) return; for(int i = 0; i < _files.length; i++) { if (wt != null && wt.isAborted()) break; VFSFile file = _files[i]; if (skipHidden && (file.isHidden() || MiscUtilities.isBackup(file.getName()))) continue; if(!filter.accept(file)) continue; if(file.getType() == VFSFile.DIRECTORY || file.getType() == VFSFile.FILESYSTEM) { if(recursive) { String canonPath = _canonPath(session, file.getPath(),comp); listFiles(session,stack,files, canonPath,filter,recursive, comp, skipBinary, skipHidden); } } else // It's a regular file { if (skipBinary) { try { if (file.isBinary(session)) { Log.log(Log.NOTICE,this ,file.getPath() + ": skipped as a binary file"); continue; } } catch(IOException e) { Log.log(Log.ERROR,this,e); // may be not binary... } } Log.log(Log.DEBUG,this,file.getPath()); files.add(file.getPath()); } } } //}}} //{{{ loadColors() method private static void loadColors() { synchronized(lock) { colors = new ArrayList<ColorEntry>(); if(!jEdit.getBooleanProperty("vfs.browser.colorize")) return; String glob; int i = 0; while((glob = jEdit.getProperty("vfs.browser.colors." + i + ".glob")) != null) { try { colors.add(new ColorEntry( Pattern.compile(StandardUtilities.globToRE(glob)), jEdit.getColorProperty( "vfs.browser.colors." + i + ".color", Color.black))); } catch(PatternSyntaxException e) { Log.log(Log.ERROR,VFS.class,"Invalid regular expression: " + glob); Log.log(Log.ERROR,VFS.class,e); } i++; } } } //}}} //{{{ ColorEntry class private static class ColorEntry { Pattern re; Color color; ColorEntry(Pattern re, Color color) { this.re = re; this.color = color; } } //}}} //}}} }

The table below shows all metrics for VFS.java.

MetricValueDescription
BLOCKS79.00Number of blocks
BLOCK_COMMENT26.00Number of block comment lines
COMMENTS572.00Comment lines
COMMENT_DENSITY 1.43Comment density
COMPARISONS62.00Number of comparison operators
CYCLOMATIC102.00Cyclomatic complexity
DECL_COMMENTS108.00Comments in declarations
DOC_COMMENT484.00Number of javadoc comment lines
ELOC400.00Effective lines of code
EXEC_COMMENTS 9.00Comments in executable code
EXITS72.00Procedure exits
FUNCTIONS46.00Number of function declarations
HALSTEAD_DIFFICULTY86.38Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY203.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 1.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 1.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 1.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA001817.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003422.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 1.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 1.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 1.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 1.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 0.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 6.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA011023.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 1.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 1.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 1.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 5.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 0.00JAVA0144 Line exceeds maximum M characters
JAVA01451668.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA016012.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA017337.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 1.00JAVA0176 Local variable name does not have required form
JAVA0177 1.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 1.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 0.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 1.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 1.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 1.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1197.00Number of lines in the source file
LINE_COMMENT62.00Number of line comments
LOC521.00Lines of code
LOGICAL_LINES193.00Number of statements
LOOPS 5.00Number of loops
NEST_DEPTH 6.00Maximum nesting depth
OPERANDS1146.00Number of operands
OPERATORS1958.00Number of operators
PARAMS126.00Number of formal parameter declarations
PROGRAM_LENGTH3104.00Halstead program length
PROGRAM_VOCAB458.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS77.00Number of return points from functions
SIZE34651.00Size of the file in bytes
UNIQUE_OPERANDS398.00Number of unique operands
UNIQUE_OPERATORS60.00Number of unique operators
WHITESPACE104.00Number of whitespace lines