public class FileHelper
extends java.lang.Object
| Constructor and Description |
|---|
FileHelper() |
| Modifier and Type | Method and Description |
|---|---|
static java.lang.String |
convertPackageNameToFolderPath(java.lang.String packageName_p)
Convert package name to a correct java folder path.
|
static void |
copyFile(java.lang.String sourceFileRelativePath_p,
java.lang.String targetFileRelativePath_p)
Copy given source file content in given target file.
|
static boolean |
deleteFile(java.lang.String workspaceRelativeFile_p)
Delete given relative file in the workspace.
|
static boolean |
deleteFolder(java.lang.String workspaceRelativePath_p)
Delete given relative folder in the workspace.
|
static void |
ensurePathAvailability(java.lang.String fileFullPath_p)
Make sure that given path is safe to use, ie ensure that all parent folders exist.
|
static boolean |
exists(java.lang.String fileRelativePath_p)
Is given file relative path pointing to an existing file ?
|
static java.io.InputStream |
getFileAsStream(java.lang.String filePath_p)
Get file as a stream.
|
static java.lang.String |
getFileExtension(java.lang.String filePath_p)
Returns the file extension portion for given file path,
or null if there is none. |
static org.eclipse.emf.common.util.URI |
getFileFullUri(java.lang.String fileRelativePath_p)
Get a file uri from relative one which is not resolved against the eclipse platform.
The returned uri starts with either 'platform:/plug-in/' or 'platform:/resource/'. |
static java.net.URL |
getFileFullUrl(java.lang.String fileRelativePath_p)
Get file full url from relative one.
|
static java.net.URL |
getFileFullUrl(org.eclipse.emf.common.util.URI fileFullUri_p)
Get file full url from its full uri.
See getFileFullUri(String) method. |
static IFile |
getPlatformFile(java.lang.String fileRelativePath_p)
Get platform file as an
IResource from its relative path. |
static IFolder |
getPlatformFolder(java.lang.String folderRelativePath_p)
Get platform folder as an
IResource from its relative path. |
static boolean |
makeFileWritable(java.lang.String filePath_p)
Make file writable.
That is, make sure file is modifiable after this call. The user may be asked to take a decision if the file is held by the configuration management system. Nevertheless, if no UI is reachable, then the system is urged into making the file writable. |
static boolean |
moveResource(IResource resource_p,
IPath destinationPath_p)
Move resource to given destination path.
|
static byte[] |
readFile(java.io.InputStream inputStream_p)
Read given input stream as an array of bytes.
|
static java.lang.String |
readFile(java.lang.String filePath_p)
Read file as a string.
|
static byte[] |
readRawFile(java.lang.String filePath_p)
Read file as an array of bytes.
|
static boolean |
renameFile(java.lang.String sourceFileRelativePath_p,
java.lang.String destinationFileRelativePath_p)
Rename file from source file relative path to destination relative path.
|
static boolean |
renameFolder(java.lang.String sourceFolderRelativePath_p,
java.lang.String destinationFolderRelativePath_p)
Rename folder from source folder relative path to destination relative path.
|
static boolean |
writeFile(java.lang.String filePath_p,
boolean ensureFolders_p,
byte[] contents_p)
Write given contents of bytes at specified path.
|
static boolean |
writeFile(java.lang.String filePath_p,
boolean ensureFolders_p,
java.lang.String contents_p)
Write given string contents at specified path.
|
public static java.net.URL getFileFullUrl(java.lang.String fileRelativePath_p)
fileRelativePath_p - File path relative to workspace.public static java.net.URL getFileFullUrl(org.eclipse.emf.common.util.URI fileFullUri_p)
getFileFullUri(String) method.fileFullUri_p - public static org.eclipse.emf.common.util.URI getFileFullUri(java.lang.String fileRelativePath_p)
fileRelativePath_p - File path relative to workspace.project name or pluginId. It is also recommended that both
plug-in id and plug-in project names are the same.URI not resolved against the eclipse platform.public static java.lang.String convertPackageNameToFolderPath(java.lang.String packageName_p)
packageName_p - public static byte[] readFile(java.io.InputStream inputStream_p)
inputStream_p - public static java.lang.String readFile(java.lang.String filePath_p)
throws java.io.UnsupportedEncodingException
filePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.ICommonConstants.EMPTY_STRING is returned.java.io.UnsupportedEncodingExceptionpublic static java.io.InputStream getFileAsStream(java.lang.String filePath_p)
filePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static byte[] readRawFile(java.lang.String filePath_p)
filePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static void copyFile(java.lang.String sourceFileRelativePath_p,
java.lang.String targetFileRelativePath_p)
sourceFileRelativePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.targetFileRelativePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static boolean writeFile(java.lang.String filePath_p,
boolean ensureFolders_p,
java.lang.String contents_p)
filePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.ensureFolders_p - Make sure all parent folders exist by creating all necessary ones.contents_p - Contents that should be written to pointed file.public static boolean writeFile(java.lang.String filePath_p,
boolean ensureFolders_p,
byte[] contents_p)
filePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.ensureFolders_p - Make sure all parent folders exist by creating all necessary ones.contents_p - Contents that should be written to pointed file.public static boolean renameFile(java.lang.String sourceFileRelativePath_p,
java.lang.String destinationFileRelativePath_p)
sourceFileRelativePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.destinationFileRelativePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static boolean renameFolder(java.lang.String sourceFolderRelativePath_p,
java.lang.String destinationFolderRelativePath_p)
sourceFolderRelativePath_p - Folder path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.destinationFolderRelativePath_p - Folder path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static boolean moveResource(IResource resource_p, IPath destinationPath_p)
resource_p - destinationPath_p - public static boolean exists(java.lang.String fileRelativePath_p)
fileRelativePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static void ensurePathAvailability(java.lang.String fileFullPath_p)
fileFullPath_p - public static boolean deleteFile(java.lang.String workspaceRelativeFile_p)
workspaceRelativeFile_p - public static boolean deleteFolder(java.lang.String workspaceRelativePath_p)
workspaceRelativePath_p - public static IFile getPlatformFile(java.lang.String fileRelativePath_p)
IResource from its relative path.fileRelativePath_p - File path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static IFolder getPlatformFolder(java.lang.String folderRelativePath_p)
IResource from its relative path.folderRelativePath_p - Folder path relative to the plug-in, plug-in id included.getFileFullUrl(String) documentation.public static java.lang.String getFileExtension(java.lang.String filePath_p)
null if there is none.
The file extension portion is defined as the string
following the last period (".") character in the last segment.
If there is no period in the last segment, the path has no
file extension portion. If the last segment ends in a period,
the file extension portion is the empty string.
filePath_p - nullpublic static boolean makeFileWritable(java.lang.String filePath_p)
filePath_p - File path relative to the plug-in, plug-in id included. See getFileFullUrl(String) documentation.