public class VfsUtilCore
extends java.lang.Object
VirtualFile
.Modifier and Type | Class and Description |
---|---|
static class |
VfsUtilCore.DistinctVFilesRootsCollection
this collection will keep only distinct files/folders, e.g.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
LOCALHOST_URI_PATH_PREFIX |
static java.lang.String |
VFS_SEPARATOR |
static char |
VFS_SEPARATOR_CHAR |
Constructor and Description |
---|
VfsUtilCore() |
Modifier and Type | Method and Description |
---|---|
static java.io.InputStream |
byteStreamSkippingBOM(byte [] buf,
VirtualFile file) |
static java.lang.String |
convertFromUrl(java.net.URL url) |
static java.net.URL |
convertToURL(java.lang.String vfsUrl)
Converts VsfUrl info
URL . |
static VirtualFile |
copyFile(java.lang.Object requestor,
VirtualFile file,
VirtualFile toDir)
Makes a copy of the
file in the toDir folder and returns it. |
static VirtualFile |
copyFile(java.lang.Object requestor,
VirtualFile file,
VirtualFile toDir,
java.lang.String newName)
Makes a copy of the
file in the toDir folder with the newName and returns it. |
static java.lang.String |
fileToUrl(java.io.File file) |
static VirtualFile |
findContainingDirectory(VirtualFile file,
java.lang.CharSequence name) |
static VirtualFile |
findRelativeFile(java.lang.String uri,
VirtualFile base) |
static java.lang.String |
findRelativePath(VirtualFile src,
VirtualFile dst,
char separatorChar)
Returns the relative path from one virtual file to another.
|
static java.lang.String |
fixIDEAUrl(java.lang.String ideaUrl) |
static java.lang.String |
fixURLforIDEA(java.lang.String url) |
static VirtualFile |
getCommonAncestor(VirtualFile file1,
VirtualFile file2)
Returns a common ancestor for the given files, or
null if the files do not have one. |
static java.lang.String |
getRelativeLocation(VirtualFile file,
VirtualFile root)
Gets a relative path of
file to root when it's possible
This method is designed to be used for file descriptions (in trees, lists etc.) |
static java.lang.String |
getRelativePath(VirtualFile file,
VirtualFile ancestor) |
static java.lang.String |
getRelativePath(VirtualFile file,
VirtualFile ancestor,
char separator)
Gets the relative path of
file to its ancestor . |
static VirtualFile |
getRootFile(VirtualFile file) |
static VirtualFile |
getVirtualFileForJar(VirtualFile entryVFile) |
static boolean |
hasInvalidFiles(java.lang.Iterable<? extends VirtualFile> files) |
static java.io.InputStream |
inputStreamSkippingBOM(java.io.InputStream stream,
VirtualFile file) |
static boolean |
isAncestor(java.io.File ancestor,
java.io.File file,
boolean strict) |
static boolean |
isAncestor(VirtualFile ancestor,
VirtualFile file,
boolean strict) |
static boolean |
isBrokenLink(VirtualFile file)
Returns
true if given virtual file represents broken symbolic link (which points to non-existent file). |
static boolean |
isEqualOrAncestor(java.lang.String ancestorUrl,
java.lang.String fileUrl) |
static boolean |
isInvalidLink(VirtualFile link)
Returns
true if given virtual file represents broken or recursive symbolic link. |
static boolean |
isUnder(java.lang.String url,
java.util.Collection<java.lang.String> rootUrls) |
static boolean |
isUnder(VirtualFile file,
java.util.Set<? extends VirtualFile> roots) |
static boolean |
iterateChildrenRecursively(VirtualFile root,
VirtualFileFilter filter,
ContentIterator iterator) |
static boolean |
iterateChildrenRecursively(VirtualFile root,
VirtualFileFilter filter,
ContentIterator iterator,
VirtualFileVisitor.Option... options) |
static byte [] |
loadBytes(VirtualFile file) |
static java.lang.String |
loadText(VirtualFile file) |
static java.lang.String |
loadText(VirtualFile file,
int length) |
static java.io.OutputStream |
outputStreamAddingBOM(java.io.OutputStream stream,
VirtualFile file) |
static java.lang.String |
pathToUrl(java.lang.String path) |
static boolean |
processFilesRecursively(VirtualFile root,
Processor<? super VirtualFile> processor) |
static java.lang.String |
toIdeaUrl(java.lang.String url) |
static java.lang.String |
toIdeaUrl(java.lang.String url,
boolean removeLocalhostPrefix) |
static VirtualFile [] |
toVirtualFileArray(java.util.Collection<? extends VirtualFile> files) |
static java.lang.String |
urlToPath(java.lang.String url) |
static java.io.File |
virtualToIoFile(VirtualFile file) |
static java.util.List<java.io.File> |
virtualToIoFiles(java.util.Collection<? extends VirtualFile> files) |
static VirtualFileVisitor.Result |
visitChildrenRecursively(VirtualFile file,
VirtualFileVisitor<?> visitor) |
static <E extends java.lang.Exception> |
visitChildrenRecursively(VirtualFile file,
VirtualFileVisitor<?> visitor,
java.lang.Class<E> eClass) |
public static final java.lang.String LOCALHOST_URI_PATH_PREFIX
public static final char VFS_SEPARATOR_CHAR
public static final java.lang.String VFS_SEPARATOR
public static boolean isAncestor(VirtualFile ancestor, VirtualFile file, boolean strict)
strict
- if false
then this method returns true
if ancestor
and file
are equalpublic static boolean isUnder(VirtualFile file, java.util.Set<? extends VirtualFile> roots)
true
if file
is located under one of roots
or equal to one of thempublic static boolean isUnder(java.lang.String url, java.util.Collection<java.lang.String> rootUrls)
true
if url
is located under one of rootUrls
or equal to one of thempublic static boolean isEqualOrAncestor(java.lang.String ancestorUrl, java.lang.String fileUrl)
public static boolean isAncestor(java.io.File ancestor, java.io.File file, boolean strict)
public static java.lang.String getRelativeLocation(VirtualFile file, VirtualFile root)
file
to root
when it's possible
This method is designed to be used for file descriptions (in trees, lists etc.)file
- the fileroot
- candidate to be parent file (Project base dir, any content roots etc.)file
or full path if root
is not actual ancestor of file
public static java.lang.String getRelativePath(VirtualFile file, VirtualFile ancestor)
public static java.lang.String getRelativePath(VirtualFile file, VirtualFile ancestor, char separator)
file
to its ancestor
. Uses separator
for
separating files.file
- the fileancestor
- parent fileseparator
- character to use as files separatornull
if ancestor
is not ancestor for file
public static java.lang.String findRelativePath(VirtualFile src, VirtualFile dst, char separatorChar)
src
is a file, the path is calculated from its parent directory.src
- the file or directory, from which the path is builtdst
- the file or directory, to which the path is builtseparatorChar
- the separator for the path componentsnull
if the files have no common ancestorpublic static VirtualFile getVirtualFileForJar(VirtualFile entryVFile)
public static VirtualFile copyFile(java.lang.Object requestor, VirtualFile file, VirtualFile toDir) throws java.io.IOException
file
in the toDir
folder and returns it.requestor
- any object to control who called this method. Note that
it is considered to be an external change if requestor
is null
.
See VirtualFileEvent.getRequestor()
file
- file to make a copy oftoDir
- directory to make a copy injava.io.IOException
- if file failed to be copiedpublic static VirtualFile copyFile(java.lang.Object requestor, VirtualFile file, VirtualFile toDir, java.lang.String newName) throws java.io.IOException
file
in the toDir
folder with the newName
and returns it.requestor
- any object to control who called this method. Note that
it is considered to be an external change if requestor
is null
.
See VirtualFileEvent.getRequestor()
file
- file to make a copy oftoDir
- directory to make a copy innewName
- a new name of the filejava.io.IOException
- if file failed to be copiedpublic static java.io.InputStream byteStreamSkippingBOM(byte [] buf, VirtualFile file) throws java.io.IOException
java.io.IOException
public static java.io.InputStream inputStreamSkippingBOM(java.io.InputStream stream, VirtualFile file) throws java.io.IOException
java.io.IOException
public static java.io.OutputStream outputStreamAddingBOM(java.io.OutputStream stream, VirtualFile file) throws java.io.IOException
java.io.IOException
public static boolean iterateChildrenRecursively(VirtualFile root, VirtualFileFilter filter, ContentIterator iterator)
public static boolean iterateChildrenRecursively(VirtualFile root, VirtualFileFilter filter, ContentIterator iterator, VirtualFileVisitor.Option... options)
public static VirtualFileVisitor.Result visitChildrenRecursively(VirtualFile file, VirtualFileVisitor<?> visitor) throws VirtualFileVisitor.VisitorException
public static <E extends java.lang.Exception> VirtualFileVisitor.Result visitChildrenRecursively(VirtualFile file, VirtualFileVisitor<?> visitor, java.lang.Class<E> eClass) throws E extends java.lang.Exception
E extends java.lang.Exception
public static boolean isBrokenLink(VirtualFile file)
true
if given virtual file represents broken symbolic link (which points to non-existent file).public static boolean isInvalidLink(VirtualFile link)
true
if given virtual file represents broken or recursive symbolic link.public static java.lang.String loadText(VirtualFile file) throws java.io.IOException
java.io.IOException
public static java.lang.String loadText(VirtualFile file, int length) throws java.io.IOException
java.io.IOException
public static byte [] loadBytes(VirtualFile file) throws java.io.IOException
java.io.IOException
public static VirtualFile [] toVirtualFileArray(java.util.Collection<? extends VirtualFile> files)
public static java.lang.String urlToPath(java.lang.String url)
public static java.io.File virtualToIoFile(VirtualFile file)
public static java.lang.String pathToUrl(java.lang.String path)
public static java.lang.String fileToUrl(java.io.File file)
public static java.util.List<java.io.File> virtualToIoFiles(java.util.Collection<? extends VirtualFile> files)
public static java.lang.String toIdeaUrl(java.lang.String url)
public static java.lang.String toIdeaUrl(java.lang.String url, boolean removeLocalhostPrefix)
public static java.lang.String fixURLforIDEA(java.lang.String url)
public static java.lang.String convertFromUrl(java.net.URL url)
public static java.net.URL convertToURL(java.lang.String vfsUrl)
URL
.vfsUrl
- VFS url (as constructed by VirtualFile.getUrl()
public static java.lang.String fixIDEAUrl(java.lang.String ideaUrl)
public static VirtualFile findRelativeFile(java.lang.String uri, VirtualFile base)
public static boolean processFilesRecursively(VirtualFile root, Processor<? super VirtualFile> processor)
public static VirtualFile getCommonAncestor(VirtualFile file1, VirtualFile file2)
null
if the files do not have one.public static boolean hasInvalidFiles(java.lang.Iterable<? extends VirtualFile> files)
public static VirtualFile findContainingDirectory(VirtualFile file, java.lang.CharSequence name)
public static VirtualFile getRootFile(VirtualFile file)