|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.intellij.openapi.util.io.FileUtil
jetbrains.buildServer.util.FileUtil
public class FileUtil
| Nested Class Summary | |
|---|---|
static interface |
FileUtil.Processor
|
| Field Summary |
|---|
| Fields inherited from class com.intellij.openapi.util.io.FileUtil |
|---|
MEGABYTE |
| Constructor Summary | |
|---|---|
FileUtil()
|
|
| Method Summary | |
|---|---|
static boolean |
areTheSame(java.io.File file1,
java.io.File file2)
Checks that both file pointers specify the same object. |
static boolean |
checkContentEqual(java.io.File file1,
java.io.File file2)
Check both files exist and are same byte-by-byte. |
static void |
checkTmpDir()
Checks if it is allowed to use tmpDir taked from "java.io.tmpdir" system property |
static void |
close(java.io.Closeable e)
Closes a resource if it is not null All possible IOExceptions are ignored |
static void |
closeAll(java.io.Closeable... toClose)
Closes all not-null resources All possible IOExceptions are ignored |
static java.lang.String |
convertAntToRegexp(java.lang.String antPattern)
|
static java.lang.String |
convertAntToRegexp(java.lang.String antPattern,
boolean ignoreStartingSlash)
|
static void |
copy(java.io.File from,
java.io.File to)
|
static void |
copyFilePart(java.io.File sourceFile,
long offset,
long length,
java.io.OutputStream destination)
Copies a part of a file to output stream. |
static void |
copyResource(java.lang.Class<?> clazz,
java.lang.String resourceName,
java.io.File outputFile)
Copies contents of the specified resource into the specified file. |
static void |
copyResource(java.lang.String resourceName,
java.io.File outputFile)
Deprecated. Use copyResource(Class, String, java.io.File) to overcome classloader change issues |
static void |
copyResourceIfNotExists(java.lang.Class<?> clazz,
java.lang.String resourceName,
java.io.File outputFile)
Copies the resource file into specified file if it doesn't exist (see copyResource(Class, String, java.io.File)). |
static void |
copyResourceWithDist(java.lang.Class<?> clazz,
java.lang.String resourceName,
java.io.File outputFile)
Copies the resource file into specified file (see copyResource(Class, String, java.io.File)). |
static void |
copyStreamRangeAndClose(java.io.InputStream source,
long offset,
long length,
java.io.OutputStream destination)
Copies a stream range of a file to output stream. |
static void |
copyStreams(java.io.InputStream is,
java.io.OutputStream os)
|
static java.io.File |
createDir(java.io.File dir)
Creates directory if it does not exist. |
static java.io.File |
createEmptyDir(java.io.File dir)
Creates an empty directory, removing all content if it already exists. |
static java.io.File |
createTempDirectory(java.lang.String prefix,
java.lang.String suffix,
java.io.File in)
|
static void |
deleteIfEmpty(java.io.File dir)
Removes directory if it is empty |
static java.io.File |
findFile(java.io.FileFilter filter,
java.io.File... directories)
Searches for a file in the specified directories recursively. |
static java.util.Collection<java.io.File> |
findFiles(java.io.FileFilter filter,
java.io.File... directories)
Searches for files in the specified directories recursively. |
static java.lang.String |
fixDirectoryName(java.lang.String name)
Fixes directory name: replaces all dangerous characters with '_'. |
static java.io.File |
getCanonicalFile(java.io.File file)
Attempts to obtain canonical file from the specified file and if it fails returns absolute file. |
static java.lang.String |
getCommonParent(java.lang.String firstUrl,
java.lang.String secondUrl)
|
static java.lang.String |
getExtension(java.lang.String fileNameWithDirectory)
Unlike com.intellij.openapi.util.io.FileUtil.getExtension, can use this with full full file name (including directory name). |
static java.io.File |
getFileInSameDir(java.io.File origFile,
java.lang.String neededFileName)
Returns a java.io.File object representing the file located in the same directory as origFile with the given file name
assert getFileInSameDir(new File("somDir/someFile.txt"), "anotherFile.txt"). |
static java.lang.String |
getFilesSignature(java.util.Collection<java.io.File> _files)
|
static java.lang.Long |
getFreeSpace(java.io.File file)
Computes free space on the disk that contains a file |
static java.lang.String |
getNameWithoutExtension(java.io.File file)
|
static java.lang.String |
getNameWithoutExtension(java.lang.String name)
|
static java.util.List<java.io.File> |
getSubDirectories(java.io.File root)
|
static long |
getTotalDirectorySize(java.io.File dir)
Returns the total directory size in bytes. |
static boolean |
isAncestor(java.io.File ancestor,
java.io.File file,
boolean strict)
Check if the ancestor is an ancestor of file. |
static boolean |
isBadDirectoryName(java.lang.String name)
Checks whether specified name contains dangerous characters which might prevent successful directory creation. |
static boolean |
isEmptyDir(java.io.File dir)
Returns true if directory is empty or does not exist and false otherwise. |
static boolean |
isFileSeparator(char c1)
|
static java.io.File[] |
listFiles(java.io.File file,
java.io.FilenameFilter filter)
A simple wrapper around file.listFiles(filter) that handles
possible null result. |
static java.lang.String |
normalizeRelativePath(java.lang.String path)
Normalizes relative path by eliminating all possible path/../ /./ ./path combinations |
static java.lang.String |
normalizeSeparator(java.lang.String filePath)
Replace all separators like / and \ to File.separatorChar |
static org.jdom.Element |
parseDocument(java.io.File file)
|
static org.jdom.Element |
parseDocument(java.io.File file,
boolean validate)
|
static org.jdom.Element |
parseDocument(java.io.InputStream input,
boolean validate)
|
static void |
processXmlFile(java.io.File file,
FileUtil.Processor p)
|
static java.util.List<java.lang.String> |
readFile(java.io.File file)
Read list of lines from the file. |
static java.lang.String |
readResourceAsString(java.lang.Class<?> clazz,
java.lang.String resourceName,
java.nio.charset.Charset charset)
Reads the jar resource as a text. |
static java.lang.String |
readText(java.io.File file)
Read the specified text file into a String variable. |
static void |
readXmlFile(java.io.File file,
FileUtil.Processor p)
|
static java.io.File |
resolvePath(java.io.File baseDir,
java.lang.String path)
If path is absolute, returns path, otherwise it returns path within specified base directory. |
static void |
saveDocument(org.jdom.Document document,
java.io.File file)
|
static void |
setExectuableAttribute(java.lang.String path,
boolean executableFlag)
Set executable attibute, it makes sense only on non-windows platforms. |
static void |
sortFiles(java.io.File[] files)
|
static void |
writeFile(java.io.File file,
java.lang.String text)
Write text to file and report any errors via LOG.error() |
static void |
writeFileAndReportErrors(java.io.File file,
java.lang.String text)
Writes text to file. |
| Methods inherited from class com.intellij.openapi.util.io.FileUtil |
|---|
adaptiveLoadBytes, adaptiveLoadText, asyncDelete, asyncDelete, canCallCanExecute, canExecute, collectMatchedFiles, comparePaths, copy, copy, copyContent, copyDir, copyDir, copyDir, createIfDoesntExist, createParentDirs, createSequentFileName, createTempDirectory, createTempFile, createTempFile, delete, ensureCanCreateFile, findFirstThatExist, findSequentNonexistentFile, getParentFile, getRelativePath, getRelativePath, getRelativePath, getTempDirectory, isAbsolute, isFilePathAcceptable, loadBytes, loadBytes, loadFileBytes, loadFileText, loadFileText, loadText, loadTextAndClose, moveDirWithContent, nameToCompare, pathHashCode, pathsEqual, processFilesRecursively, rename, resolveShortWindowsName, sanitizeFileName, setReadOnlyAttribute, startsWith, startsWith, toSystemDependentName, toSystemIndependentName, unquote, writeToFile, writeToFile |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileUtil()
| Method Detail |
|---|
@NotNull
public static java.util.List<java.lang.String> readFile(@NotNull
java.io.File file)
throws java.io.IOException
file - file to read
java.io.IOException - upon a problem when reading from file
public static java.lang.String readText(@NotNull
java.io.File file)
throws java.io.IOException
file - file to read
java.io.IOException - upon a problem when reading from file
public static void writeFile(@NotNull
java.io.File file,
@NotNull
java.lang.String text)
file - file to writetext - text to write to file
public static void writeFileAndReportErrors(@NotNull
java.io.File file,
@NotNull
java.lang.String text)
throws java.io.IOException
file - file to write text totext - text to write in file
java.io.IOException - if error occurred
public static void readXmlFile(@NotNull
java.io.File file,
@NotNull
FileUtil.Processor p)
public static org.jdom.Element parseDocument(@NotNull
java.io.File file)
throws org.jdom.JDOMException,
java.io.IOException
org.jdom.JDOMException
java.io.IOException
public static org.jdom.Element parseDocument(@NotNull
java.io.File file,
boolean validate)
throws org.jdom.JDOMException,
java.io.IOException
org.jdom.JDOMException
java.io.IOException
public static org.jdom.Element parseDocument(@NotNull
java.io.InputStream input,
boolean validate)
throws org.jdom.JDOMException,
java.io.IOException
org.jdom.JDOMException
java.io.IOException
public static void processXmlFile(@NotNull
java.io.File file,
@NotNull
FileUtil.Processor p)
public static void saveDocument(@NotNull
org.jdom.Document document,
@NotNull
java.io.File file)
throws java.io.IOException
java.io.IOException
@NotNull
public static java.lang.String getFilesSignature(@NotNull
java.util.Collection<java.io.File> _files)
@NotNull
public static java.io.File createTempDirectory(java.lang.String prefix,
java.lang.String suffix,
java.io.File in)
throws java.io.IOException
java.io.IOException
@NotNull
public static java.io.File getFileInSameDir(@NotNull
java.io.File origFile,
java.lang.String neededFileName)
assert getFileInSameDir(new File("somDir/someFile.txt"), "anotherFile.txt").
equals(new File("someDir/anotherFile.txt"));
origFile - original fileneededFileName - name of required file
@NotNull
public static java.io.File resolvePath(@NotNull
java.io.File baseDir,
@NotNull
java.lang.String path)
baseDir - base directory for the resolving the pathpath - path to be resolved, may be absolute or relative for baseDir
public static void copyResource(@NotNull
java.lang.String resourceName,
@NotNull
java.io.File outputFile)
copyResource(Class, String, java.io.File) to overcome classloader change issues
resourceName - Name of the classpath resourceoutputFile - target file for the resource data
public static void copyResource(@NotNull
java.lang.Class<?> clazz,
@NotNull
java.lang.String resourceName,
@NotNull
java.io.File outputFile)
Class.getResourceAsStream(String) in 'clazz' parameter to fetch the resource.
NOTE: File will be created even if there was no such resource
clazz - class from the class loader that can access the resourceresourceName - Name of the classpath resourceoutputFile - target file for the resource data
public static void copyResourceIfNotExists(@NotNull
java.lang.Class<?> clazz,
@NotNull
java.lang.String resourceName,
@NotNull
java.io.File outputFile)
copyResource(Class, String, java.io.File)).
clazz - class from the class loader that can access the resourceresourceName - the name of the classpath resourceoutputFile - destination file for the resource data
public static void copyResourceWithDist(@NotNull
java.lang.Class<?> clazz,
@NotNull
java.lang.String resourceName,
@NotNull
java.io.File outputFile)
copyResource(Class, String, java.io.File)).
Handles the '.dist' file as well, i.e.:
clazz - class from the class loader that can access the resourceresourceName - the name of the classpath resourceoutputFile - destination file for the resource data
@Nullable
public static java.lang.String readResourceAsString(@NotNull
java.lang.Class<?> clazz,
@NotNull
java.lang.String resourceName,
@NotNull
java.nio.charset.Charset charset)
throws java.io.IOException
clazz - class (used to determine the resource path).resourceName - name of resource to read.charset - character set of the resource file.
java.io.IOException - when IO error occurs
public static void copyStreams(java.io.InputStream is,
java.io.OutputStream os)
throws java.io.IOException
java.io.IOException
public static void copyFilePart(@NotNull
java.io.File sourceFile,
long offset,
long length,
@NotNull
java.io.OutputStream destination)
throws java.io.IOException
sourceFile - file to copyoffset - file offsetlength - length of datadestination - strem to write to
java.io.IOException
public static void copyStreamRangeAndClose(@NotNull
java.io.InputStream source,
long offset,
long length,
@NotNull
java.io.OutputStream destination)
throws java.io.IOException
source - file to copyoffset - file offsetlength - length of datadestination - strem to write to
java.io.IOExceptionTCStreamUtil.skip(java.io.InputStream, long),
TCStreamUtil.writeBinary(java.io.InputStream, long, java.io.OutputStream)
public static void close(@Nullable
java.io.Closeable e)
e - resource to close
public static void closeAll(@NotNull
java.io.Closeable... toClose)
toClose - resources to close
@NotNull
public static java.util.List<java.io.File> getSubDirectories(@NotNull
java.io.File root)
@NotNull
public static java.io.File createDir(@NotNull
java.io.File dir)
throws java.io.IOException
dir - directory to be created
java.io.IOException - if failed to create directory
public static java.io.File createEmptyDir(@NotNull
java.io.File dir)
throws java.io.IOException
dir - the directory to create
java.io.IOException - in case of I/O error occurred
public static long getTotalDirectorySize(@Nullable
java.io.File dir)
dir - the directory to traverse
public static void deleteIfEmpty(@NotNull
java.io.File dir)
dir - directory to be removed
public static boolean isEmptyDir(@NotNull
java.io.File dir)
dir - directory
@NotNull
public static java.lang.String fixDirectoryName(@NotNull
java.lang.String name)
name - name of the directory to fix
public static boolean isBadDirectoryName(@NotNull
java.lang.String name)
name - name to check (just name not path)
@NotNull
public static java.lang.String normalizeSeparator(@NotNull
java.lang.String filePath)
filePath - path to ve normilized
@NotNull
public static java.lang.String normalizeRelativePath(@NotNull
java.lang.String path)
path - relative path, not null
public static void sortFiles(@NotNull
java.io.File[] files)
@NotNull
public static java.lang.String getCommonParent(@NotNull
java.lang.String firstUrl,
@NotNull
java.lang.String secondUrl)
public static boolean isFileSeparator(char c1)
@NotNull
public static java.io.File getCanonicalFile(@NotNull
java.io.File file)
file - file
public static void checkTmpDir()
java.lang.IllegalStateException - if there is no access to temp dir.
@Nullable
public static java.io.File findFile(@NotNull
java.io.FileFilter filter,
@NotNull
java.io.File... directories)
filter - filter which checks whether file is acceptabledirectories - directories to search for (recursively)
@NotNull
public static java.util.Collection<java.io.File> findFiles(@NotNull
java.io.FileFilter filter,
@NotNull
java.io.File... directories)
filter - filter which checks whether file is acceptabledirectories - directories to search for (recursively)
@NotNull
public static java.io.File[] listFiles(@NotNull
java.io.File file,
@NotNull
java.io.FilenameFilter filter)
file.listFiles(filter) that handles
possible null result. In this case an empty array is returned.
file - the filefilter - the filter to apply
@Nullable
public static java.lang.Long getFreeSpace(@NotNull
java.io.File file)
file - file to select disk
public static void copy(@NotNull
java.io.File from,
@NotNull
java.io.File to)
throws java.io.IOException
java.io.IOException
public static boolean areTheSame(@Nullable
java.io.File file1,
@Nullable
java.io.File file2)
throws java.io.IOException
Note: it also returns true if both pointers are null.
file1 - the first file pointer.file2 - the second file pointer.
java.io.IOException
@NotNull
public static java.lang.String convertAntToRegexp(@NotNull
java.lang.String antPattern)
@NotNull
public static java.lang.String convertAntToRegexp(@NotNull
java.lang.String antPattern,
boolean ignoreStartingSlash)
antPattern - ant-style path pattern
FileUtil.toSystemIndependentName(java.lang.String)
@NotNull
public static java.lang.String getExtension(@NotNull
java.lang.String fileNameWithDirectory)
fileNameWithDirectory -
@NotNull
public static java.lang.String getNameWithoutExtension(@NotNull
java.io.File file)
@NotNull
public static java.lang.String getNameWithoutExtension(@NotNull
java.lang.String name)
public static void setExectuableAttribute(java.lang.String path,
boolean executableFlag)
throws java.io.IOException
path - the path to useexecutableFlag - new value of executable attribute
java.io.IOException - if there is a problem with setting the flag
public static boolean checkContentEqual(@NotNull
java.io.File file1,
@NotNull
java.io.File file2)
file1 - first filefile2 - second file
public static boolean isAncestor(@NotNull
java.io.File ancestor,
@NotNull
java.io.File file,
boolean strict)
ancestor is an ancestor of file.
Overrides the same method from FileUtil.
Please do not use the method from super class directly - it can cause the compilation problems.
ancestor - the filefile - the filestrict - if false then this method returns true if ancestor
and file are equal
true if ancestor is parent of file; false otherwise
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||