Provides file access for workspace and file system resources. Methods accepting location objects can deal with String, URI, IFile and File instances.
Constant | Description |
---|---|
APPEND | Access modifier for append mode (4). |
READ | Access modifier for read mode (1). |
WRITE | Access modifier for write mode (2). |
Method | Description |
---|---|
closeFile() | Close a file. |
copyFile() | Copies a file from location to targetLocation. |
createFile() | Create a new file in the workspace or the file system. |
createFolder() | Create a new folder in the workspace or the file system. |
createProblemMarker() | Create a problem marker on a file resource. |
createProject() | Create a new workspace project. |
deleteFile() | Delete a file. |
deleteFolder() | Delete a folder recursively. |
deleteProject() | Delete a project from the workspace. |
fileExists() | Verifies that a specific file exists. |
findFiles() | Return files matching a certain pattern. |
getChecksum() | Get an MD5 checksum over a readable resource. |
getFile() | Get a workspace or file system file. |
getProject() | Get a project instance. |
getWorkspace() | Get the workspace root. |
importProject() | Imports a project into the current workspace. |
linkProject() | Links a project into the current workspace. |
openFile() | Opens a file from the workspace or the file system. |
readFile() | Read data from a file. |
readLine() | Read a single line from a file. |
readStream() | Read from an InputStream into a string. |
readUrl() | Read full content from a given URL. |
refreshResource() | Refresh a given resource and all its child elements. |
showFileSelectionDialog() | Opens a file dialog. |
showFolderSelectionDialog() | Opens a dialog box which allows the user to select a container (project or folder). |
unzip() | Unzip a zip file to the provided target location. |
writeFile() | Write data to a file. |
writeLine() | Write a line of data to a file. |
zip() | Create or update a zip file with given resources. |
void closeFile(IFileHandle handle)
Close a file. Releases system resources bound by an open file.
void copyFile(Object sourceLocation, Object targetLocation) throws IOException
Copies a file from location to targetLocation.
Object createFile(Object location) throws IOException
Create a new file in the workspace or the file system.
IFile, File or null
in case of error
Object createFolder(Object location) throws IOException
Create a new folder in the workspace or the file system.
IFolder or File instance
IWorkspace.validateName
).force
is false
.IResourceChangeEvent
for
more details.void createProblemMarker(String severity, Object location, int lineNumber, String message, [String type], [boolean permanent]) throws IOException
Create a problem marker on a file resource.
true
for permanent markers, false
for temporary markersOptional: defaults to <true>.IProject createProject(String name) throws IOException
Create a new workspace project. Will create a new project if it not already exists. In case the project already exists, the existing instance will be returned.
project instance
void deleteFile(Object location) throws IOException
Delete a file. Does nothing if location cannot be resolved to an existing file.
void deleteFolder(Object location) throws IOException
Delete a folder recursively.
void deleteProject(Object source) throws IOException
Delete a project from the workspace.
boolean fileExists(Object location)
Verifies that a specific file exists.
true
if file exists
String[] findFiles(String pattern, [Object rootFolder], [boolean recursive]) throws IOException
Return files matching a certain pattern.
null
for workspace rootOptional: defaults to <null>.true
Optional: defaults to <true>.An array of all matching file locations
String getChecksum(Object location) throws IOException
Get an MD5 checksum over a readable resource.
file hash as hex encoded string
Object getFile(String location, [boolean exists]) throws FileNotFoundException
Get a workspace or file system file. Resolves relative and absolute file locations. Relative files are resolved against the current script file. If
exists is false
this method also returns files that do not exist yet. If true
only existing instances are returned.
resolved IFile or File instance
true
IProject getProject(String name)
Get a project instance.
project or null
IProject importProject(Object location) throws IOException
Imports a project into the current workspace. The project needs to be available on the file system and needs to be unpacked. Zipped projects cannot be imported.
project instance, throws otherwise
IProject linkProject(Object location) throws IOException
Links a project into the current workspace. Does not copy resources to the workspace.
linked project, throws otherwise
IFileHandle openFile(Object location, [int mode], [boolean autoClose]) throws IOException
Opens a file from the workspace or the file system. If the file does not exist and we open it for writing, the file is created automatically.
file handle instance to be used for file modification commands
String readFile(Object location, [int bytes]) throws IOException
Read data from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.
file data or null
if EOF is reached
String readLine(Object location) throws IOException
Read a single line from a file. To repeatedly read from a file retrieve a IFileHandle first using openFile() and use the handle for location.
line of text or null
if EOF is reached
String readStream(InputStream input) throws IOException
Read from an InputStream into a string. Consumes an InputStream and stores all available data in a string. Usually a stream is only readable once.
string content of stream.
String readUrl(String address) throws IOException
Read full content from a given URL.
read data
void refreshResource(Object resource) throws IOException
Refresh a given resource and all its child elements.
String showFileSelectionDialog([Object rootFolder], [int type], [String title], [String message]) throws IOException
Opens a file dialog. Depending on the rootFolder a workspace dialog or a file system dialog will be used. If the folder cannot be located, the workspace root folder is used by default. When type is set to WRITE or APPEND a save dialog will be shown instead of the default open dialog.
full path to selected file either as absolute file system path or as absolute workspace URI. Returns null
when the dialog is
cancelled by the user.
String showFolderSelectionDialog([Object rootFolder], [String title], [String message]) throws IOException
Opens a dialog box which allows the user to select a container (project or folder). Workspace paths will always display the workspace as root object.
full path to selected folder either as absolute file system path or as absolute workspace URI. Returns null
when the dialog is
cancelled by the user.
Object unzip(Object zipLocation, Object targetLocation) throws IOException
Unzip a zip file to the provided target location.
target location reference
IFileHandle writeFile(Object location, Object data, [int mode], [boolean autoClose]) throws IOException
Write data to a file. Files that do not exist yet will be created automatically. After the write operation the file remains open. It needs to be closed explicitly using the closeFile() command.
file handle to continue write operations
IFileHandle writeLine(Object location, String data, [int mode], [boolean autoClose]) throws IOException
Write a line of data to a file. Files that do not exist yet will be created automatically. After the write operation the file remains open. It needs to be closed explicitly using the closeFile() command.
file handle to continue write operations
Object zip(Object sourceLocation, Object zipLocation) throws IOException
Create or update a zip file with given resources.
zip file reference