| java.lang.Object org.gjt.sp.jedit.MiscUtilities
MiscUtilities | public class MiscUtilities (Code) | | Path name manipulation, string manipulation, and more.
The most frequently used members of this class are:
Some path name methods:
String comparison:
A
MiscUtilities.compareStrings(String,String,boolean) method that unlike
String.compareTo(), correctly recognizes and handles
embedded numbers.
This class also defines several inner classes for use with the
sorting features of the Java collections API:
For example, you might call:
Arrays.sort(myListOfStrings,
new MiscUtilities.StringICaseCompare());
author: Slava Pestov author: John Gellene (API documentation) version: $Id: MiscUtilities.java 9835 2007-06-22 10:51:33Z Vampire0 $ |
Inner Class :public interface Compare extends Comparator | |
Inner Class :public static class StringCompare implements Compare | |
Inner Class :public static class StringICaseCompare implements Comparator<Object> | |
Inner Class :public static class MenuItemCompare implements Compare | |
Method Summary | |
public static Reader | autodetect(InputStream in, Buffer buffer) Tries to detect if the stream is gzipped, and if it has an encoding
specified with an XML PI.
Parameters: in - the input stream reader that must be autodetected Parameters: buffer - a buffer. | public static String | buildToVersion(String build) Converts an internal version number (build) into a
`human-readable' form. | public static String | canonPath(String path) the canonical form of the specified path name. | public static String | charsToEntities(String str) Converts <, >, & in the string to their HTML entity
equivalents. | public static String | charsToEscapes(String str) Escapes newlines, tabs, backslashes, and quotes in the specified
string. | public static String | charsToEscapes(String str, String toEscape) Escapes the specified characters in the specified string. | public static String | classToFile(String name) Converts a class name to a file name. | public static void | closeQuietly(InputStream in) Method that will close an
InputStream ignoring it if it is null and ignoring exceptions. | public static void | closeQuietly(OutputStream out) Method that will close an
OutputStream ignoring it if it is null and ignoring exceptions. | public static int | compareStrings(String str1, String str2, boolean ignoreCase) Compares two strings.
Unlike String.compareTo(),
this method correctly recognizes and handles embedded numbers. | public static int | compareVersions(String v1, String v2) | public static String | concatPath(String parent, String path) Like
MiscUtilities.constructPath , except path will be
appended to parent even if it is absolute. | public static String | constructPath(String parent, String path) Constructs an absolute path name from a directory and another
path name. | public static String | constructPath(String parent, String path1, String path2) Constructs an absolute path name from three path components. | public static boolean | copyStream(int bufferSize, ProgressObserver progress, InputStream in, OutputStream out, boolean canStop) Copy an input stream to an output stream. | public static boolean | copyStream(ProgressObserver progress, InputStream in, OutputStream out, boolean canStop) Copy an input stream to an output stream with a buffer of 4096 bytes. | public static String | createWhiteSpace(int len, int tabSize) | public static String | createWhiteSpace(int len, int tabSize, int start) | public static String | escapesToChars(String str) Converts "\n" and "\t" escapes in the specified string to
newlines and tabs. | public static String | expandVariables(String arg) Accepts a string from the user which may contain variables of various syntaxes. | public static String | fileToClass(String name) Converts a file name to a class name. | public static InputSource | findEntity(String systemId, String test, Class where) Tries to find the given systemId in the context of the given
class. | public static String | formatFileSize(long length) Formats the given file size into a nice string (123 Bytes, 10.6 kB,
1.2 MB). | public static String[] | getEncodings() Returns a list of supported character encodings. | public static String[] | getEncodings(boolean getSelected) Returns a list of supported character encodings. | public static String | getFileExtension(String path) Returns the extension of the specified filename, or an empty
string if there is none. | public static String | getFileName(String path) Returns the last component of the specified path. | public static String | getFileNameNoExtension(String path) Returns the last component of the specified path name without the
trailing extension (if there is one). | public static String | getFileParent(String path) | public static String | getFileProtocol(String url) | public static int | getFirstSeparatorIndex(String path) Return the first index of either / or the OS-specific file
separator. | public static int | getLastSeparatorIndex(String path) Return the last index of either / or the OS-specific file
separator. | public static int | getLeadingWhiteSpace(String str) Returns the number of leading white space characters in the
specified string. | public static int | getLeadingWhiteSpaceWidth(String str, int tabSize) Returns the width of the leading white space in the specified
string. | public static String | getLongestPrefix(List str, boolean ignoreCase) Returns the longest common prefix in the given set of strings. | public static String | getLongestPrefix(String[] str, boolean ignoreCase) Returns the longest common prefix in the given set of strings. | public static String | getLongestPrefix(Object[] str, boolean ignoreCase) Returns the longest common prefix in the given set of strings. | public static int | getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth) Returns the array offset of a virtual column number (taking tabs
into account) in the segment.
Parameters: seg - The segment Parameters: tabSize - The tab size Parameters: column - The virtual column number Parameters: totalVirtualWidth - If this array is non-null, the totalvirtual width will be stored in its first location if this methodreturns -1. | public static String | getParentOfPath(String path) Returns the parent of the specified path. | public static String | getProtocolOfURL(String url) Returns the protocol specified by a URL. | public static int | getTrailingWhiteSpace(String str) Returns the number of trailing whitespace characters in the
specified string. | public static int | getVirtualWidth(Segment seg, int tabSize) Returns the virtual column number (taking tabs into account) of the
specified offset in the segment. | public static String | globToRE(String glob) Converts a Unix-style glob to a regular expression.
? becomes ., * becomes .*, {aa,bb} becomes (aa|bb). | public static boolean | isAbsolutePath(String path) Returns if the specified path name is an absolute path or URL. | public static boolean | isBackup(String filename) Check if the filename is a backup file. | public static boolean | isBinary(Reader reader) Check if a Reader is binary. | public static boolean | isBinary(InputStream in) Check if an InputStream is binary.
First this tries encoding auto detection. | public static boolean | isToolsJarAvailable() If on JDK 1.2 or higher, make sure that tools.jar is available.
This method should be called by plugins requiring the classes
in this library.
tools.jar is searched for in the following places:
- the classpath that was used when jEdit was started,
- jEdit's jars folder in the user's home,
- jEdit's system jars folder,
- java.home/lib/.
| public static boolean | isURL(String str) Checks if the specified string is a URL. | public static boolean | moveFile(File source, File dest) Moves the source file to the destination.
If the destination cannot be created or is a read-only file, the
method returns false . | public static boolean | objectsEqual(Object o1, Object o2) Returns if two strings are equal. | public static int | parsePermissions(String s) Parse a Unix-style permission string (rwxrwxrwx). | public static boolean | parseXML(InputStream in, DefaultHandler handler) Convenience method for parsing an XML file. | public static boolean | pathsEqual(String p1, String p2) | public static void | quicksort(Object[] obj, Comparator compare) Sorts the specified array. | public static void | quicksort(Vector vector, Comparator compare) Sorts the specified vector. | public static void | quicksort(List list, Comparator compare) Sorts the specified list. | public static void | quicksort(Object[] obj, Compare compare) Sorts the specified array. | public static void | quicksort(Vector vector, Compare compare) Sorts the specified vector. | public static String | resolveSymlinks(String path) Resolves any symbolic links in the path name specified
using File.getCanonicalPath() . | public static void | saveBackup(File file, int backups, String backupPrefix, String backupSuffix, String backupDirectory) Saves a backup (optionally numbered) of a file.
Parameters: file - A local file Parameters: backups - The number of backups. | public static void | saveBackup(File file, int backups, String backupPrefix, String backupSuffix, String backupDirectory, int backupTimeDistance) Saves a backup (optionally numbered) of a file.
Parameters: file - A local file Parameters: backups - The number of backups. | public static boolean | stringsEqual(String s1, String s2) | public static String | throwableToString(Throwable t) Returns a string containing the stack trace of the given throwable. |
UTF_8_Y | final public static String UTF_8_Y(Code) | | This encoding is not supported by Java, yet it is useful.
A UTF-8 file that begins with 0xEFBBBF.
|
varPatternString2 | final static String varPatternString2(Code) | | |
autodetect | public static Reader autodetect(InputStream in, Buffer buffer) throws IOException(Code) | | Tries to detect if the stream is gzipped, and if it has an encoding
specified with an XML PI.
Parameters: in - the input stream reader that must be autodetected Parameters: buffer - a buffer. It can be null if you only want to autodetect the encoding of a file a Reader using the detected encoding throws: IOException - io exception during read since: jEdit 4.3pre5 |
buildToVersion | public static String buildToVersion(String build)(Code) | | Converts an internal version number (build) into a
`human-readable' form.
Parameters: build - The build |
canonPath | public static String canonPath(String path)(Code) | | the canonical form of the specified path name. Currentlyonly expands a leading ~ . For local path namesonly. Parameters: path - The path name since: jEdit 4.0pre2 |
charsToEscapes | public static String charsToEscapes(String str)(Code) | | Escapes newlines, tabs, backslashes, and quotes in the specified
string.
Parameters: str - The string since: jEdit 2.3pre1 |
charsToEscapes | public static String charsToEscapes(String str, String toEscape)(Code) | | Escapes the specified characters in the specified string.
Parameters: str - The string Parameters: toEscape - Any characters that require escaping since: jEdit 4.1pre3 |
classToFile | public static String classToFile(String name)(Code) | | Converts a class name to a file name. All periods are replaced
with slashes and the '.class' extension is added.
Parameters: name - The class name |
compareStrings | public static int compareStrings(String str1, String str2, boolean ignoreCase)(Code) | | Compares two strings.
Unlike String.compareTo(),
this method correctly recognizes and handles embedded numbers.
For example, it places "My file 2" before "My file 10".
Parameters: str1 - The first string Parameters: str2 - The second string Parameters: ignoreCase - If true, case will be ignored negative If str1 < str2, 0 if both are the same,positive if str1 > str2 since: jEdit 4.0pre1org.gjt.sp.util.StandardUtilities.compareStrings(StringStringboolean) |
constructPath | public static String constructPath(String parent, String path)(Code) | | Constructs an absolute path name from a directory and another
path name. This method is VFS-aware.
Parameters: parent - The directory Parameters: path - The path name |
constructPath | public static String constructPath(String parent, String path1, String path2)(Code) | | Constructs an absolute path name from three path components.
This method is VFS-aware.
Parameters: parent - The parent directory Parameters: path1 - The first path Parameters: path2 - The second path |
createWhiteSpace | public static String createWhiteSpace(int len, int tabSize)(Code) | | Creates a string of white space with the specified length.
To get a whitespace string tuned to the current buffer's
settings, call this method as follows:
myWhitespace = MiscUtilities.createWhiteSpace(myLength,
(buffer.getBooleanProperty("noTabs") ? 0
: buffer.getTabSize()));
Parameters: len - The length Parameters: tabSize - The tab size, or 0 if tabs are not to be usedorg.gjt.sp.util.StandardUtilities.createWhiteSpace(intint) |
createWhiteSpace | public static String createWhiteSpace(int len, int tabSize, int start)(Code) | | Creates a string of white space with the specified length.
To get a whitespace string tuned to the current buffer's
settings, call this method as follows:
myWhitespace = MiscUtilities.createWhiteSpace(myLength,
(buffer.getBooleanProperty("noTabs") ? 0
: buffer.getTabSize()));
Parameters: len - The length Parameters: tabSize - The tab size, or 0 if tabs are not to be used Parameters: start - The start offset, for tab alignment since: jEdit 4.2pre1org.gjt.sp.util.StandardUtilities.createWhiteSpace(intintint) |
escapesToChars | public static String escapesToChars(String str)(Code) | | Converts "\n" and "\t" escapes in the specified string to
newlines and tabs.
Parameters: str - The string since: jEdit 2.3pre1 |
expandVariables | public static String expandVariables(String arg)(Code) | | Accepts a string from the user which may contain variables of various syntaxes.
The goal is to support the following:
$varname
${varname}
And expand each of these by looking at the system environment variables for possible
expansions.
a string which is either the unchanged input string, or one with expanded variables. since: 4.3pre7 author: ezust |
fileToClass | public static String fileToClass(String name)(Code) | | Converts a file name to a class name. All slash characters are
replaced with periods and the trailing '.class' is removed.
Parameters: name - The file name |
formatFileSize | public static String formatFileSize(long length)(Code) | | Formats the given file size into a nice string (123 Bytes, 10.6 kB,
1.2 MB).
Parameters: length - The size since: jEdit 4.2pre1 |
getEncodings | public static String[] getEncodings()(Code) | | Returns a list of supported character encodings.
since: jEdit 4.2pre5 |
getEncodings | public static String[] getEncodings(boolean getSelected)(Code) | | Returns a list of supported character encodings.
since: jEdit 4.3pre5 Parameters: getSelected - Whether to return just the selected encodings or all. |
getFileExtension | public static String getFileExtension(String path)(Code) | | Returns the extension of the specified filename, or an empty
string if there is none.
Parameters: path - The path |
getFileName | public static String getFileName(String path)(Code) | | Returns the last component of the specified path.
This method is VFS-aware.
Parameters: path - The path name |
getFileNameNoExtension | public static String getFileNameNoExtension(String path)(Code) | | Returns the last component of the specified path name without the
trailing extension (if there is one).
Parameters: path - The path name since: jEdit 4.0pre8 |
getFirstSeparatorIndex | public static int getFirstSeparatorIndex(String path)(Code) | | Return the first index of either / or the OS-specific file
separator.
Parameters: path - The path since: jEdit 4.3pre3 |
getLastSeparatorIndex | public static int getLastSeparatorIndex(String path)(Code) | | Return the last index of either / or the OS-specific file
separator.
Parameters: path - The path since: jEdit 4.3pre3 |
getLongestPrefix | public static String getLongestPrefix(List str, boolean ignoreCase)(Code) | | Returns the longest common prefix in the given set of strings.
Parameters: str - The strings Parameters: ignoreCase - If true, case insensitive since: jEdit 4.2pre2 |
getLongestPrefix | public static String getLongestPrefix(String[] str, boolean ignoreCase)(Code) | | Returns the longest common prefix in the given set of strings.
Parameters: str - The strings Parameters: ignoreCase - If true, case insensitive since: jEdit 4.2pre2 |
getLongestPrefix | public static String getLongestPrefix(Object[] str, boolean ignoreCase)(Code) | | Returns the longest common prefix in the given set of strings.
Parameters: str - The strings (calls toString() on each object) Parameters: ignoreCase - If true, case insensitive since: jEdit 4.2pre6 |
getOffsetOfVirtualColumn | public static int getOffsetOfVirtualColumn(Segment seg, int tabSize, int column, int[] totalVirtualWidth)(Code) | | Returns the array offset of a virtual column number (taking tabs
into account) in the segment.
Parameters: seg - The segment Parameters: tabSize - The tab size Parameters: column - The virtual column number Parameters: totalVirtualWidth - If this array is non-null, the totalvirtual width will be stored in its first location if this methodreturns -1. -1 if the column is out of bounds since: jEdit 4.1pre1org.gjt.sp.util.StandardUtilities.getVirtualWidth(javax.swing.text.Segmentint) |
getParentOfPath | public static String getParentOfPath(String path)(Code) | | Returns the parent of the specified path. This method is VFS-aware.
Parameters: path - The path name since: jEdit 2.6pre5 |
getProtocolOfURL | public static String getProtocolOfURL(String url)(Code) | | Returns the protocol specified by a URL.
Parameters: url - The URL since: jEdit 2.6pre5 |
isAbsolutePath | public static boolean isAbsolutePath(String path)(Code) | | Returns if the specified path name is an absolute path or URL.
since: jEdit 4.1pre11 |
isBackup | public static boolean isBackup(String filename)(Code) | | Check if the filename is a backup file.
Parameters: filename - the filename to check true if this is a backup file. since: jEdit 4.3pre5 |
isBinary | public static boolean isBinary(InputStream in) throws IOException(Code) | | Check if an InputStream is binary.
First this tries encoding auto detection. If an encoding is
detected, the stream should be a text stream. Otherwise, this
will check the first characters 100
(jEdit property vfs.binaryCheck.length) in the system default
encoding. If more than 1 (jEdit property vfs.binaryCheck.count)
NUL(\u0000) was found, the stream is declared binary.
This is not 100% because sometimes the autodetection could fail.
This method will not close the stream. You have to do it yourself
Parameters: in - the stream true if the stream was detected as binary throws: IOException - IOException If an I/O error occurs since: jEdit 4.3pre10 |
isToolsJarAvailable | public static boolean isToolsJarAvailable()(Code) | | If on JDK 1.2 or higher, make sure that tools.jar is available.
This method should be called by plugins requiring the classes
in this library.
tools.jar is searched for in the following places:
- the classpath that was used when jEdit was started,
- jEdit's jars folder in the user's home,
- jEdit's system jars folder,
- java.home/lib/. In this case, tools.jar is added to
jEdit's list of known jars using jEdit.addPluginJAR(),
so that it gets loaded through JARClassLoader.
On older JDK's this method does not perform any checks, and returns
true (even though there is no tools.jar).
false if and only if on JDK 1.2 and tools.jarcould not be found. In this case it prints some warnings on Log,too, about the places where it was searched for. since: jEdit 3.2.2 |
isURL | public static boolean isURL(String str)(Code) | | Checks if the specified string is a URL.
Parameters: str - The string to check True if the string is a URL, false otherwise |
moveFile | public static boolean moveFile(File source, File dest)(Code) | | Moves the source file to the destination.
If the destination cannot be created or is a read-only file, the
method returns false . Otherwise, the contents of the
source are copied to the destination, the source is deleted,
and true is returned.
Parameters: source - The source file to move. Parameters: dest - The destination where to move the file. true on success, false otherwise. since: jEdit 4.3pre1org.gjt.sp.util.IOUtilities.moveFile(java.io.Filejava.io.File) |
parsePermissions | public static int parsePermissions(String s)(Code) | | Parse a Unix-style permission string (rwxrwxrwx).
Parameters: s - The string (must be 9 characters long). since: jEdit 4.1pre8 |
pathsEqual | public static boolean pathsEqual(String p1, String p2)(Code) | | Parameters: p1 - A path name Parameters: p2 - A path name True if both paths are equal, ignoring trailing slashes, aswell as case insensitivity on Windows. since: jEdit 4.3pre2 |
quicksort | public static void quicksort(Object[] obj, Comparator compare)(Code) | | Sorts the specified array. Equivalent to calling
Arrays.sort() .
Parameters: obj - The array Parameters: compare - Compares the objects since: jEdit 4.0pre4 |
quicksort | public static void quicksort(Vector vector, Comparator compare)(Code) | | Sorts the specified vector.
Parameters: vector - The vector Parameters: compare - Compares the objects since: jEdit 4.0pre4 |
quicksort | public static void quicksort(List list, Comparator compare)(Code) | | Sorts the specified list.
Parameters: list - The list Parameters: compare - Compares the objects since: jEdit 4.0pre4 |
quicksort | public static void quicksort(Object[] obj, Compare compare)(Code) | | Sorts the specified array. Equivalent to calling
Arrays.sort() .
Parameters: obj - The array Parameters: compare - Compares the objects |
quicksort | public static void quicksort(Vector vector, Compare compare)(Code) | | Sorts the specified vector.
Parameters: vector - The vector Parameters: compare - Compares the objects |
resolveSymlinks | public static String resolveSymlinks(String path)(Code) | | Resolves any symbolic links in the path name specified
using File.getCanonicalPath() . For local path
names only.
since: jEdit 4.2pre1 |
saveBackup | public static void saveBackup(File file, int backups, String backupPrefix, String backupSuffix, String backupDirectory)(Code) | | Saves a backup (optionally numbered) of a file.
Parameters: file - A local file Parameters: backups - The number of backups. Must be >= 1. If > 1, backupfiles will be numbered. Parameters: backupPrefix - The backup file name prefix Parameters: backupSuffix - The backup file name suffix Parameters: backupDirectory - The directory where to save backups; if null,they will be saved in the same directory as the file itself. since: jEdit 4.0pre1 |
saveBackup | public static void saveBackup(File file, int backups, String backupPrefix, String backupSuffix, String backupDirectory, int backupTimeDistance)(Code) | | Saves a backup (optionally numbered) of a file.
Parameters: file - A local file Parameters: backups - The number of backups. Must be >= 1. If > 1, backupfiles will be numbered. Parameters: backupPrefix - The backup file name prefix Parameters: backupSuffix - The backup file name suffix Parameters: backupDirectory - The directory where to save backups; if null,they will be saved in the same directory as the file itself. Parameters: backupTimeDistance - The minimum time in minutes when a backupversion 1 shall be moved into version 2; if 0, backups are alwaysmoved. since: jEdit 4.2pre5 |
throwableToString | public static String throwableToString(Throwable t)(Code) | | Returns a string containing the stack trace of the given throwable.
since: jEdit 4.2pre6 |
|
|