Package com._1c.g5.v8.dt.common
Class FileUtil
java.lang.Object
com._1c.g5.v8.dt.common.FileUtil
File utility methods.
- Restriction:
- This class is not intended to be sub-classed by clients.
- Restriction:
- This class is not intended to be instantiated by clients.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classAutomatically deletes folder (or file) when leaving try-with-resources block. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCommon DT IDE parent folder name to use for temporary folder creation.static final charUnicode Byte Order Mark (BOM) char, value is. -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidcleanFolderIfEmpty(org.eclipse.core.resources.IContainer container) Removes all container folders if they are empty start from givencontainer.static voidcopyRecursively(Path sourcePath, Path targetPath) Copies folder fromsourcePathwith its sub folders totargetPathstatic final voidcreateEmptyFileIfNotExist(org.eclipse.core.resources.IFile file) Create empty file if it is not already exist.static voidcreateFolders(org.eclipse.core.resources.IFolder folder) Creates a folder by creating all nonexistent parent folders first.static final voidcreateParentFolders(org.eclipse.core.resources.IFile file) Creates parent folders recursively for given file.static FileCreates a new directory in the DT IDE temporary directory, using generated name.static FilecreateTempDirectory(String prefix) Creates a new directory in the DT IDE temporary directory, using the givenprefixto generate its name.static FilecreateTempDirectory(String prefix, Path parent) Creates a new directory in the DT IDE temporary directory, using the givenprefixto generate its name under the provided parent directory.static FilecreateTempFile(String prefix, String suffix) Creates a new empty file in the DT IDE temporary directory, using the givenprefixandsuffixstrings to generate its name.static final voiddeleteRecursively(File file) Delete the target file, if it is a file, or delete the target folder recursively with entire content of files and sub-folders if it is a folder.static final voiddeleteRecursively(Path path) Delete the target file, if it is a file, or delete the target folder recursively with entire content of files and sub-folders if it is a folder.static final voidDelete the target file, if it is a file, or delete the target folder recursively with entire content of files and sub-folders if it is a folder.static final StringgetExtension(File file) Returns file extension of the given file, resolved by the file name.static final StringgetExtension(String fileName) Returns file extension of the given file, resolved by the file name.static Collection<Path>getFilesInDirectory(Path directory, Predicate<? super Path> filter) Provides the list of files in selected directorystatic PathReturns DT IDE base path for temporary directories and files location.static final booleanhasExtension(File file, String extension) Returns whether the given file has the given file extension.static booleanChecks that file is emptystatic final voidmoveOrRenameFile(org.eclipse.core.resources.IFile newFile, org.eclipse.core.resources.IFile oldFile) Moves or renames the file Supports renaming of separate parts of the path, supports renames with case-changes only Supports creation of missed part of folders Cleans old folder if emptystatic final voidmoveOrRenameFolder(org.eclipse.core.resources.IFolder newFolder, org.eclipse.core.resources.IFolder oldFolder) Moves or renames the folder Supports renaming of separate parts of the path, supports renames with case-changes only Supports creation of missed part of folders Cleans old folder if emptystatic final BufferedReaderskipBom(BufferedReader reader) Skip Unicode BOM in the given buffered reader.static final StringtrimExtension(File file) Returns the file name with trimmed extension of the file.static final StringtrimExtension(Path path) Returns the file name with trimmed extension of the path.
-
Field Details
-
UTF_BOM
public static final char UTF_BOMUnicode Byte Order Mark (BOM) char, value is.- See Also:
-
ContentHandler.ByteOrderMarkIContentDescription- Constant Field Values
-
DT_TEMP_FOLDER
Common DT IDE parent folder name to use for temporary folder creation. Used to hold DT IDE temp folders in one parent folder.- See Also:
-
-
Method Details
-
getTempBasePath
Returns DT IDE base path for temporary directories and files location.- Returns:
- DT IDE base path for temporary directories and files location, never
null - See Also:
-
createTempFile
Creates a new empty file in the DT IDE temporary directory, using the givenprefixandsuffixstrings to generate its name.Instead of
com.google.common.io.Filesandjava.nio.file.Filescreates temp file under generalDT_TEMP_FOLDERsuper directory.- Parameters:
prefix- the prefix string to be used in generating the file's name ornullif not neededsuffix- the suffix string to be used in generating the file's name ornullif not needed, in which case.tmpis used- Returns:
- the creted temporary file, never
null - Throws:
IOException- if an I/O error occurs
-
createTempDirectory
Creates a new directory in the DT IDE temporary directory, using generated name.Instead of
com.google.common.io.Filesandjava.nio.file.Filescreates temp directory under generalDT_TEMP_FOLDERsuper directory.- Returns:
- the creted temporary directory, never
null - Throws:
IOException- if an I/O error occurs
-
createTempDirectory
Creates a new directory in the DT IDE temporary directory, using the givenprefixto generate its name.Instead of
com.google.common.io.Filesandjava.nio.file.Filescreates temp directory under generalDT_TEMP_FOLDERsuper directory.- Parameters:
prefix- the prefix string to be used in generating the directory's name ornullif not needed- Returns:
- the creted temporary directory, never
null - Throws:
IOException- if an I/O error occurs
-
createTempDirectory
Creates a new directory in the DT IDE temporary directory, using the givenprefixto generate its name under the provided parent directory.- Parameters:
prefix- the prefix string to be used in generating the directory's name ornullif not neededparent- the parent directory to create in, cannot benull- Returns:
- the creted temporary directory, never
null - Throws:
IOException- if an I/O error occurs
-
deleteRecursively
Delete the target file, if it is a file, or delete the target folder recursively with entire content of files and sub-folders if it is a folder.- Parameters:
file- the file or folder to delete recursively, cannot benull- Throws:
IOException- if delete fails for some reason
-
deleteRecursively
Delete the target file, if it is a file, or delete the target folder recursively with entire content of files and sub-folders if it is a folder.- Parameters:
path- the path of the file or folder to delete recursively, cannot benull- Throws:
IOException- if delete fails for some reason
-
deleteRecursivelyWithRetries
Delete the target file, if it is a file, or delete the target folder recursively with entire content of files and sub-folders if it is a folder. If an I/O error occurs, deletion is retried.This method is intended to bypass problems with anti-virus software on Windows. Unike Unix, Windows does not allow to delete a file if it is open, thus inspections performed by anti-virus software cause deletion to fail.
- Parameters:
path- The path of the file or folder to delete, cannot benull- Throws:
IOException- if an I/O error occurs and no more retries left.
-
getExtension
Returns file extension of the given file, resolved by the file name.- Parameters:
file- the file to get extension for, cannot benull- Returns:
- file extension of the given file or empty
Stringif cannot get
-
getExtension
Returns file extension of the given file, resolved by the file name.- Parameters:
file- the file to get extension for, cannot benull- Returns:
- file extension of the given file or empty
Stringif cannot get
-
hasExtension
Returns whether the given file has the given file extension. File extension is resolved by the file name.- Parameters:
file- the file to check extension for, cannot benullextension- the file extension to check, cannot benull- Returns:
- whether the given file has the given file extension
-
getFilesInDirectory
public static Collection<Path> getFilesInDirectory(Path directory, Predicate<? super Path> filter) throws IOException Provides the list of files in selected directory- Parameters:
directory- the target directory, cannot benullfilter- the files filter, can benull- Returns:
- the list of files in selected directory, never
null - Throws:
IOException
-
trimExtension
Returns the file name with trimmed extension of the file.- Parameters:
file- the file to trim extension for, cannot benull- Returns:
- the file name with trimmed extension of the file or the original file name if cannot get file extension
-
trimExtension
Returns the file name with trimmed extension of the path.- Parameters:
path- the file path to trim extension for, cannot benull- Returns:
- the file name with trimmed extension of the path or the original file or dirictory name if cannot get extension
-
skipBom
Skip Unicode BOM in the given buffered reader. If reader has no BOM in the current read cursor then reader will stay unchanged.- Parameters:
reader- the reader to skip Unicode BOM, cannot benull- Returns:
- a reference to the using reader, never
null - Throws:
IOException- if I/0 error occurred
-
cleanFolderIfEmpty
public static final void cleanFolderIfEmpty(org.eclipse.core.resources.IContainer container) throws org.eclipse.core.runtime.CoreException Removes all container folders if they are empty start from givencontainer. If container isIProjectthen removal process stops.- Parameters:
container- container to start cleaning from (notnull)- Throws:
org.eclipse.core.runtime.CoreException- if this request fails. Reasons include:- This resource does not exist.
- This resource is a project that is not open.
-
createParentFolders
public static final void createParentFolders(org.eclipse.core.resources.IFile file) throws org.eclipse.core.runtime.CoreException Creates parent folders recursively for given file.- Parameters:
file- the file to create parent folders for- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- The workspace contains a resource of a different type at the same path as this resource.
- The parent of this resource or containing folders is a project that is not open.
- The parent contains a resource of a different type at the same path as this resource.
- The parent of this resource is virtual, but this resource is not.
- The name of one of folders is not valid (according to
IWorkspace.validateName). - The corresponding location in the local file system is occupied by a file (as opposed to a directory).
- Resource changes are disallowed during certain types of resource change
event notification. See
IResourceChangeEventfor more details.
-
createFolders
public static void createFolders(org.eclipse.core.resources.IFolder folder) throws org.eclipse.core.runtime.CoreException Creates a folder by creating all nonexistent parent folders first.- Parameters:
folder- The folder to create. May not benull.- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- The workspace contains a resource of a different type at the same path as this resource.
- The parent of this resource or containing folders is a project that is not open.
- The parent contains a resource of a different type at the same path as this resource.
- The parent of this resource is virtual, but this resource is not.
- The name of one of folders is not valid (according to
IWorkspace.validateName). - The corresponding location in the local file system is occupied by a file (as opposed to a directory).
- Resource changes are disallowed during certain types of resource change
event notification. See
IResourceChangeEventfor more details.
-
moveOrRenameFile
public static final void moveOrRenameFile(org.eclipse.core.resources.IFile newFile, org.eclipse.core.resources.IFile oldFile) throws org.eclipse.core.runtime.CoreException Moves or renames the file Supports renaming of separate parts of the path, supports renames with case-changes only Supports creation of missed part of folders Cleans old folder if empty- Parameters:
newFile- The new file path. May not benulloldFile- The old file path. May not benull- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- The workspace contains a resource of a different type at the same path as this resource.
- The parent of this resource or containing folders is a project that is not open.
- The parent contains a resource of a different type at the same path as this resource.
- The parent of this resource is virtual, but this resource is not.
- The name of one of folders is not valid (according to
IWorkspace.validateName). - The corresponding location in the local file system is occupied by a file (as opposed to a directory).
- Resource changes are disallowed during certain types of resource change
event notification. See
IResourceChangeEventfor more details.
-
moveOrRenameFolder
public static final void moveOrRenameFolder(org.eclipse.core.resources.IFolder newFolder, org.eclipse.core.resources.IFolder oldFolder) throws org.eclipse.core.runtime.CoreException Moves or renames the folder Supports renaming of separate parts of the path, supports renames with case-changes only Supports creation of missed part of folders Cleans old folder if empty- Parameters:
newFolder- The new folder path. May not benulloldFolder- The old folder path. May not benull- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- The workspace contains a resource of a different type at the same path as this resource.
- The parent of this resource or containing folders is a project that is not open.
- The parent contains a resource of a different type at the same path as this resource.
- The parent of this resource is virtual, but this resource is not.
- The name of one of folders is not valid (according to
IWorkspace.validateName). - The corresponding location in the local file system is occupied by a file (as opposed to a directory).
- Resource changes are disallowed during certain types of resource change
event notification. See
IResourceChangeEventfor more details.
-
createEmptyFileIfNotExist
public static final void createEmptyFileIfNotExist(org.eclipse.core.resources.IFile file) throws org.eclipse.core.runtime.CoreException Create empty file if it is not already exist. Creates parent folders recursively for given file.- Parameters:
file- the file to create- Throws:
org.eclipse.core.runtime.CoreException- if this method fails. Reasons include:- The workspace contains a resource of a different type at the same path as this resource.
- The parent of this resource or containing folders is a project that is not open.
- The parent contains a resource of a different type at the same path as this resource.
- The parent of this resource is virtual, but this resource is not.
- The name of one of folders is not valid (according to
IWorkspace.validateName). - The corresponding location in the local file system is occupied by a file (as opposed to a directory).
- Resource changes are disallowed during certain types of resource change
event notification. See
IResourceChangeEventfor more details.
-
copyRecursively
Copies folder fromsourcePathwith its sub folders totargetPath- Parameters:
sourcePath- path to the copying folder, can't benulltargetPath- path to the destination of copied folder, can't benull- Throws:
IOException- ifIOExceptionwas occurred, seeFiles.walkFileTree(Path, java.nio.file.FileVisitor)
-
isEmpty
Checks that file is empty- Parameters:
path- path to the checked file, can't benull- Returns:
trueif the file content is empty or there is no such files,falseotherwise- Throws:
IOException- ifIOExceptionwas occurred
-